/* 旗语 Semaphore — 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; } }

/* ---- Semaphore ---- */
.sm-view-note { margin-top: 16px; padding: 12px 16px; background: var(--recessed); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; color: var(--ink); }
.sm-board-wrap { display: flex; flex-wrap: wrap; gap: 28px; align-items: center; }
.sm-figure-box { width: min(280px, 72vw); background: var(--recessed); border: 1px solid var(--line); border-radius: 20px; padding: 12px; touch-action: none; }
.sm-figure-box.sm-figure-small { width: min(220px, 60vw); }
.sm-figure { display: block; width: 100%; height: auto; }
.sm-figure-board { cursor: grab; }
.sm-figure-board:active { cursor: grabbing; }
.sm-readout { display: grid; gap: 2px; min-width: 160px; }
.sm-big-char { font-size: 4.5rem; line-height: 1.1; color: var(--ink); }
.sm-readout-line { font-size: 1.5rem; font-weight: 600; color: var(--ink); }
.sm-readout-dirs { font-size: 1rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.sm-label { font-weight: 600; color: var(--ink); }
.sm-rings { display: flex; flex-wrap: wrap; gap: 24px; }
.sm-ring-block { display: grid; gap: 8px; justify-items: start; }
.sm-ring { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 6px; }
.sm-ring-btn { width: 64px; height: 64px; min-height: 64px; padding: 0; border-radius: 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--control-line); font-size: 15px; font-weight: 600; }
.sm-ring-btn:hover { background: var(--selected); }
.sm-ring-btn[aria-pressed="true"] { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.sm-ring-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--control-line); place-self: center; }
textarea { width: 100%; font: inherit; color: var(--ink); background: var(--recessed); border: 1px solid var(--control-line); border-radius: 12px; padding: 12px 14px; resize: vertical; }
.sm-enc-seq { display: flex; flex-wrap: wrap; gap: 8px; }
.sm-enc-seq:empty { display: none; }
.sm-enc-card { display: grid; justify-items: center; gap: 2px; background: var(--recessed); border: 1px solid var(--line); border-radius: 14px; padding: 8px 6px 6px; width: 108px; text-align: center; }
.sm-enc-card.sm-enc-sign { border-color: var(--accent); }
.sm-enc-card.sm-enc-unsupported { border-color: var(--bad); }
.sm-enc-figure { width: 76px; }
.sm-enc-figure .sm-figure { width: 100%; height: auto; }
.sm-enc-q { display: grid; place-items: center; height: 88px; font-size: 2rem; font-weight: 600; color: var(--bad); }
.sm-enc-top { font-size: 13px; font-weight: 600; color: var(--ink); }
.sm-enc-dirs { font-size: 11px; color: var(--muted); line-height: 1.35; }
.sm-sub-h { font-size: 1rem; margin: 8px 0 0; }
.sm-chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 8px; }
.sm-chart-cell { display: grid; justify-items: center; gap: 0; background: var(--recessed); border: 1px solid var(--line); border-radius: 14px; padding: 8px 4px 6px; text-align: center; color: var(--ink); }
.sm-chart-cell:hover { background: var(--selected); }
.sm-chart-figure { width: 72px; }
.sm-chart-figure .sm-figure { width: 100%; height: auto; }
.sm-chart-key { font-size: 1rem; font-weight: 600; color: var(--ink); }
.sm-chart-dirs { font-size: 11px; color: var(--muted); line-height: 1.35; }
.sm-quiz-meta { color: var(--muted); }
.sm-quiz-meta strong { color: var(--ink); }
.sm-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.sm-options button { font-size: 1.5rem; min-height: 56px; }
.sm-options button.sm-picked-correct { background: var(--good); color: #fff; }
.sm-options button.sm-picked-wrong { background: var(--bad); color: #fff; }
.sm-feedback { font-size: 1rem; color: var(--ink); min-height: 1.5em; }
.sm-feedback:empty { display: none; }
.sm-feedback.sm-good { color: var(--good); font-weight: 600; }
.sm-feedback.sm-bad { color: var(--bad); font-weight: 600; }
.sm-feedback-figure { width: 120px; }
.sm-feedback-figure .sm-figure { width: 100%; height: auto; }
.sm-result-line { font-size: 1.125rem; color: var(--ink); }
.sm-result-line strong { font-variant-numeric: tabular-nums; }
.sm-review { display: grid; gap: 8px; }
.sm-review:empty { display: none; }
.sm-review-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--recessed); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.sm-review-figure { width: 52px; flex: none; }
.sm-review-figure .sm-figure { width: 100%; height: auto; }
.sm-review-letter { font-weight: 600; color: var(--ink); }
.sm-review-wrong { color: var(--bad); }
#board-msg:empty, #encode-msg:empty, #quiz-best:empty { display: none; }
@media (max-width: 640px) {
  .sm-options { grid-template-columns: repeat(2, 1fr); }
  .sm-big-char { font-size: 3.5rem; }
  .sm-ring { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(3, 56px); }
  .sm-ring-btn { width: 56px; height: 56px; min-height: 56px; font-size: 14px; }
  .sm-enc-card { width: 96px; }
}
