/* Cuts — key bitting notes.
   Phone first. Everything is sized so a thumb can hit it while the other hand
   is holding a key and a pair of callipers. */

:root {
  --bg: #12100e;
  --surface: #1c1917;
  --surface-2: #242019;
  --line: #322c25;
  --text: #f6f1e8;
  --muted: #a49a8e;
  --brass: #d8a75a;
  --brass-soft: #6b5326;
  --danger: #e0685a;
  --radius: 14px;
  --tap: 46px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f4ef;
    --surface: #ffffff;
    --surface-2: #f2ede4;
    --line: #e2dbd0;
    --text: #191512;
    --muted: #6d645a;
    --brass: #9a6f16;
    --brass-soft: #efe0c0;
    --danger: #c0392b;
    --shadow: 0 8px 24px rgba(80, 66, 40, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute has to win, and by default it does not.
 *
 * `[hidden] { display: none }` lives in the BROWSER's stylesheet, and any author
 * rule that sets `display` on the same element beats it outright — author styles
 * outrank user-agent styles whatever the specificity. So `.busy { display: flex }`
 * silently made `hidden` a no-op, and the loading overlay — fixed, full-bleed,
 * z-index 50 — stayed over a working app forever.
 *
 * It hid nothing while every check said it had: `el.hidden` reads back true, and
 * the DOM underneath is correct and measurable. Only computed style tells you.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin-inline: auto;
}

svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(var(--bg) 70%, transparent);
}

.wordmark { display: flex; align-items: center; gap: 9px; margin-right: auto; }
.wordmark h1 { font-size: 17px; font-weight: 620; letter-spacing: .01em; margin: 0; }
.mark svg { width: 34px; height: 14px; color: var(--brass); stroke-width: 1.7; display: block; }

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text);
  margin-left: -12px; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }

.text-btn {
  min-height: 38px;
  padding: 0 15px;
  border-radius: 999px;
  border: 1px solid var(--brass);
  background: var(--brass);
  color: #1a1408;
  font: inherit; font-size: 14.5px; font-weight: 640;
  cursor: pointer;
}
@media (prefers-color-scheme: light) { .text-btn { color: #fff; } }
.text-btn:active { transform: translateY(1px); }

/* ------------------------------------------------------------ start screen */

.hero { padding: 14px 0 0; }

.hero h2 {
  font-size: clamp(27px, 8vw, 38px);
  line-height: 1.1;
  letter-spacing: -.022em;
  font-weight: 660;
  margin: 6px 0 14px;
  text-wrap: balance;
}

.lede { color: var(--muted); font-size: 16.5px; margin: 0 0 26px; max-width: 44ch; }

.cta { display: block; margin-bottom: 12px; cursor: pointer; }
.cta input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.cta-body {
  display: flex; align-items: center; justify-content: center; gap: 11px;
  min-height: 62px;
  border-radius: var(--radius);
  background: var(--brass);
  color: #171104;
  font-size: 17.5px; font-weight: 650;
  box-shadow: var(--shadow);
}
@media (prefers-color-scheme: light) { .cta-body { color: #fff; } }
.cta-icon { width: 23px; height: 23px; stroke-width: 1.8; }
.cta:active .cta-body { transform: translateY(1px); }

.cta.secondary .cta-body {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  min-height: 54px;
  font-size: 16px; font-weight: 560;
  box-shadow: none;
}

.resume {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; margin-top: 6px; padding: 13px 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--line);
  background: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer;
}
.resume-label { font-weight: 600; font-size: 15px; }
.resume-meta { color: var(--muted); font-size: 13px; }

.tips { color: var(--muted); font-size: 14.5px; margin: 30px 0 0; padding-left: 20px; }
.tips li { margin-bottom: 7px; }
.tips b { color: var(--text); font-weight: 600; }

.disclaimer {
  margin: 26px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px;
  max-width: 48ch;
}

/* ------------------------------------------------------------- work screen */

.namerow { display: flex; align-items: baseline; gap: 10px; margin: 2px 0 12px; }

.keyname {
  flex: 1; min-width: 0;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  color: var(--text);
  font: inherit; font-size: 19px; font-weight: 600;
  padding: 5px 2px;
}
.keyname::placeholder { color: var(--muted); font-weight: 500; }
.keyname:focus { outline: none; border-bottom-color: var(--brass); }

.stamp { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

.stage { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }

.stage canvas {
  display: block;
  width: 100%;
  border-radius: 12px;
  background: var(--surface-2);
}

#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

#gutter { position: relative; }

/* One typed reading. Deliberately chunky: this is the control the whole app
   exists for, and it gets used with cold hands. */
.chip {
  position: absolute;
  width: 60px;
  display: block;
  transition: transform .12s ease;
}
.chip input {
  width: 100%;
  height: 42px;
  padding: 0 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 16px; font-weight: 600;
  text-align: center;
  -moz-appearance: textfield;
}
.chip input::-webkit-outer-spin-button,
.chip input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chip input::placeholder { color: var(--muted); font-weight: 400; opacity: .55; }
.chip input:focus { outline: none; border-color: var(--brass); box-shadow: 0 0 0 3px var(--brass-soft); }

/* Sits astride the top border like a fieldset legend, so the box's full width
   belongs to the reading. A five-character value such as 10.25 has to fit. */
.chip-no {
  position: absolute;
  left: 6px; top: -7px;
  z-index: 1;
  padding: 0 3px;
  background: var(--bg);
  font-size: 10.5px; font-weight: 700; line-height: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.chip.sel input { border-color: var(--brass); }
.chip.sel .chip-no { color: var(--brass); }
.chip.filled input { border-color: var(--brass-soft); }

.status { color: var(--muted); font-size: 13.5px; margin: 12px 2px 0; min-height: 20px; }
.status b { color: var(--text); font-weight: 600; }
.status.warn b { color: var(--brass); }

.tools { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.tool {
  flex: 1 1 0;
  min-width: 84px;
  min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 12px; font-weight: 560;
  cursor: pointer;
  padding: 6px 4px;
}
.tool svg { width: 19px; height: 19px; }
.tool:disabled { opacity: .38; }
.tool:not(:disabled):active { background: var(--surface-2); }
.tool.armed { border-color: var(--brass); color: var(--brass); }
#delBtn:not(:disabled) { color: var(--danger); }

.tuning { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.tuning summary { color: var(--muted); font-size: 13.5px; cursor: pointer; list-style: none; }
.tuning summary::-webkit-details-marker { display: none; }
.tuning summary::before { content: "⌄  "; }
.tuning[open] summary::before { content: "⌃  "; }
.tuning-body { padding: 10px 0 4px; color: var(--muted); font-size: 13.5px; }
.tuning-body p { margin: 0 0 14px; max-width: 52ch; }

.slider { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.slider span { flex: 0 0 auto; font-size: 13px; }
.slider input { flex: 1; min-width: 0; accent-color: var(--brass); height: 30px; }
.slider output { flex: 0 0 44px; text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }

.linkish { background: none; border: 0; color: var(--brass); font: inherit; font-size: 13px; padding: 6px 0; cursor: pointer; text-decoration: underline; }
.checkline { display: flex; align-items: center; gap: 9px; margin-top: 10px; font-size: 13.5px; }
.checkline input { accent-color: var(--brass); width: 17px; height: 17px; }

/* ------------------------------------------------------------- busy + toast */

.busy {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  color: var(--muted); font-size: 14.5px;
  backdrop-filter: blur(3px);
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--brass);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 14px;
  text-align: center;
}
