/* 珠算 Abacus — 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;
  --wood: #a97c50;
  --wood-dark: #8a5f3a;
  --beam: #7c5233;
  --bead: #5d3a1e;
  --bead-hi: #8a5f3a;
  --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;
  --wood: #8a6a44;
  --wood-dark: #6e5232;
  --beam: #6b4a2c;
  --bead: #c89b6d;
  --bead-hi: #e0b98a;
}
* { 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; }
.fineprint { font-size: 13px; color: var(--muted); }
.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); }
#status:empty, #msg:empty { display: none; }
.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; } }

/* ---- Abacus ---- */
.ab-readout { text-align: center; display: grid; gap: 4px; }
.ab-value { font-size: clamp(2.5rem, 8vw, 4rem); font-weight: 700; letter-spacing: -.03em; line-height: 1.1; color: var(--ink); }
.ab-reading { font-size: 1.125rem; color: var(--muted); min-height: 1.6em; }
.ab-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.ab-stat { text-align: center; background: var(--recessed); border-radius: 14px; padding: 12px 8px; }
.ab-stat .num { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; color: var(--ink); }
.ab-stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ab-board { background: linear-gradient(180deg, var(--wood), var(--wood-dark)); border-radius: 20px; padding: 18px 14px 10px; display: flex; justify-content: center; gap: 6px; position: relative; }
.ab-rod { position: relative; width: 62px; flex: 0 1 62px; }
.ab-rod::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 48px; width: 3px; margin-left: -1.5px; background: rgb(0 0 0 / .28); border-radius: 2px; }
.ab-upper { position: relative; height: 84px; }
.ab-beam { height: 10px; border-radius: 5px; background: var(--beam); box-shadow: 0 1px 2px rgb(0 0 0 / .35); position: relative; z-index: 2; }
.ab-lower { position: relative; height: 210px; margin-top: 0; }
.ab-bead { position: absolute; left: 50%; width: 54px; height: 34px; margin-left: -27px; border-radius: 50%; background: radial-gradient(ellipse at 50% 28%, var(--bead-hi), var(--bead) 68%); box-shadow: 0 2px 4px rgb(0 0 0 / .35), inset 0 1px 1px rgb(255 255 255 / .25); cursor: pointer; transition: top .18s cubic-bezier(.16, 1, .3, 1); z-index: 1; }
.ab-bead:active { filter: brightness(1.12); }
.ab-bead:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ab-digit { text-align: center; font-size: 1.25rem; font-weight: 700; color: #fff; margin-top: 6px; text-shadow: 0 1px 2px rgb(0 0 0 / .3); }
.ab-unit { text-align: center; font-size: 12px; color: rgb(255 255 255 / .8); }
.ab-rod-labels { background: var(--recessed); border-radius: 0 0 14px 14px; margin: 0 0 4px; }
#msg { font-size: 15px; min-height: 1.5em; }
.ab-msg-good { color: var(--good); }
.ab-msg-bad { color: var(--bad); }
#target-line { font-size: 15px; color: var(--ink); }
#target-line strong { font-size: 1.25rem; }
@media (max-width: 640px) {
  .ab-stats { grid-template-columns: repeat(2, 1fr); }
  .ab-rod { width: 44px; flex-basis: 44px; }
  .ab-bead { width: 40px; height: 30px; margin-left: -20px; }
  .ab-board { gap: 2px; padding: 14px 6px 8px; }
  .ab-unit { font-size: 11px; }
}
