/* 呼号 Cipher Lab — Apple-minimal, self-contained (shares the site's
   token values from app-style.css; tools with their own style.css do
   not get the shared sheet, so the tokens are duplicated here). */
:root {
  color-scheme: light;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
  --canvas: #f5f5f7;
  --surface: #fff;
  --recessed: #f5f5f7;
  --ink: #1d1d1f;
  --muted: #65656b;
  --line: rgb(0 0 0 / .06);
  --control-line: rgb(0 0 0 / .14);
  --selected: rgb(0 0 0 / .075);
  --accent: #0071e3;
  --accent-hover: #0065cc;
  --accent-ink: #fff;
  --good: #1eaa50;
  --bad: #e02028;
  --motion: .2s cubic-bezier(.16, 1, .3, 1);
  color: var(--ink);
  background: var(--canvas);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #161618;
  --surface: #1e1e20;
  --recessed: #242426;
  --ink: #f5f5f7;
  --muted: #ababaf;
  --line: rgb(255 255 255 / .08);
  --control-line: rgb(255 255 255 / .19);
  --selected: rgb(255 255 255 / .10);
  --accent: #5aaaf9;
  --accent-hover: #7bbaff;
  --accent-ink: #101820;
  --good: #4ade80;
  --bad: #f87171;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; transition: background-color var(--motion), color var(--motion); }
main { width: min(896px, calc(100% - 32px)); margin: clamp(32px, 7vw, 80px) auto; }
h1 { font-size: clamp(2.25rem, 5vw, 4rem); font-weight: 600; line-height: 1.12; letter-spacing: -.045em; margin: 16px 0 8px; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -.01em; margin: 0; }
p { color: var(--muted); margin: 0; }
a { color: var(--ink); text-underline-offset: .2em; }
.subtitle { font-size: 1.125rem; color: var(--ink); }
.lede { margin-top: 8px; }
.badges { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.panel { display: grid; gap: 24px; margin-block-start: 32px; border: 1px solid var(--line); border-radius: 24px; padding: clamp(16px, 4vw, 32px); background: var(--surface); }
.of-url-note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
button { display: inline-flex; justify-content: center; align-items: center; background: var(--accent); color: var(--accent-ink); border: 1px solid transparent; border-radius: 8px; min-height: 44px; font: inherit; font-size: 14px; font-weight: 500; padding: 8px 16px; cursor: pointer; transition: background-color var(--motion), transform var(--motion); }
button:not(:disabled):hover { background: var(--accent-hover); }
button:not(:disabled):active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: default; }
.secondary { color: var(--ink); background: var(--recessed); }
.secondary:not(:disabled):hover { background: var(--selected); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--recessed); border: 1px solid var(--control-line); border-radius: 10px; padding: 4px; }
.seg button { background: transparent; color: var(--ink); border: 0; min-height: 36px; border-radius: 7px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
.brand-line { text-align: center; color: var(--muted); font-size: 12.5px; letter-spacing: .14em; padding: 20px 0 28px; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---- Cipher Lab ---- */
.cl-voice-note { margin-top: 16px; padding: 12px 16px; border: 1px solid var(--control-line); border-radius: 12px; background: var(--recessed); color: var(--ink); font-size: 14px; }
.cl-rate-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.cl-label { font-weight: 600; color: var(--ink); }
.cl-chart-wrap { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.cl-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 16px; background: var(--recessed); border: 1px solid var(--line); border-radius: 20px; flex: 1 1 420px; }
.cl-cell { display: grid; justify-items: center; align-content: center; gap: 0; min-height: 72px; padding: 8px 4px; border-radius: 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--control-line); transition: background-color .15s ease, transform .15s ease, border-color .15s ease; }
.cl-cell:hover { background: var(--selected); }
.cl-cell-letter { font-size: 1.25rem; font-weight: 600; line-height: 1.15; }
.cl-cell-word { font-size: 13px; color: var(--ink); }
.cl-cell-phonetic { font-size: 11px; color: var(--muted); }
.cl-cell.cl-active { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.cl-cell.cl-active .cl-cell-word, .cl-cell.cl-active .cl-cell-phonetic { color: var(--accent-ink); opacity: .85; }
.cl-readout { display: grid; gap: 2px; min-width: 160px; }
.cl-big-letter { font-size: 4.5rem; line-height: 1.1; color: var(--ink); }
.cl-readout-line { font-size: 1.75rem; font-weight: 600; color: var(--ink); }
.cl-readout-phonetic { font-size: 1.125rem; color: var(--muted); }
textarea, input[type="text"] { width: 100%; font: inherit; color: var(--ink); background: var(--recessed); border: 1px solid var(--control-line); border-radius: 12px; padding: 12px 14px; resize: vertical; }
.cl-seq-out { font-size: 1.375rem; line-height: 1.6; color: var(--ink); word-break: break-word; min-height: 2.2rem; }
.cl-parts { display: flex; flex-wrap: wrap; gap: 8px; }
.cl-parts:empty { display: none; }
.cl-part { display: inline-grid; grid-template-columns: auto auto; gap: 0 8px; align-items: baseline; background: var(--recessed); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.cl-part .cl-part-letter { color: var(--ink); font-weight: 600; }
.cl-part .cl-part-word { font-size: 1rem; color: var(--ink); }
.cl-part.cl-playing { border-color: var(--accent); }
.cl-part.cl-invalid { border-color: var(--bad); }
.cl-part.cl-invalid .cl-part-word { color: var(--bad); font-weight: 600; }
.cl-card-img { display: block; max-width: 100%; margin-top: 12px; border: 1px solid var(--line); border-radius: 12px; }
.cl-sub-h { font-size: 1rem; margin: 8px 0 0; }
.cl-quiz-meta { color: var(--muted); }
.cl-quiz-meta strong { color: var(--ink); }
.cl-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.cl-options button { font-size: 1.25rem; min-height: 56px; }
.cl-options button.cl-picked-correct { background: var(--good); color: #fff; }
.cl-options button.cl-picked-wrong { background: var(--bad); color: #fff; }
.cl-feedback { font-size: 1rem; color: var(--ink); min-height: 1.5em; }
.cl-feedback:empty { display: none; }
.cl-feedback.cl-good { color: var(--good); font-weight: 600; }
.cl-feedback.cl-bad { color: var(--bad); font-weight: 600; }
.cl-result-line { font-size: 1.125rem; color: var(--ink); }
.cl-result-line strong { font-variant-numeric: tabular-nums; }
.cl-review { display: grid; gap: 8px; }
.cl-review:empty { display: none; }
.cl-review-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; background: var(--recessed); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.cl-review-row .cl-review-letter { font-weight: 600; color: var(--ink); }
.cl-review-row .cl-review-wrong { color: var(--bad); }
#encode-msg:empty, #quiz-best:empty { display: none; }
@media (max-width: 640px) {
  .cl-options { grid-template-columns: repeat(2, 1fr); }
  .cl-big-letter { font-size: 3.5rem; }
  .cl-grid { grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 12px; }
  .cl-cell { min-height: 68px; }
}

/* ---- Cipher Lab: encoder controls ---- */
.cl-cipher-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.cl-shift-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.cl-shift-row input[type="range"] { flex: 1 1 220px; accent-color: var(--accent); }
.cl-shift-val { min-width: 44px; text-align: center; font-weight: 600; color: var(--ink); }
.cl-key-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.cl-key-row input[type="text"] { flex: 1 1 220px; }
.cl-out { font-size: 1.375rem; line-height: 1.6; color: var(--ink); word-break: break-word; min-height: 2.2rem; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.cl-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

/* ---- Pigpen ---- */
.cl-pigpen-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; padding: 16px; background: var(--recessed); border: 1px solid var(--line); border-radius: 20px; }
.cl-pigpen-cell { display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 84px; padding: 8px 4px; border-radius: 14px; background: var(--surface); color: var(--ink); border: 1px solid var(--control-line); }
.cl-pigpen-cell:hover { background: var(--selected); }
.cl-pigpen-cell.cl-active { background: var(--accent); border-color: transparent; }
.cl-pigpen-cell.cl-active .cl-pigpen-letter { color: var(--accent-ink); }
.cl-pigpen-cell.cl-active svg * { stroke: var(--accent-ink); }
.cl-pigpen-cell.cl-active svg circle { fill: var(--accent-ink); }
.cl-pigpen-letter { font-size: 1rem; font-weight: 600; line-height: 1.15; }
.cl-pigpen-wrap { display: flex; flex-wrap: wrap; gap: 28px; align-items: flex-start; }
.cl-pigpen-readout { display: grid; gap: 2px; min-width: 160px; justify-items: start; }
.cl-pigpen-big { width: 120px; height: 120px; }
.cl-pigpen-big-letter { font-size: 3rem; line-height: 1.1; color: var(--ink); font-weight: 600; }
.cl-pigpen-group { font-size: 1rem; color: var(--muted); }
.cl-pigpen-word-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; min-height: 56px; }
.cl-pigpen-word-row:empty { display: none; }
.cl-pigpen-word-cell { display: grid; justify-items: center; gap: 0; }
.cl-pigpen-word-cell span { font-size: 12px; color: var(--muted); }
.cl-pigpen-word-cell svg { width: 44px; height: 44px; }

/* ---- Cracker ---- */
.cl-brute { display: grid; gap: 4px; max-height: 320px; overflow-y: auto; padding: 4px; }
.cl-brute-row { display: grid; grid-template-columns: 72px 1fr; gap: 12px; align-items: baseline; background: var(--recessed); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; font-size: 14px; }
.cl-brute-shift { color: var(--muted); font-variant-numeric: tabular-nums; }
.cl-brute-text { color: var(--ink); font-family: ui-monospace, "SF Mono", Menlo, monospace; word-break: break-word; }
.cl-freq { display: grid; gap: 6px; }
.cl-freq-row { display: grid; grid-template-columns: 20px 1fr 148px; gap: 10px; align-items: center; font-size: 13px; }
.cl-freq-letter { font-weight: 600; color: var(--ink); }
.cl-freq-track { position: relative; height: 14px; background: var(--recessed); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.cl-freq-bar { height: 100%; background: var(--accent); border-radius: 7px; }
.cl-freq-std { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--bad); }
.cl-freq-nums { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Quiz prompt ---- */
.cl-quiz-prompt { font-size: 1.5rem; line-height: 1.5; color: var(--ink); font-family: ui-monospace, "SF Mono", Menlo, monospace; word-break: break-word; }
.cl-quiz-label { font-size: 0.875rem; color: var(--muted); }
.cl-explain { font-size: 0.875rem; color: var(--muted); min-height: 1.4em; }
.cl-explain:empty { display: none; }
@media (max-width: 640px) {
  .cl-pigpen-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 12px; }
  .cl-pigpen-cell { min-height: 76px; }
  .cl-freq-row { grid-template-columns: 18px 1fr 118px; }
  .cl-brute-row { grid-template-columns: 56px 1fr; }
}
