:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #1b1d22;
  --ink-2: #4a4f5a;
  --muted: #6f7480;
  --line: #e2dfd7;
  --accent: #2456c9;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfa;
  --win: #17824c;
  --win-soft: #e2f3ea;
  --loss: #c13a2f;
  --loss-soft: #f9e6e3;
  --draw: #6b6f78;
  --draw-soft: #ecebe7;
  --shadow: 0 1px 2px rgba(20, 22, 27, .04), 0 8px 24px rgba(20, 22, 27, .06);
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --surface: #1c1f26;
    --surface-2: #252932;
    --ink: #eceae4;
    --ink-2: #c3c5cc;
    --muted: #9095a1;
    --line: #2f333d;
    --accent: #7aa2ff;
    --accent-ink: #0f1420;
    --accent-soft: #232c44;
    --win: #4cc788;
    --win-soft: #1b3328;
    --loss: #ff7b6e;
    --loss-soft: #3a2220;
    --draw: #a7abb4;
    --draw-soft: #2a2d34;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; margin: 0; }
p { margin: 0 0 1rem; }
sup { line-height: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 12px; z-index: 100; background: var(--surface); padding: 8px 12px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 1.05rem; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.site-nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a { color: var(--ink-2); text-decoration: none; font-size: .92rem; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.site-nav a:hover { background: var(--surface-2); color: var(--ink); }
@media (max-width: 640px) { .site-nav .opt { display: none; } }
@media (max-width: 420px) { .site-nav .opt2 { display: none; } }

/* Hero */
.hero { padding: 48px 0 24px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 750; max-width: 18ch; }
.hero p { color: var(--ink-2); font-size: 1.125rem; max-width: 60ch; margin: 14px 0 0; }

/* Calculator */
.calc {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px;
  margin: 24px 0 20px;
}
@media (max-width: 860px) { .calc { grid-template-columns: minmax(0, 1fr); } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px;
}
@media (max-width: 480px) { .card { padding: 18px; } }
.card h2 { font-size: 1rem; font-weight: 650; margin-bottom: 16px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: .75rem; font-weight: 700; margin-right: 8px; vertical-align: 1px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }
label, .label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 6px; }

input[type=number] {
  width: 100%; height: 46px; padding: 0 14px;
  font: 600 1.15rem var(--font); font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
input[type=number]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=number]::placeholder { color: var(--muted); font-weight: 500; }
input[aria-invalid=true] { border-color: var(--loss); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  font: 600 .8rem var(--font); color: var(--ink-2); background: var(--surface-2);
  border: 1px solid transparent; border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip[aria-pressed=true] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }

.toggle { display: flex; align-items: center; gap: 10px; font-size: .88rem; color: var(--ink-2); margin: -8px 0 24px; cursor: pointer; font-weight: 500; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

.add { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; }
@media (max-width: 480px) { .add { grid-template-columns: auto minmax(0, 1fr); } .add > div:first-child { grid-column: 1 / -1; } }
@media (max-width: 480px) { .game-list .game { grid-template-columns: minmax(0, 1fr) auto 52px 28px; gap: 8px; } .game-list .game-n { display: none; } }
.game-r small { white-space: nowrap; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  font: 650 .85rem var(--font); min-width: 40px; height: 40px; padding: 0 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.seg.sm button { height: 30px; min-width: 32px; font-size: .78rem; padding: 0 8px; border-radius: 7px; }
.seg.sm { border-radius: 9px; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed=true][data-r="1"] { background: var(--win-soft); color: var(--win); }
.seg button[aria-pressed=true][data-r="0.5"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.seg button[aria-pressed=true][data-r="0"] { background: var(--loss-soft); color: var(--loss); }

.btn {
  font: 650 .92rem var(--font); height: 46px; padding: 0 18px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 85%, var(--bg)); }
.btn-ghost { border: 0; background: none; color: var(--muted); height: auto; padding: 4px 6px; font-size: .85rem; }
.btn-ghost:hover { color: var(--loss); background: none; }

.preview { font-size: .84rem; color: var(--muted); margin-top: 10px; min-height: 1.4em; font-variant-numeric: tabular-nums; }
.preview b { font-weight: 650; }

.games { margin-top: 24px; }
.games-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.games-head .label { margin: 0; }
.game-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.game {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto 64px 28px; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.game-n { color: var(--muted); font-size: .8rem; }
.game-r { font-weight: 650; }
.game-r small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.game-d { text-align: right; font-weight: 650; font-size: .92rem; }
.remove { width: 28px; height: 28px; border: 0; border-radius: 7px; background: none; color: var(--muted); cursor: pointer; font-size: 1.2rem; line-height: 1; }
.remove:hover { background: var(--loss-soft); color: var(--loss); }
.empty { color: var(--muted); font-size: .9rem; padding: 18px; text-align: center; border: 1px dashed var(--line); border-radius: 10px; }

.pos { color: var(--win); }
.neg { color: var(--loss); }
.zero { color: var(--draw); }

/* Result card */
.result { position: sticky; top: 80px; align-self: start; }
@media (max-width: 860px) { .result { position: static; } }
.result-label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.big { font-size: clamp(3rem, 8vw, 4rem); font-weight: 750; letter-spacing: -0.03em; line-height: 1.05; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.delta { display: inline-block; font-weight: 700; font-size: 1.05rem; padding: 2px 10px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.delta.pos { background: var(--win-soft); }
.delta.neg { background: var(--loss-soft); }
.delta.zero { background: var(--draw-soft); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 22px 0 18px; }
.stat { background: var(--surface); padding: 12px 14px; }
.stat dt { font-size: .76rem; color: var(--muted); font-weight: 600; }
.stat dd { margin: 2px 0 0; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.meter { display: grid; grid-template-columns: 64px minmax(0, 1fr) 40px; align-items: center; gap: 10px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 8px; }
.meter span:last-child { text-align: right; color: var(--ink); font-weight: 650; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--muted); transition: width .25s ease; }
.bar i.act { background: var(--accent); }
.formula-line { margin-top: 18px !important; font-family: var(--mono); font-size: .78rem; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 10px 12px; margin-top: 16px; overflow-wrap: anywhere; }
.result-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

/* Article */
.article { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 56px; padding-bottom: 64px; }
@media (max-width: 860px) { .article { grid-template-columns: minmax(0, 1fr); gap: 0; } .toc { display: none; } }
.toc { position: sticky; top: 84px; align-self: start; font-size: .88rem; }
.toc p { font-weight: 650; color: var(--ink); margin-bottom: 8px; }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.toc a { display: block; padding: 4px 0 4px 14px; color: var(--muted); text-decoration: none; margin-left: -1px; border-left: 1px solid transparent; }
.toc a:hover { color: var(--ink); border-left-color: var(--ink); }
.prose { max-width: 70ch; color: var(--ink-2); }
.prose section { margin-bottom: 56px; }
.prose h2 { font-size: clamp(1.5rem, 3vw, 1.85rem); color: var(--ink); margin-bottom: 16px; font-weight: 700; }
.prose h3 { font-size: 1.15rem; color: var(--ink); margin: 28px 0 10px; font-weight: 650; }
.prose strong { color: var(--ink); font-weight: 650; }
.prose ul, .prose ol { padding-left: 1.25rem; margin: 0 0 1rem; }
.prose li { margin-bottom: .4rem; }
.eq {
  font-family: var(--mono); font-size: .95rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 14px 16px; margin: 0 0 1rem; overflow-x: auto;
}
.table-wrap { overflow-x: auto; margin: 0 0 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td:first-child { color: var(--ink); font-weight: 600; }
.steps { counter-reset: s; list-style: none; padding: 0 !important; }
.steps li { counter-increment: s; position: relative; padding-left: 40px; margin-bottom: 14px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .8rem; display: grid; place-items: center; }
.callout { background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; color: var(--ink); margin: 0 0 1rem; }
details { border-bottom: 1px solid var(--line); padding: 14px 0; }
details:first-of-type { border-top: 1px solid var(--line); }
summary { cursor: pointer; font-weight: 650; color: var(--ink); list-style: none; display: flex; justify-content: space-between; gap: 16px; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--muted); font-weight: 500; font-size: 1.2rem; line-height: 1; }
details[open] summary::after { content: "–"; }
details p { margin: 10px 0 0; }

/* Footer */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 40px 0 28px; font-size: .9rem; color: var(--muted); }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 32px; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr 1fr; } .footer-grid > :first-child { grid-column: 1 / -1; } }
.site-footer h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); margin-bottom: 10px; font-weight: 650; }
.site-footer ul { list-style: none; margin: 0; padding: 0; }
.site-footer li { margin-bottom: 6px; }
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }
.footer-bottom { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); font-size: .84rem; }

/* Content pages (about, privacy, 404) */
.page { padding-top: 48px; padding-bottom: 72px; }
.page .hero { padding: 0 0 32px; }
.page .prose section { margin-bottom: 40px; }
.page .prose h2 { font-size: 1.35rem; }
.meta-line { font-size: .88rem; color: var(--muted); margin-top: 12px; }
.btn-link { display: inline-block; text-decoration: none; background: var(--ink); color: var(--bg); font-weight: 650; padding: 12px 20px; border-radius: 10px; }
.btn-link:hover { background: color-mix(in srgb, var(--ink) 85%, var(--bg)); }

/* iPhone app promo */
.app-promo {
  display: flex; align-items: center; gap: 16px; margin: 0 0 64px; padding: 16px 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.app-promo img { width: 56px; height: 56px; border-radius: 13px; flex: none; }
.app-promo-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: .92rem; color: var(--ink-2); }
.app-promo-text strong { color: var(--ink); font-size: 1rem; }
.app-btn {
  display: inline-flex; align-items: center; gap: 10px; flex: none; text-decoration: none;
  background: var(--ink); color: var(--bg); border-radius: 10px; padding: 8px 16px 8px 14px; font-weight: 650; font-size: 1.05rem; line-height: 1.1;
}
.app-btn small { display: block; font-size: .68rem; font-weight: 500; opacity: .85; }
.app-btn:hover { background: color-mix(in srgb, var(--ink) 85%, var(--bg)); }
@media (max-width: 560px) {
  .app-promo { flex-wrap: wrap; }
  .app-promo-text { flex-basis: calc(100% - 72px); }
  .app-btn { width: 100%; justify-content: center; }
}
