:root {
  --ink: #15202b;
  --muted: #4a5561;
  --page: #eef1f4;
  --brand: #0f5132;
  --brand-ink: #ffffff;
  /* each area has its own tint + a 2px darker border (r349) */
  --modes-bg: #f1e8fb; --modes-bd: #7a4cb8; --modes-ink: #4a2480;
  --ed-bg: #e3eefc;    --ed-bd: #3b6fc4;    --ed-ink: #1d3f7a;
  --fx-bg: #fdf3d8;    --fx-bd: #b7861a;    --fx-ink: #6b4b05;
  --tile: #ffffff;     --tile-alt-modes: #faf6fe; --tile-alt-fx: #fffaf0;
  --err: #a1121b;
  --mark: rgba(220, 38, 38, .95);
  /* r367 (10/27/2026): every button looks like a button - 2px clear line + a fill unlike the sheet */
  --btnline: #5f6b78;
  --btnfill: #f3f5f8;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: 24px;
}
button { font: inherit; cursor: pointer; }
h1 { font-size: 1.25rem; margin: 0; flex: 1; }
h2 { font-size: .95rem; margin: 0 0 4px; }
h3 { font-size: .95rem; margin: 14px 0 6px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px; background: var(--brand); color: var(--brand-ink);
}
.top img { border-radius: 8px; }
.live-state { font-size: .8rem; opacity: .95; border: 2px solid rgba(255,255,255,.7); background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px 10px; min-height: 30px; display: inline-flex; align-items: center; cursor: pointer; }
.live-state:empty { display: none; } /* r367: the tappable status pill is bordered */
.icon-btn {
  background: transparent; border: 0; color: inherit; font-size: 1.4rem;
  min-width: 40px; min-height: 40px; border-radius: 8px;
}

main { max-width: 820px; margin: 0 auto; padding: 8px 10px; display: grid; gap: 8px; }
main > * { min-width: 0; } /* 10/29: the one-row format bar scrolls sideways; it must not widen the page */
.area { border-radius: 10px; padding: 8px 10px; }
.area-modes { background: var(--modes-bg); border: 2px solid var(--modes-bd); }
.area-modes h2 { color: var(--modes-ink); }
.area-editor { background: var(--ed-bg); border: 2px solid var(--ed-bd); }
.area-editor h2 { color: var(--ed-ink); }
.area-result { background: #e2f4e8; border: 2px solid #2f8a52; }
.area-result h2 { color: #145530; }
.area-result .busy-box { margin-top: 0; }
.area-fixes { background: var(--fx-bg); border: 2px solid var(--fx-bd); }
.area-fixes h2 { color: var(--fx-ink); }
.editor-head { display: flex; align-items: baseline; gap: 8px; }
.editor-head h2 { flex: 1; margin: 0; }
.editor-head .link-btn { min-height: 34px; padding: 0 12px; }
.mini-primary:disabled { opacity: .55; cursor: default; }
.mini-primary { background: var(--brand); color: #fff; border: 2px solid #0a3a24; border-radius: 8px; font-weight: 700; padding: 0 12px; min-height: 30px; }
.count { font-size: .8rem; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip {
  background: var(--tile); color: var(--modes-ink);
  border: 2px solid var(--modes-bd); border-radius: 999px; /* r367: chips with words get the 2px line */
  padding: 4px 12px; min-height: 34px; font-weight: 600;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip:nth-child(even) { background: var(--tile-alt-modes); }
.chip[aria-checked="true"] { background: #5b3a94; color: #fff; border-color: #3d2566; }
.chip-add { border-style: dashed; font-size: 1.1rem; min-width: 34px; padding: 0 8px; }

/* the editor: a transparent textarea over a backdrop that draws the underlines */
.editor { position: relative; background: var(--tile); border: 1.5px solid var(--ed-bd); border-radius: 10px; }
.backdrop, .editor textarea {
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 8px 10px; margin: 0; border: 0; width: 100%;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; letter-spacing: normal;
}
.backdrop {
  position: absolute; inset: 0; overflow: hidden; color: transparent; pointer-events: none;
}
.backdrop mark {
  color: transparent; background: transparent;
  text-decoration: underline wavy var(--mark); text-decoration-thickness: 1.5px;
  text-underline-offset: 4px; text-decoration-skip-ink: none;
}
.backdrop mark.on { background: rgba(250, 204, 21, .45); }
.editor textarea {
  position: relative; display: block; resize: none; overflow-y: auto;
  min-height: 56px; height: 56px; max-height: calc(var(--vvh, 100dvh) * .4);
  background: transparent; color: var(--ink); outline: none; border-radius: 10px;
}
.editor:focus-within { box-shadow: 0 0 0 3px rgba(59, 111, 196, .35); }

.phi-note { margin: 8px 2px 0; font-size: .82rem; color: var(--ed-ink); }
.phi-warn {
  margin-top: 8px; padding: 10px; border-radius: 8px;
  background: #fde8e8; border: 2px solid #c2343c; color: #5c0b10; font-size: .9rem;
}
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.primary {
  background: var(--brand); color: #fff; border: 2px solid #0a3a24;
  border-radius: 10px; padding: 6px 14px; min-height: 40px; font-weight: 700;
}
.primary:disabled { opacity: .55; cursor: default; }
.plain {
  background: var(--btnfill); color: var(--ink); border: 2px solid var(--btnline);
  border-radius: 10px; padding: 6px 12px; min-height: 40px; font-weight: 600;
}
.plain:disabled { opacity: .55; }
.danger { color: var(--err); border-color: var(--err); }
.link-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--btnfill); border: 2px solid var(--btnline); border-radius: 8px;
  color: #0b4fb3; text-decoration: none; font-weight: 600; padding: 4px 12px; min-height: 36px;
} /* r367: was bare underlined text; now a bordered button */
.toast .link-btn { border-color: #9fd0ff; background: rgba(255, 255, 255, .12); }
/* r367: the one primary is filled and full width; the others sit under it at one width (max 260px), centered */
.actions { justify-content: center; }
.actions .primary { flex: 1 1 100%; }
.actions .plain { flex: 1 1 0; min-width: 0; max-width: 260px; }
.sheet-foot { justify-content: center; }
.sheet-foot .primary { flex: 1 1 100%; }
.sheet-foot .plain { flex: 1 1 0; min-width: 0; max-width: 260px; }
.sheet-body .plain { display: flex; align-items: center; justify-content: center; width: min(100%, 260px); margin: 10px auto; text-decoration: none; text-align: center; }

.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tile {
  background: var(--tile); border: 1.5px solid var(--fx-bd); border-left: 6px solid var(--fx-bd);
  border-radius: 8px; padding: 6px 10px;
}
.tile:nth-child(even) { background: var(--tile-alt-fx); }
.tile.flash { box-shadow: 0 0 0 3px rgba(250, 204, 21, .9); }
.tile .swap { font-weight: 600; overflow-wrap: anywhere; }
.tile .from { color: var(--err); text-decoration: line-through; }
.tile .to { color: var(--fx-ink); }
.tile .why { margin: 2px 0 2px; color: var(--muted); font-size: .9rem; }
.tile .kind { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--fx-ink); }
.tile .row { display: flex; gap: 8px; }
.tile .row button { min-height: 38px; padding: 6px 12px; border-radius: 8px; }
.accept { background: #1f6a3c; color: #fff; border: 2px solid #145530; font-weight: 600; }
.dismiss { background: var(--btnfill); color: var(--ink); border: 2px solid var(--btnline); font-weight: 600; }
.area-fixes h3 { color: var(--fx-ink); margin: 0 0 6px; }
#fixes:not([hidden]) ~ #whyArea { margin-top: 8px; }
.empty { margin: 4px 2px; color: var(--fx-ink); font-size: .9rem; }

/* sheets: anchored to the visible viewport so the keyboard never covers them */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 32, .45); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 21;
  max-width: 760px; margin: 0 auto;
  max-height: calc(var(--vvh, 100dvh) - 24px);
  display: flex; flex-direction: column;
  background: #ffffff; border: 2px solid #5a6876; border-bottom: 0;
  border-radius: 16px 16px 0 0; box-shadow: 0 -8px 28px rgba(0, 0, 0, .25);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.sheet-body { padding: 8px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1.5px solid #cfd6dd; }
.sheet label { display: block; font-weight: 600; margin: 8px 0 4px; }
.sheet input[type=text], .sheet input[type=password], .sheet textarea {
  width: 100%; font: 16px/1.4 inherit; padding: 10px; border: 1.5px solid #6b7785; border-radius: 8px;
}
.sheet label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; min-height: 44px; }
.sheet label.check input { width: 22px; height: 22px; }
.hint { color: var(--muted); font-size: .88rem; }
.busy { color: var(--muted); }
.busy-box { display: flex; gap: 12px; align-items: center; padding: 10px 12px; margin: 4px 0; border: 1.5px solid var(--ed-bd, #6b7785); border-radius: 10px; background: #fff; color: #1f2937; }
.busy-box[hidden] { display: none; }
.busy-box p { margin: 4px 0 0; }
.spin { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 4px solid #cfd8e3; border-top-color: #0f5132; animation: polish-spin .8s linear infinite; }
.spin-sm { display: inline-block; width: 11px; height: 11px; border-width: 2px; vertical-align: -1px; margin-right: 6px; }
@keyframes polish-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }
.err { color: var(--err); font-weight: 600; }
.doc-type { display: inline-block; margin: 0 0 8px; padding: 2px 10px; border-radius: 999px; background: var(--modes-bg); border: 1.5px solid var(--modes-bd); color: var(--modes-ink); font-size: .85rem; font-weight: 600; }
.subject-row { padding: 8px 10px; margin-bottom: 8px; background: var(--ed-bg); border: 1.5px solid var(--ed-bd); border-radius: 8px; }
.subject-row span:first-child { font-weight: 700; color: var(--ed-ink); }
.output {
  overflow-wrap: anywhere; padding: 8px 10px; border-radius: 8px;
  background: #ffffff; border: 1.5px solid #2f8a52; border-left: 6px solid #2f8a52;
  font-size: 1rem; min-height: 9em; outline: none;
  /* 10/29 PT #1676: no max-height / overflow here - the box grows and the PAGE scrolls, so the sticky bar above it works */
}
.output:focus { box-shadow: 0 0 0 3px rgba(47, 138, 82, .35); }
.output ul, .output ol { margin: 4px 0; padding-left: 24px; }
.output ul.wkd-cl { list-style: none; padding-left: 4px; }
.output li.wkd-cl-item { position: relative; padding-left: 28px; list-style: none; } /* not display:flex: Chrome hangs on Numbers over a range that holds a flex row */
.output li.wkd-cl-item > input { position: absolute; left: 2px; top: .3em; margin: 0; width: 18px; height: 18px; }
.output li.wkd-cl-done > span { text-decoration: line-through; opacity: .65; }
/* 10/29 PT #1676 (Kevin: like A&K's Ingredients box): the format bar stays pinned right under the sticky header
   while Kevin scrolls a long rewrite, and lets go once the box has scrolled past. .rtwrap holds ONLY the bar and
   the box, so sticky releases at the end of the box. --toph = the header's height (set by app.js, 48px fallback).
   z-index 3 = under the header (5), toasts (40) and the sheets. Opaque fill = the result area's own tint.
   On a phone the tools are one row that scrolls sideways, so the pinned bar keeps the box its room. */
.rtwrap { position: relative; }
.fmt-bar { display: flex; flex-wrap: nowrap; gap: 6px; align-items: center; margin: 0 0 6px;
  position: sticky; top: var(--toph, 48px); z-index: 3; background: #e2f4e8; padding: 6px 0;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; box-shadow: 0 6px 6px -6px rgba(0, 0, 0, .45); }
.fmt-bar::-webkit-scrollbar { display: none; }
.fmt-bar > .fmt-btn, .fmt-hl > .fmt-btn { flex: none; white-space: nowrap; }
.fmt-hl { display: inline-flex; flex-wrap: nowrap; flex: none; gap: 6px; align-items: center; margin-left: 4px; }
@media (min-width: 700px) { .fmt-bar, .fmt-hl { flex-wrap: wrap; overflow-x: visible; } .fmt-hl { flex: 0 1 auto; } }
/* the caret / a focused line is never revealed under the header + pinned bar */
html { scroll-padding-top: calc(var(--toph, 48px) + 58px); }
.fmt-btn { background: #fff; color: #1d4d33; border: 2px solid #2f8a52; border-radius: 8px; min-height: 34px; min-width: 34px; padding: 0 10px; font-weight: 700; font-size: .9rem; }
.fmt-btn.fmt-sw { padding: 0; width: 34px; border-color: #1d4d33; }
#changes .tile { border-color: var(--fx-bd); border-left-color: var(--fx-bd); }
#changes .tile:nth-child(even) { background: var(--tile-alt-fx); }

.toast.up { top: calc(var(--vvt, 0px) + 10px); bottom: auto; } /* result sheet open: keep clear of OK / Share */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--kb, 0px) + 20px); z-index: 40;
  background: #15202b; color: #fff; padding: 10px 16px; border-radius: 10px;
  border: 1.5px solid #000; max-width: calc(100vw - 32px);
}
