/* Unitwise — mobile-first. Base styles target a 320–430px phone; larger screens just center the column. */
:root {
  --bg: #f3f2ee;
  --surface: #ffffff;
  --surface-2: #ebe9e3;
  --ink: #121211;
  --ink-2: #6f6b64;
  --line: #dcd9d1;
  --accent: #e2491f;
  --accent-ink: #ffffff;
  --mark-bg: #fde4da;
  --mark-ink: #a5300d;
  --display-bg: #121211;
  --display-ink: #f3f2ee;
  --display-ink-2: #9a968e;
  --warn: #c62d1a;
  --r: 12px;
  --r-sm: 8px;
  --tabbar: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f0f0e; --surface: #181816; --surface-2: #23221f; --ink: #f1efe9; --ink-2: #9a968e;
    --line: #2e2d29; --accent: #ff6a3d; --accent-ink: #160803; --mark-bg: #3a1d12; --mark-ink: #ffb79c;
    --display-bg: #f1efe9; --display-ink: #121211; --display-ink-2: #6f6b64; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f0f0e; --surface: #181816; --surface-2: #23221f; --ink: #f1efe9; --ink-2: #9a968e;
  --line: #2e2d29; --accent: #ff6a3d; --accent-ink: #160803; --mark-bg: #3a1d12; --mark-ink: #ffb79c;
  --display-bg: #f1efe9; --display-ink: #121211; --display-ink-2: #6f6b64; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent;
  min-height: 100dvh; padding-bottom: calc(var(--tabbar) + var(--safe-b) + 8px);
  font-feature-settings: "tnum" 1; overscroll-behavior-y: none; overflow-x: hidden;
}
body.typing { padding-bottom: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; touch-action: manipulation; }
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
h2 { font-size: 11px; margin: 0 0 8px; letter-spacing: .09em; text-transform: uppercase; font-weight: 650; color: var(--ink-2); }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(4px + env(safe-area-inset-top)) 16px 4px; background: var(--bg);
}
.brand { font-weight: 750; font-size: 18px; display: flex; gap: 8px; align-items: center; letter-spacing: -.02em; }
.brand svg { width: 22px; height: 22px; }
.icon-btn { background: none; border: 0; width: 44px; height: 44px; border-radius: var(--r-sm); cursor: pointer; display: grid; place-items: center; color: var(--ink); margin-right: -10px; }
.icon-btn:active { background: var(--surface-2); }

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 16px; }
.view, .stack { display: flex; flex-direction: column; gap: 14px; }
.stack { gap: 26px; }

/* buttons */
.btn {
  border: 1px solid var(--ink); background: var(--ink); color: var(--bg); border-radius: var(--r); padding: 0 14px;
  font-weight: 600; font-size: 15px; cursor: pointer; flex: 1; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn svg.i { width: 18px; height: 18px; }
.btn:active { transform: scale(.98); opacity: .85; }
.row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* categories: 4×2 grid, all visible */
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 58px; padding: 6px 2px;
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); cursor: pointer; font-size: 12px; color: var(--ink-2);
}
.cat svg.i { width: 22px; height: 22px; color: var(--ink); }
.cat[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 600; }
.cat[aria-selected="true"] svg.i { color: var(--accent); }

/* converter */
.converter { display: flex; flex-direction: column; gap: 8px; }
.in-box { position: relative; }
.big-input {
  width: 100%; height: 68px; font-size: 40px; font-weight: 650; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--r); padding: 0 64px 0 14px; letter-spacing: -.02em; -webkit-appearance: none; appearance: none;
}
.big-input:focus, .type-in:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sign-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; font-weight: 600; cursor: pointer;
}
select {
  width: 100%; min-height: 48px; border: 1px solid var(--line); background-color: var(--surface); border-radius: var(--r); padding: 0 40px 0 14px; font-size: 16px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236f6b64' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
.unit-select { font-weight: 600; }
.hero {
  margin: 10px 0 6px; font-size: clamp(34px, 12vw, 54px); font-weight: 700; letter-spacing: -.035em; line-height: 1.02; overflow-wrap: anywhere;
}
.hero .side { display: block; font-size: 14px; font-weight: 400; color: var(--ink-2); letter-spacing: 0; margin-top: 8px; }
.results { list-style: none; margin: 6px 0 0; padding: 0; border-top: 1px solid var(--ink); }
.results li { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.results li .v { font-weight: 600; overflow-wrap: anywhere; }
.results li .n { color: var(--ink-2); font-size: 13px; text-align: right; }
.results li.same { color: var(--ink-2); }
.results li.same .v { font-weight: 400; }
.results li.note { cursor: default; }
.results li.note .n { text-align: left; }
.results li:active:not(.note) { background: var(--surface-2); }

/* pinned: 2-column grid, no sideways scrolling */
.pins { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pin { background: var(--display-bg); color: var(--display-ink); border-radius: var(--r); padding: 10px 12px 12px; position: relative; cursor: pointer; min-width: 0; }
.pin .p-label { font-size: 11px; color: var(--display-ink-2); letter-spacing: .06em; text-transform: uppercase; padding-right: 26px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin .p-from { display: flex; align-items: baseline; gap: 5px; margin-top: 6px; color: var(--display-ink-2); font-size: 14px; }
.pin input {
  width: 100%; min-width: 0; max-width: 5.5ch; background: transparent; border: 0; border-bottom: 1px solid color-mix(in srgb, var(--display-ink) 30%, transparent);
  border-radius: 0; padding: 2px 0; font-size: 18px; font-weight: 600; color: var(--display-ink);
}
.pin input:focus { outline: 0; border-bottom-color: var(--accent); }
.pin .p-to { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; overflow-wrap: anywhere; line-height: 1.15; }
.pin .p-x { position: absolute; top: 0; right: 0; width: 40px; height: 40px; background: none; border: 0; color: var(--display-ink-2); cursor: pointer; display: grid; place-items: center; }
.pin .p-x svg { width: 15px; height: 15px; }
.pin-empty { grid-column: 1 / -1; border: 1px dashed var(--line); border-radius: var(--r); padding: 14px; color: var(--ink-2); font-size: 14px; }

/* text */
textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 12px; resize: none;
  font-size: 16px; line-height: 1.5; min-height: 112px; max-height: 40vh; display: block;
}
.text-in { display: flex; flex-direction: column; gap: 8px; }
.tool-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool-row .btn { padding: 0 6px; font-size: 14px; min-width: 0; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: var(--r); padding: 3px; gap: 3px; background: var(--surface); }
.seg button { border: 0; background: none; min-height: 40px; padding: 0 4px; border-radius: var(--r-sm); font-size: 14px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-checked="true"], .seg button.on { background: var(--ink); color: var(--bg); font-weight: 600; }
.seg.mini { padding: 2px; }
.seg.mini button { min-height: 32px; font-size: 13px; padding: 0 10px; }
.out-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; }
.out-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 10px; margin-bottom: 10px; flex-wrap: wrap; }
.badge { font-size: 13px; color: var(--ink-2); }
.badge b { color: var(--ink); font-weight: 600; }
.annotated { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.85; min-height: 1.85em; }
.annotated.replace .src { display: none; }
.conv {
  display: inline; background: var(--mark-bg); color: var(--mark-ink); border-radius: 4px; padding: 1px 5px;
  margin: 0 1px; font-weight: 600; font-size: .94em; cursor: default; border: 0; white-space: normal;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.conv.ask { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.conv small { font-weight: 400; opacity: .75; }
.placeholder { color: var(--ink-2); }
/* copy button stays reachable above the tab bar while you scroll a long recipe */
.sticky-action {
  position: sticky; bottom: calc(var(--tabbar) + var(--safe-b) + 8px); z-index: 3;
  padding-top: 18px; margin-top: -8px; background: linear-gradient(to bottom, transparent, var(--bg) 40%);
}
.sticky-action .btn { width: 100%; }
body.typing .sticky-action { bottom: 8px; }

/* talk */
.show-card { padding: 18px 16px; background: var(--display-bg); color: var(--display-ink); border-radius: var(--r); }
.show-card .muted { color: var(--display-ink-2); }
.show-from { font-size: 15px; color: var(--display-ink-2); overflow-wrap: anywhere; }
.show-to { font-size: clamp(38px, 14vw, 60px); font-weight: 700; letter-spacing: -.035em; line-height: 1.05; margin: 6px 0 10px; overflow-wrap: anywhere; }
.show-label { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--display-ink-2); margin-bottom: 8px; }
.mic-wrap { display: flex; align-items: center; gap: 14px; }
.mic {
  width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.mic svg.i { width: 28px; height: 28px; stroke-width: 2; }
.mic.on { background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--warn) 15%, transparent); } }
.mic-meta { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.mic-status { font-size: 15px; }
.lang { min-height: 40px; font-size: 16px; color: var(--ink-2); max-width: 220px; }
.type-in { width: 100%; height: 52px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 0 14px; font-size: 16px; }
.type-card { display: flex; flex-direction: column; }
.annotated.live { margin: 10px 2px 0; }
.annotated.live:empty { display: none; }
.transcript { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.transcript:empty { display: none; }
.line { padding: 10px 0; border-bottom: 1px solid var(--line); }
.line.interim { opacity: .55; }
.line .annotated { margin: 0; line-height: 1.75; }

/* cheats */
.cheat table { width: 100%; border-collapse: collapse; font-size: 15px; border-top: 1px solid var(--ink); }
.cheat td { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cheat td + td { padding-left: 12px; }
.cheat td:first-child { font-weight: 600; white-space: nowrap; }
.cheat td.r { text-align: right; color: var(--ink-2); }
.cheat tr.head td { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; }
.rules { border-top: 1px solid var(--ink); }
.rule { display: grid; grid-template-columns: minmax(6.5em, 36%) 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.rule b { font-weight: 600; }
.rule .ex { display: block; color: var(--ink-2); font-size: 13px; margin-top: 2px; }

/* bottom tabs; hidden while the keyboard is up */
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); border-top: 1px solid var(--line); padding: 0 4px var(--safe-b);
}
body.typing .tabs { display: none; }
.tabs button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--tabbar); font-size: 11px; color: var(--ink-2); cursor: pointer; position: relative;
}
.tabs button svg.i { width: 22px; height: 22px; }
.tabs button.active { color: var(--ink); font-weight: 600; }
.tabs button.active::before { content: ""; position: absolute; top: -1px; left: 28%; right: 28%; height: 2px; background: var(--accent); }

/* settings: bottom sheet */
dialog {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0;
}
dialog[open] { animation: sheet-up .22s ease-out; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .4; } }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet {
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + var(--safe-b));
  display: flex; flex-direction: column; gap: 16px; overflow-y: auto; max-height: 92dvh;
}
.sheet::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line); align-self: center; }
.sheet-title { font-size: 18px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field select { font-weight: 400; }
.install { border-top: 1px solid var(--line); padding-top: 14px; }
.install h3 { font-size: 15px; margin: 0; }
.install p { margin: 6px 0 10px; }

/* maker credit */
.maker {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 24px auto 0; width: fit-content; min-height: 44px;
  color: var(--ink-2); font-size: 13px; text-decoration: none; padding: 0 12px; border-radius: var(--r-sm);
}
.maker b { color: var(--ink); font-weight: 600; }
.maker img { width: 22px; height: 22px; border-radius: 50%; display: block; }
.maker:active { background: var(--surface-2); }
.maker.in-sheet { margin: -6px auto 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: var(--r-sm); font-size: 14px; opacity: 0;
  pointer-events: none; transition: .18s; z-index: 10; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.typing .toast { bottom: 16px; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
