/* Layout: a radio-operator console — status strip on top, big key button, 26 dial-ring letter keys in a grid */
:root {
  --bg: #eef0ea;
  --panel: #f8f9f5;
  --fg: #1d231f;
  --muted: #5f6b62;
  --line: #cfd5cb;
  --accent: #c2621a;
  --accent-soft: #f3dcc8;
  --ring-track: #dde2d8;
  --good: #2f7d4a;
  --good-soft: #d6ecdc;
  --bad: #b3362e;
  --bad-soft: #f4d6d3;
  --display: "Chakra Petch", "Arial Narrow", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141815; --panel: #1c211d; --fg: #e6ebe4; --muted: #95a196; --line: #313932;
    --accent: #f08a3c; --accent-soft: #3d2a1b; --ring-track: #2b322c;
    --good: #5cc07f; --good-soft: #1e3526; --bad: #f0786e; --bad-soft: #3f2220;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141815; --panel: #1c211d; --fg: #e6ebe4; --muted: #95a196; --line: #313932;
  --accent: #f08a3c; --accent-soft: #3d2a1b; --ring-track: #2b322c;
  --good: #5cc07f; --good-soft: #1e3526; --bad: #f0786e; --bad-soft: #3f2220;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; }
.wrap { max-width: 760px; margin: 0 auto; padding-inline: 16px; padding-block: 20px 40px; display: flex; flex-direction: column; gap: 18px; }

h1 { font-family: var(--display); font-weight: 700; font-size: 1.6rem; margin: 0; letter-spacing: .02em; text-wrap: balance; }
h1 span { color: var(--accent); }
.stats { display: flex; gap: 18px; font-variant-numeric: tabular-nums; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat b { font-family: var(--display); font-size: 1.4rem; line-height: 1; }
.stat small { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

.console { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.key {
  width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-family: var(--display); font-weight: 700; font-size: 1rem; letter-spacing: .06em;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000); transition: transform .08s, box-shadow .08s;
}
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.key.sounding { animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { filter: brightness(1.15); } }
.readout { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.msg { font-size: 1.05rem; min-height: 2.6em; line-height: 1.3; }
.msg.good { color: var(--good); }
.msg.bad { color: var(--bad); }
.msg code { font-family: var(--display); font-size: 1.25rem; letter-spacing: .15em; }
.linkbtn { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 999px; padding: 4px 12px; font: inherit; cursor: pointer; }
.linkbtn:hover { border-color: var(--accent); }

.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
/* Learn mode: a full-width label before each group of codes with the same number of marks. */
.board .group-head { grid-column: 1 / -1; margin: 8px 0 -2px; font: 700 .72rem var(--body); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.board .group-head:first-child { margin-top: 0; }
.letter {
  position: relative; aspect-ratio: 1; max-width: 100%; border: none; background: none; padding: 0; cursor: pointer;
  color: var(--fg); border-radius: 50%;
}
.letter svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.letter .track { fill: var(--panel); stroke: var(--ring-track); stroke-width: 6; }
.letter .prog { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; transition: stroke-dasharray .5s ease; }
.letter .face { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 1px; }
.letter .ch { font-family: var(--display); font-weight: 600; font-size: 1.55rem; line-height: 1; }
.letter .n { font-size: .68rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.letter .code { font-family: var(--display); font-size: .7rem; letter-spacing: .12em; color: var(--accent); }
.letter:hover .track { stroke: var(--line); }
.letter:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.letter.right .track { fill: var(--good-soft); }
.letter.wrong .track { fill: var(--bad-soft); }
.letter.answer .track { fill: var(--good-soft); stroke: var(--good); }

.dk { align-self: flex-start; background: var(--panel); color: var(--fg); border: 1.5px dashed var(--muted); border-radius: 999px; padding: 6px 16px; font: 600 .9rem var(--body); cursor: pointer; }
.dk:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.dk:disabled { opacity: .4; cursor: default; }
.compare { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 10px; border: 1.5px solid; }
.row.pick { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.row.ans { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.row .tag { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; width: 5.5em; flex: none; line-height: 1.2; }
.row .big { font-family: var(--display); font-weight: 700; font-size: 2.4rem; line-height: 1; width: 1.1em; text-align: center; flex: none; }
.row { transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease; }
.compare.live .row { opacity: .45; }
.compare.live .row.playing { opacity: 1; transform: scale(1.03); box-shadow: 0 0 0 3px currentColor; }
.row .now { margin-left: auto; font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; visibility: hidden; flex: none; }
.row.playing .now { visibility: visible; animation: blink .6s ease-in-out infinite alternate; }
@keyframes blink { to { opacity: .35; } }
.marks { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.marks i { display: block; height: 16px; border-radius: 8px; background: currentColor; }
.marks i.dot { width: 16px; }
.marks i.dash { width: 48px; }
@media (max-width: 480px) {
  .dk { align-self: center; }
  .row { gap: 10px; padding: 8px 10px; }
  .row .tag { width: 4.5em; }
  .row .big { font-size: 2rem; }
  .marks { gap: 7px; }
  .row .now { display: none; }
  .marks i { height: 13px; } .marks i.dot { width: 13px; } .marks i.dash { width: 38px; }
}
.picker { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.picker-head h2 { font: 600 1rem var(--display); margin: 0; letter-spacing: .03em; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.chip { height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); color: var(--muted); font: 600 1.05rem var(--display); cursor: pointer; text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 50%, transparent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--fg); text-decoration: none; }
.chip:focus-visible, .linkbtn:focus-visible, .dk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.picker-note { font-size: .8rem; color: var(--muted); margin: 0; }
.picker-note.warn { color: var(--bad); }

.linkbtn.danger { color: var(--bad); }
.linkbtn.danger:hover { border-color: var(--bad); }

.coffee { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; background: var(--accent-soft); color: var(--fg); text-decoration: none; font-weight: 700; border: 1px solid transparent; }
.coffee:hover { border-color: var(--accent); }
.coffee:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.coffee svg { width: 16px; height: 16px; color: var(--accent); }

@media (max-width: 480px) {
  .console { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .board { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .letter .ch { font-size: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) {
  .key.sounding { animation: none; }
  .letter .prog { transition: none; }
  .row, .row.playing .now { transition: none; animation: none; }
  .compare.live .row.playing { transform: none; }
}

/* ---- Server-rendered (htmx) layout ---- */
.console { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
.picker:not([open]) { gap: 0; }
.console-live { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.letter:disabled { cursor: default; }
.letter .code { display: none; }
body:has(#showCodes:checked) .letter .code { display: block; }
.picker > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; font: 600 1rem var(--display); letter-spacing: .03em; }
.picker > summary::-webkit-details-marker { display: none; }
.picker > summary::after { content: "Show"; font: 400 .8rem var(--body); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.picker[open] > summary::after { content: "Hide"; }
.picker > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.picker-body { display: flex; flex-direction: column; gap: 12px; }
.htmx-request.key, .htmx-request.letter, .htmx-request.chip { opacity: .75; }
.notice { color: var(--bad); }
@media (max-width: 480px) {
  .console-live { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}

/* ---- Compact header: title, score, and small Settings / Account menus ---- */
header { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap; }
header .stats { margin-left: auto; }
.menus { display: flex; align-items: center; gap: 8px; position: relative; }
.net { font-size: .72rem; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); color: var(--fg); display: grid; place-items: center; overflow: hidden; }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn:hover, .menu[open] > .iconbtn { border-color: var(--accent); }
.iconbtn.avatar { background: var(--accent-soft); color: var(--accent); font: 700 .9rem var(--display); }
.iconbtn.avatar img { width: 100%; height: 100%; object-fit: cover; }
.signin { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.signin:hover, .menu[open] > .signin { border-color: var(--accent); }
.menu > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: min(300px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  box-shadow: 0 10px 30px rgb(0 0 0 / .25); display: flex; flex-direction: column; gap: 12px; font-size: .88rem; color: var(--muted);
}
.menu-panel h2 { margin: 0; font: 600 1rem var(--display); color: var(--fg); letter-spacing: .03em; }
.menu-panel .name { color: var(--fg); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-panel .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.slider { display: grid; grid-template-columns: 5em 1fr 4.5em; align-items: center; gap: 8px; }
.slider input { width: 100%; accent-color: var(--accent); }
.slider output { font-variant-numeric: tabular-nums; color: var(--fg); text-align: right; }
.check { display: flex; align-items: center; gap: 8px; color: var(--fg); cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.g_id_signin { min-height: 32px; }

.foot { font-size: .8rem; color: var(--muted); display: flex; flex-direction: column; gap: 12px; }
.support { display: flex; align-items: center; justify-content: center; gap: 8px 12px; flex-wrap: wrap; font-size: .9rem; color: var(--fg); text-align: center; }
.foot-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }

@media (max-width: 480px) {
  .wrap { gap: 12px; padding-block: 12px 32px; }
  h1 { font-size: 1.45rem; }
  header .menus { margin-left: auto; }
  header .stats { order: 3; width: 100%; margin-left: 0; justify-content: space-around; }
  header .net { order: 4; width: 100%; text-align: center; padding: 2px 10px; }
  .stat { align-items: center; }
  .stat b { font-size: 1.15rem; }
  .console { padding: 12px; }
  /* Key beside the message to save height; stack again when the answer comparison needs the width. */
  .console-live { grid-template-columns: auto 1fr; justify-items: stretch; text-align: left; gap: 12px; }
  .console-live:has(.compare) { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .key { width: 72px; height: 72px; font-size: .85rem; }
  .msg { font-size: .95rem; min-height: 0; }
  .dk { align-self: flex-start; padding: 5px 14px; }
  .console-live:has(.compare) .dk { align-self: center; }
  .picker { padding: 10px 14px; }
}

/* ---- Settings panel: preferences plus the letter picker ---- */
.settings-panel { width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 90px); overflow-y: auto; overscroll-behavior: contain; }
.prefs { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.slider select { grid-column: 2 / 4; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; accent-color: var(--accent); }
.slider select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-panel .picker { background: none; border: none; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 0; }
.settings-panel .picker > summary { color: var(--fg); }
.settings-panel .chips { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); }
.settings-panel .chip { height: 40px; }

/* ---- Learn tab: the dots and dashes under each ring ---- */
.board.learning { row-gap: 24px; padding-bottom: 14px; }
.letter .below { position: absolute; top: calc(100% + 7px); left: 0; right: 0; display: flex; justify-content: center; align-items: center; gap: 3px; }
.letter .below i { display: block; height: 5px; border-radius: 3px; background: var(--accent); }
.letter .below i.dot { width: 5px; flex: none; }
.letter .below i.dash { width: 15px; min-width: 7px; flex-shrink: 1; }
.console-live.learning .compare:empty { display: none; }
@media (max-width: 480px) {
  .console-live.learning { grid-template-columns: auto 1fr; justify-items: stretch; text-align: left; }
  .console-live.learning .compare .row { padding: 6px 10px; }
  .console-live.learning .compare .row .tag { display: none; }
  .console-live.learning .compare { width: 100%; }
  .console-live.learning .marks { gap: 6px; }
  .console-live.learning .marks i { height: 11px; } .console-live.learning .marks i.dot { width: 11px; } .console-live.learning .marks i.dash { width: 30px; }
}

/* ---- Learn / Guess / Type tabs ---- */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px; gap: 4px; }
.tab { border: none; background: none; color: var(--muted); font: 600 1rem var(--display); letter-spacing: .04em; padding: 8px 12px; border-radius: 999px; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--accent); color: #fff; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.screen { display: flex; flex-direction: column; gap: 18px; }
.wrap[data-screen="send"] #listen-screen, .wrap:not([data-screen="send"]) #send-screen { display: none; }
.wrap[data-keyer="straight"] .paddles, .wrap[data-keyer="straight"] .hint-paddle,
.wrap:not([data-keyer="straight"]) .straight, .wrap:not([data-keyer="straight"]) .hint-straight { display: none; }

.sender { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.copy { display: flex; flex-direction: column; gap: 8px; }
.copy-head { display: flex; justify-content: space-between; align-items: center; font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.decoded { min-height: 2.6em; max-height: 6.5em; overflow-y: auto; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1.5px solid var(--line);
  font: 700 1.9rem/1.25 var(--display); letter-spacing: .12em; overflow-wrap: anywhere; white-space: pre-wrap; transition: border-color .08s; }
.sender.keyed .decoded { border-color: var(--accent); }
.decoded .unknown { color: var(--bad); }
.decoded .placeholder { font: 400 .9rem var(--body); letter-spacing: 0; color: var(--muted); }
.current { height: 18px; display: flex; align-items: center; gap: 8px; color: var(--accent); }
.current i { display: block; height: 14px; border-radius: 7px; background: currentColor; }
.current i.dot { width: 14px; }
.current i.dash { width: 42px; }
.keymode { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg { border: 1px solid var(--line); background: var(--bg); color: var(--muted); border-radius: 10px; padding: 8px; font: 600 .9rem var(--body); cursor: pointer; }
.seg[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.paddles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.paddle {
  height: 170px; border-radius: 18px; border: 2px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font: 600 .95rem var(--body);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 4px 0 var(--line); transition: transform .05s, box-shadow .05s, background .05s;
}
.paddle .sym { display: block; background: var(--accent); height: 18px; border-radius: 9px; }
.paddle .sym.dot { width: 18px; }
.paddle .sym.dash { width: 56px; }
.paddle .sym.knob { width: 44px; height: 44px; border-radius: 50%; }
.wrap[data-screen="send"] .kbd-listen { display: none; }
.paddle.down { background: var(--accent-soft); border-color: var(--accent); transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.paddle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.straight .paddle { width: 100%; }
.hint { margin: 0; font-size: .8rem; color: var(--muted); }
.chart > summary { cursor: pointer; font: 600 .9rem var(--display); color: var(--muted); }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px 10px; margin-top: 10px; font: .9rem var(--display); color: var(--muted); }
.chart-grid b { color: var(--fg); }
@media (max-width: 480px) {
  .screen { gap: 12px; }
  .sender { padding: 12px; }
  .paddle { height: 150px; }
}
@media (prefers-reduced-motion: reduce) { .paddle, .decoded { transition: none; } }

/* ---- Paddle mode ---- */
.paddle-mode { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .9rem; color: var(--muted); }
.paddle-mode select { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.paddle-mode select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap[data-keyer="straight"] .paddle-mode { display: none; }
.hint-paddle .mode-A, .hint-paddle .mode-B, .hint-paddle .mode-tap { display: none; }
.wrap[data-paddle-mode="A"] .hint-paddle .mode-A, .wrap[data-paddle-mode="tap"] .hint-paddle .mode-tap,
.wrap:not([data-paddle-mode="A"]):not([data-paddle-mode="tap"]) .hint-paddle .mode-B { display: inline; }

/* Long presses on the keys must never start a text selection or callout (iOS). */
#send-screen { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.paddle, .paddle * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.paddle * { pointer-events: none; }
