/* MTG Mana Calculator. Design notes in DESIGN.md: graphite on white paper,
   one highlighter yellow, color only for the five mana markers. */

@font-face {
  font-family: "Schibsted Grotesk";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/schibsted-grotesk-latin.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-500-latin.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/fonts/ibm-plex-mono-600-latin.woff2") format("woff2");
}

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --sheet: #f4f4f1;
  --rule: #dcdcd6;
  --rule-strong: #878780;
  --ink: #17181b;
  --text: #3a3c42;
  --muted: #5f616a;
  --hl: #ffe14d;
  --on-hl: #17181b;
  --on-ink: #ffffff;
  --track: #e6e6e1;
  --fill-low: #8a8c94;
  --b-border: #2a2530;
  --sans: "Schibsted Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141518; --surface: #1c1d21; --sheet: #202126;
    --rule: #2e3036; --rule-strong: #717379;
    --ink: #f2f2ee; --text: #d2d3cd; --muted: #a3a49d;
    --on-ink: #141518; --track: #2e3036; --fill-low: #7c7e86; --b-border: #5a5463;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141518; --surface: #1c1d21; --sheet: #202126;
  --rule: #2e3036; --rule-strong: #717379;
  --ink: #f2f2ee; --text: #d2d3cd; --muted: #a3a49d;
  --on-ink: #141518; --track: #2e3036; --fill-low: #7c7e86; --b-border: #5a5463;
  color-scheme: dark;
}

html { scroll-padding-top: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--hl); color: var(--on-hl); }
input, textarea, select { caret-color: var(--ink); }
a { color: var(--ink); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { color: var(--ink); line-height: 1.15; text-wrap: balance; }
p, li { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
button, input, select, textarea, summary, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums lining-nums; font-weight: 500; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: 16px; }
@media (min-width: 720px) { .wrap { padding-inline: 24px; } }

.skip-link { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--on-ink); padding: 10px 14px; border-radius: 6px; z-index: 10; }
.skip-link:focus { top: 8px; }

/* ---------- header ---------- */
.site-header { border-bottom: 1px solid var(--rule); }
.head-row { display: flex; align-items: center; gap: 12px 20px; min-height: 64px; flex-wrap: wrap; padding-block: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; text-decoration: none; color: var(--ink); min-height: 44px; }
.brand .mark { width: 28px; height: 28px; color: var(--ink); flex: none; }
.nav { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.nav a { padding: 10px 12px; border-radius: 6px; text-decoration: none; color: var(--text); font-weight: 500; font-size: 0.95rem; }
.nav a:hover { background: var(--sheet); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); border-radius: 0; }
.theme-toggle { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; padding: 2px; }
.theme-toggle button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px; color: var(--muted); cursor: pointer; }
.theme-toggle button:hover { color: var(--ink); }
.theme-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.icon { width: 18px; height: 18px; flex: none; }
@media (max-width: 640px) {
  .nav { order: 3; width: 100%; margin-left: -12px; }
  .theme-toggle { margin-left: auto; }
}
@media (pointer: coarse) { .theme-toggle button { width: 44px; height: 44px; } }

/* ---------- intro ---------- */
.intro { padding-block: 32px 20px; }
.intro h1 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.1rem); font-weight: 800; letter-spacing: -0.03em; }
.lede { margin-top: 12px; max-width: 64ch; font-size: 1.125rem; color: var(--text); }

/* ---------- the tool ---------- */
.tool { position: relative; padding-bottom: 8px; }
.sheet { border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
@media (min-width: 960px) {
  .sheet { display: grid; grid-template-columns: minmax(360px, 5fr) 7fr; }
  .inputs { border-right: 1px solid var(--rule); }
}
.inputs { background: var(--sheet); padding: 4px 20px 16px; min-width: 0; }
.field { border: 0; padding: 16px 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.field:last-child { border-bottom: 0; }
.field > label, .field legend, .pair label, .more-body > label { display: block; font-weight: 600; color: var(--ink); font-size: 0.95rem; margin-bottom: 8px; padding: 0; }
.hint { font-size: 0.875rem; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.field legend { float: left; width: 100%; }
.field legend + * { clear: both; }
.field legend + .hint { margin: 0 0 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 380px) { .pair { grid-template-columns: 1fr; } }

/* format segments */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
@media (max-width: 480px) { .seg { grid-template-columns: repeat(2, 1fr); } }
.seg-opt { position: relative; display: flex; flex-direction: column; justify-content: center; min-height: 52px; padding: 8px 10px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--surface); cursor: pointer; line-height: 1.2; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-main { font-weight: 700; color: var(--ink); font-size: 0.95rem; }
.seg-sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.seg-opt:hover { border-color: var(--ink); }
.seg-opt:has(input:checked) { background: var(--ink); border-color: var(--ink); }
.seg-opt:has(input:checked) .seg-main, .seg-opt:has(input:checked) .seg-sub { color: var(--on-ink); }
.seg-opt:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }

/* steppers */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--surface); overflow: hidden; }
.stepper input { width: 4.6ch; min-width: 0; border: 0; background: none; text-align: center; font-family: var(--mono); font-weight: 600; font-size: 1rem; color: var(--ink); padding: 0 2px; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; border-radius: 0; }
.step { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--ink); cursor: pointer; }
.step:hover { background: var(--sheet); }
.step:active { background: var(--rule); }
.step:focus-visible { outline-offset: -2px; border-radius: 0; }
@media (pointer: coarse) { .step { width: 44px; height: 44px; } }
.lands-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* color rows */
.colors { display: grid; gap: 6px; }
.color-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; }
.color-row label { font-weight: 500; color: var(--text); font-size: 0.95rem; }

/* mana markers: our own rounded squares, never the official symbols */
.mk { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 6px; font-family: var(--mono); font-weight: 600; font-size: 0.85rem; line-height: 1; flex: none; border: 1px solid transparent; }
.mk-W { background: #f3ead0; color: #4d4122; border-color: #c9b77f; }
.mk-U { background: #1f63b0; color: #ffffff; }
.mk-B { background: #2a2530; color: #f1eef5; border-color: var(--b-border); }
.mk-R { background: #c0392b; color: #ffffff; }
.mk-G { background: #23753f; color: #ffffff; }

/* disclosures */
.more { border-top: 1px solid var(--rule); }
.more summary { display: flex; align-items: center; gap: 8px; min-height: 52px; font-weight: 600; color: var(--ink); cursor: pointer; list-style: none; font-size: 0.95rem; }
.more summary::-webkit-details-marker { display: none; }
.more summary:hover, .faq summary:hover { text-decoration: underline; text-underline-offset: 0.18em; }
.chev { transition: transform 0.15s ease-out; }
details[open] > summary .chev { transform: rotate(90deg); }
.more-body { padding-bottom: 12px; }
.more-body .field { padding-top: 4px; border-bottom: 0; }
.more-body .colors { margin-bottom: 4px; }
textarea { display: block; width: 100%; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--surface); color: var(--ink); font-family: var(--mono); font-size: 0.875rem; line-height: 1.5; padding: 10px 12px; resize: vertical; }
textarea::placeholder { color: var(--muted); }
.lookup-status { font-size: 0.9rem; color: var(--ink); margin-top: 8px; }
.lookup-status:empty { margin: 0; }
#lookup { margin-top: 12px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--ink); border-radius: 8px; background: var(--ink); color: var(--on-ink); font-weight: 600; font-size: 0.95rem; cursor: pointer; }
.btn:hover { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--rule-strong); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: progress; }
.btn.quiet { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn.quiet:hover { border-color: var(--ink); box-shadow: none; }
.text-btn:hover { text-decoration-thickness: 2px; }
.text-btn { border: 0; background: none; padding: 6px 2px; min-height: 44px; color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; font-size: 0.95rem; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text); cursor: pointer; min-height: 44px; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }

/* results */
.results { padding: 4px 20px 16px; min-width: 0; }
.res-top { display: grid; gap: 0 28px; border-bottom: 1px solid var(--rule); }
@media (min-width: 640px) { .res-top { grid-template-columns: 1fr 1fr; } }
.res-block { padding: 16px 0; min-width: 0; }
.res-label { font-weight: 700; color: var(--ink); font-size: 0.95rem; line-height: 1.6; letter-spacing: 0; }
.big { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 6px; flex-wrap: wrap; }
.big .num, .big mark { font-family: var(--mono); font-weight: 600; font-size: 3.25rem; line-height: 1.05; letter-spacing: -0.04em; }
mark.hl { background: var(--hl); color: var(--on-hl); padding: 0 0.12em; border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.big-of { color: var(--muted); font-size: 0.95rem; }
.res-note { font-size: 0.9rem; color: var(--text); margin-top: 6px; line-height: 1.5; }
.res-note.empty { color: var(--muted); }

.split { list-style: none; padding: 0; margin-top: 8px; }
.split-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px 10px; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.split-name { font-weight: 600; color: var(--ink); }
.split-count { font-weight: 600; font-size: 1.35rem; color: var(--ink); text-align: right; }
.split-meta { grid-column: 2 / 4; font-size: 0.82rem; color: var(--muted); margin-top: -4px; }
.split-bar { display: flex; gap: 2px; height: 8px; margin-top: 12px; border-radius: 4px; overflow: hidden; }
.split-bar span { flex-basis: 0; min-width: 4px; }
.bar-W { background: #d9c98e; } .bar-U { background: #1f63b0; } .bar-B { background: #2a2530; box-shadow: inset 0 0 0 1px var(--b-border); } .bar-R { background: #c0392b; } .bar-G { background: #23753f; }

.cast-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 16px; }
.table-wrap { overflow-x: auto; }
.cast { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.95rem; }
.cast thead th { text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--muted); padding: 8px 8px 8px 0; border-bottom: 1px solid var(--rule-strong); vertical-align: bottom; line-height: 1.3; }
.cast td, .cast tbody th { padding: 10px 8px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: middle; text-align: left; font-weight: 400; }
.cast-color { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.cast-need { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.cast-need select { font-family: var(--mono); font-weight: 600; font-size: 0.85rem; color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 6px; padding: 6px 4px; min-height: 36px; cursor: pointer; }
@media (pointer: coarse) { .cast-need select { min-height: 44px; } }
.cast td .num { font-weight: 600; color: var(--ink); }
.meter { position: relative; display: block; height: 6px; margin-top: 6px; max-width: 120px; background: var(--track); border-radius: 3px; }
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--ink); }
.meter-fill.close { background: repeating-linear-gradient(135deg, var(--ink) 0 3px, transparent 3px 5px); }
.meter-fill.low { background: repeating-linear-gradient(135deg, var(--muted) 0 1.5px, transparent 1.5px 5px); box-shadow: inset 0 0 0 1px var(--muted); }
.meter-line { position: absolute; left: 90%; top: -3px; bottom: -3px; width: 3px; background: var(--hl); box-shadow: 0 0 0 1px var(--ink); border-radius: 1px; }
.delta { display: block; font-size: 0.8rem; font-weight: 700; color: var(--ink); line-height: 1.3; }
.delta.ok { font-weight: 400; color: var(--muted); }
.warn { font-size: 0.85rem; color: var(--ink); }

@media (max-width: 640px) {
  .cast thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cast, .cast tbody { display: block; }
  .cast tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .cast tbody th { grid-column: 1 / -1; border: 0; padding: 0; }
  .cast td { border: 0; padding: 0; }
  .cast td::before { content: attr(data-label); display: block; font-size: 0.78rem; color: var(--muted); }
  .cast td[data-cell="play"] { order: 1; } .cast td[data-cell="draw"] { order: 2; } .cast td[data-cell="sources"] { order: 3; } .cast td[data-cell="needed"] { order: 4; }
  .meter { max-width: none; }
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 16px; border-top: 1px solid var(--rule); margin-top: 4px; }
.action-status { font-size: 0.9rem; color: var(--ink); }

/* phone summary bar */
.peek { display: none; }
@media (max-width: 959px) {
  .peek:not([hidden]) { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; min-height: 52px; background: var(--ink); color: var(--on-ink); border-radius: 10px; text-decoration: none; font-size: 0.92rem; font-weight: 600; box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); }
  .peek-go { flex: none; background: var(--hl); color: var(--on-hl); padding: 4px 10px; border-radius: 6px; font-size: 0.85rem; }
  html { scroll-padding-bottom: 80px; }
}

/* hypergeometric page */
.hyper-presets { display: flex; flex-wrap: wrap; gap: 6px; padding: 16px 0 8px; }
.chip { min-height: 40px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: 999px; background: var(--surface); color: var(--ink); font-size: 0.85rem; font-weight: 500; cursor: pointer; }
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
@media (pointer: coarse) { .chip { min-height: 44px; } }
.odds { border-collapse: collapse; width: 100%; max-width: 360px; margin-top: 12px; }
.odds th, .odds td { padding: 8px 0; border-bottom: 1px solid var(--rule); text-align: left; font-weight: 400; }
.odds td { text-align: right; color: var(--ink); font-weight: 600; }
.hyper .results { padding-top: 12px; }
@media (min-width: 480px) { #hyper-inputs { display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; } .hyper-presets { grid-column: 1 / -1; } }
.hyper .results > div:first-child { padding: 4px 0 16px; }

/* ---------- content ---------- */
.content { padding-block: 24px 48px; }
.content > section, .content > article, .notfound > * { max-width: 68ch; }
.content section { margin-top: 44px; }
.content h2 { font-size: clamp(1.45rem, 1.2rem + 0.9vw, 1.85rem); font-weight: 800; letter-spacing: -0.02em; margin-bottom: 12px; }
.content h3 { font-size: 1.1rem; font-weight: 700; }
.content p + p, .content p + ul, .content ul + p, .content .table-wrap + p, .content p + .table-wrap, .content .table-wrap + .table-wrap { margin-top: 14px; }
.content ul { padding-left: 1.2em; }
.content li + li { margin-top: 8px; }
.content strong { color: var(--ink); }
.band { background: var(--sheet); border-radius: var(--radius); padding: 24px 20px; margin-inline: -4px; }
@media (min-width: 720px) { .band { padding: 28px 28px; margin-inline: -28px; } }

.data { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.data caption { text-align: left; font-weight: 700; color: var(--ink); padding-bottom: 8px; font-size: 0.95rem; }
.data th, .data td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.data thead th { font-size: 0.82rem; color: var(--muted); font-weight: 600; border-bottom-color: var(--rule-strong); }
.data tbody th { font-weight: 600; color: var(--ink); }
.pd { display: block; }
.pd + .pd { color: var(--muted); }
.data td { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 500; font-size: 0.9rem; white-space: nowrap; }

.steps { list-style: none; padding: 0; counter-reset: s; display: grid; gap: 16px; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 2rem 1fr; gap: 0 12px; }
.steps li::before { content: counter(s); grid-row: 1 / 3; font-family: var(--mono); font-weight: 600; color: var(--on-hl); background: var(--hl); width: 2rem; height: 2rem; display: grid; place-items: center; border-radius: 6px; }
.steps h3 { margin-top: 3px; }
.steps p { margin-top: 2px; }
.content .steps li + li { margin-top: 0; }

.related { list-style: none; padding: 0 !important; display: grid; gap: 0; border-top: 1px solid var(--rule); }
@media (min-width: 640px) { .related { grid-template-columns: 1fr 1fr; column-gap: 24px; } }
.content .related li + li { margin-top: 0; }
.related a { display: flex; flex-direction: column; padding: 12px 0; border-bottom: 1px solid var(--rule); text-decoration: none; min-height: 44px; }
.rel-title { font-weight: 700; color: var(--ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
.related a:hover .rel-title { text-decoration-thickness: 2px; }
.rel-blurb { font-size: 0.9rem; color: var(--muted); }

.faq details { border-bottom: 1px solid var(--rule); }
.faq details:first-of-type { border-top: 1px solid var(--rule); }
.faq summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 0; font-weight: 700; color: var(--ink); cursor: pointer; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq details p { padding: 0 0 16px 28px; }

/* legal + 404 */
.legal .content h1, .notfound h1 { font-size: clamp(2rem, 1.4rem + 2vw, 2.6rem); font-weight: 800; letter-spacing: -0.03em; margin-bottom: 8px; }
.legal article h2 { font-size: 1.3rem; margin: 32px 0 8px; }
.legal article p + p, .legal article ul { margin-top: 12px; }
.legal article ul { padding-left: 1.2em; }
.notfound .related { margin-top: 24px; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--rule); background: var(--sheet); margin-top: 24px; }
.foot-grid { display: grid; gap: 16px 32px; padding-block: 28px 32px; }
@media (min-width: 720px) { .foot-grid { grid-template-columns: 1fr auto; } }
.foot-main p { font-size: 0.92rem; margin-top: 4px; }
.site-footer nav { display: flex; gap: 4px 16px; flex-wrap: wrap; align-items: flex-start; }
.site-footer nav a { display: inline-flex; align-items: center; min-height: 44px; font-size: 0.95rem; }
.fan { grid-column: 1 / -1; font-size: 0.82rem; color: var(--muted); max-width: 68ch; border-top: 1px solid var(--rule); padding-top: 16px; }
