/* Bowling Score Calculator. Score-sheet paper, ink and lane maple. */

:root {
  --paper: #f5f0e6;
  --card: #fffdf8;
  --ink: #182338;
  --ink-soft: #2c3a57;
  --muted: #5a6273;
  --line: #ddd3c1;
  --line-strong: #b9ad97;
  --lane: #c58a3d;
  --lane-2: #d9a35c;
  --strike: #c22f2a;
  --spare: #1d5ea8;
  --good: #2e7a4d;
  --focus: #1d5ea8;
  --active: #fff3d6;
  --head-bg: #182338;
  --head-ink: #f5f0e6;
  --shadow: 0 1px 0 rgba(24, 35, 56, .06), 0 6px 18px -10px rgba(24, 35, 56, .35);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #11151d;
    --card: #19202b;
    --ink: #ece6da;
    --ink-soft: #cfc8bb;
    --muted: #a3aab7;
    --line: #2d3545;
    --line-strong: #46516a;
    --lane: #e2a65a;
    --lane-2: #b9813f;
    --strike: #ff6e62;
    --spare: #82b4ff;
    --good: #6fd296;
    --focus: #82b4ff;
    --active: #2a2a22;
    --head-bg: #0b0e14;
    --head-ink: #ece6da;
    --shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 8px 20px -12px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.6 var(--sans);
  overflow-x: hidden;
}

a { color: var(--spare); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 50;
  background: var(--card); color: var(--ink); padding: 8px 12px; border-radius: 6px;
}
.skip:focus { left: 8px; }

.wrap { width: min(1160px, 100% - 32px); margin-inline: auto; }
.narrow { width: min(760px, 100% - 32px); margin-inline: auto; }

/* ---------- Header ---------- */

.site-head { background: var(--head-bg); color: var(--head-ink); }
.head-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px 24px; flex-wrap: wrap; padding: 12px 0;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: inherit; text-decoration: none; font-weight: 800; letter-spacing: -.01em;
}
.brand-mark { width: 28px; height: 28px; fill: var(--lane-2); }
.brand-mark .hole { fill: var(--head-bg); }
.site-nav { display: flex; gap: 4px 18px; flex-wrap: wrap; font-size: .94rem; }
.site-nav a { color: inherit; opacity: .78; text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.site-nav a:hover { opacity: 1; }
.site-nav a[aria-current="page"] { opacity: 1; border-bottom-color: var(--lane-2); }

@media (max-width: 620px) {
  .head-row { padding: 10px 0; gap: 4px 16px; }
  .brand { font-size: .98rem; }
  .brand-mark { width: 24px; height: 24px; }
  .site-nav { gap: 2px 16px; font-size: .88rem; }
  .intro { padding: 18px 0 2px; }
  .intro p { font-size: .94rem; line-height: 1.5; }
  .tool { padding-top: 12px; }
  .toolbar { padding: 8px 10px; gap: 8px 14px; margin-bottom: 10px; }
  .toolbar .spacer { display: none; }
  .toolbar .btn { min-height: 36px; padding: 4px 12px; }
  #auto-switch-wrap { order: 3; }
}

/* lane boards under the header */
.lane {
  height: 10px;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 1px, transparent 1px 22px),
    linear-gradient(var(--lane-2), var(--lane));
}

/* ---------- Page intro ---------- */

.intro { padding: 28px 0 8px; }
.intro h1 {
  margin: 0 0 6px; font-size: clamp(1.75rem, 4.2vw, 2.6rem);
  line-height: 1.1; letter-spacing: -.025em; font-weight: 850;
}
.intro p { margin: 0; color: var(--muted); max-width: 62ch; }

/* ---------- Tool ---------- */

.tool { padding: 18px 0 40px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 10px 14px; margin-bottom: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.toolbar .spacer { flex: 1; }

.btn {
  font: inherit; font-weight: 650; font-size: .94rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 6px 14px; border-radius: 8px; cursor: pointer;
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong);
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-soft); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }

.check { display: inline-flex; align-items: center; gap: 8px; font-size: .94rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }

.field { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); }
.field input, .input {
  font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px; min-height: 36px;
}
.field input { width: 4.6em; font-variant-numeric: tabular-nums; }
.hdcp-settings { display: inline-flex; gap: 12px; flex-wrap: wrap; }
.hdcp-settings[hidden] { display: none; }

.tool-grid { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1020px) {
  .tool-grid { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .side { position: sticky; top: 14px; }
}

.sheets { display: grid; gap: 14px; min-height: 180px; }

/* ---------- Score sheet ---------- */

.sheet {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px 12px; position: relative;
  transition: border-color .15s, background-color .15s;
}
.sheet.is-active { border-color: var(--lane); box-shadow: 0 0 0 2px var(--lane), var(--shadow); }
.sheet-head { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; margin-bottom: 10px; }
.sheet-name {
  flex: 0 1 11em; min-width: 4em;
  font: inherit; font-weight: 750; font-size: 1.05rem; color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px; margin-left: -6px; width: 11em;
}
@supports (field-sizing: content) {
  .sheet-name { field-sizing: content; width: auto; flex: 0 1 auto; min-width: 5em; max-width: 14em; }
}
.sheet-name:hover { border-color: var(--line); }
.sheet-name:focus { border-color: var(--line-strong); background: var(--paper); }
.turn-badge {
  flex: none;
  font-size: .72rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em;
  background: var(--lane); color: #1b1407; border-radius: 99px; padding: 2px 8px;
}
.done-badge { background: var(--good); color: var(--card); }
.sheet-avg { margin-left: auto; }
.sheet-avg + .sheet-total { margin-left: 8px; }
.sheet-avg[hidden] + .sheet-total { margin-left: auto; }
@media (max-width: 620px) {
  .sheet-head { flex-wrap: nowrap; }
  .sheet-name, .sheet-head .sheet-name { flex: 1 1 0; max-width: none; }
  .turn-badge:not(.done-badge) { display: none; }
  .sheet-avg { order: 5; }
  .sheet-head:has(.sheet-avg:not([hidden])) { flex-wrap: wrap; }
  .sheet-head:has(.sheet-avg:not([hidden])) .sheet-avg { flex-basis: 100%; margin-left: 0; }
  .sheet-total { max-width: 58%; }
  .sheet-total small { display: block; }
  .key-act { font-size: .7rem; }
}
.sheet-total { margin-left: auto; text-align: right; line-height: 1.1; flex: none; }
.sheet-total .big { display: block; font: 800 1.7rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.sheet-total small { color: var(--muted); font-size: .78rem; }
.sheet-remove {
  font: inherit; font-size: 1.2rem; line-height: 1; width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.sheet-remove:hover { color: var(--strike); border-color: var(--line); }

.frames {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)) minmax(0, 1.45fr);
  border: 2px solid var(--ink); border-radius: 4px; overflow: hidden;
  background: var(--card);
}
.frame { border-left: 1px solid var(--ink); display: flex; flex-direction: column; min-width: 0; }
.frame:first-child { border-left: 0; }
.fno {
  font-size: .68rem; font-weight: 700; text-align: center; color: var(--muted);
  border-bottom: 1px solid var(--line-strong); padding: 1px 0; letter-spacing: .04em;
}
.balls { display: flex; justify-content: flex-end; }
.ball {
  font: 700 1rem/1 var(--mono); color: var(--ink);
  width: 50%; max-width: 30px; aspect-ratio: 1 / 1; min-height: 26px;
  display: grid; place-items: center; padding: 0;
  background: transparent; border: 0; border-left: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong);
  cursor: pointer;
}
.frame:last-child .ball { width: 33.33%; }
.frame:last-child .ball:first-child { border-left: 0; }
.ball:hover { background: var(--active); }
.ball.is-x { color: var(--strike); }
.ball.is-spare { color: var(--spare); }
.ball.is-cursor { background: var(--lane); color: #1b1407; }
.ball.is-next { box-shadow: inset 0 -3px 0 var(--lane); }
.ball[disabled] { cursor: default; }
.ball[disabled]:hover { background: transparent; }
.ftotal {
  font: 800 1.05rem/1 var(--mono); font-variant-numeric: tabular-nums;
  text-align: center; padding: 8px 2px 9px; min-height: 2.1em;
}
.frame.is-current { background: var(--active); }

/* score sheet on phones: two rows of five */
@media (max-width: 620px) {
  .frames { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .frame:nth-child(6) { border-left: 0; }
  .frame:nth-child(n+6) { border-top: 2px solid var(--ink); }
  .sheet { padding: 10px; }
  .sheet-head { padding-right: 30px; }
  .sheet-remove { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; }
  .sheet-total .big { font-size: 1.45rem; }
}

.type-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: .88rem; }
.type-row label { color: var(--muted); }
.rolls-input { flex: 1 1 16em; font-family: var(--mono); font-size: .92rem; min-width: 0; }
.rolls-input[aria-invalid="true"] { border-color: var(--strike); }
.type-err { color: var(--strike); width: 100%; margin: 0; min-height: 0; }
.type-err:empty { display: none; }

/* ---------- Pin pad ---------- */

.side { display: grid; gap: 14px; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px;
}
.panel h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }

.pad-status { margin: 0 0 10px; font-weight: 650; font-size: .95rem; min-height: 1.6em; }
.pad-status .hint { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; }
.pad-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.key {
  font: 750 1.25rem/1 var(--mono); min-height: 50px; border-radius: 8px; cursor: pointer;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line-strong);
  border-bottom-width: 3px; touch-action: manipulation;
}
.key:hover { border-color: var(--ink-soft); }
.key:active { transform: translateY(1px); border-bottom-width: 2px; }
.key:disabled { opacity: .3; cursor: not-allowed; transform: none; }
.key-x { color: var(--strike); }
.key-spare { color: var(--spare); }
.key-act { font: 650 .92rem/1.1 var(--sans); grid-column: span 2; border-bottom-width: 1px; background: var(--card); }
.key-new { color: var(--muted); }
.key-act:active { transform: none; }

/* phones: pad sticks to the bottom while the score sheets are on screen.
   .side dissolves so the pad's sticky container is the whole tool grid. */
@media (max-width: 1019px) {
  .side { display: contents; }
  .pad-panel {
    position: sticky; bottom: 0; z-index: 5;
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -8px 24px -14px rgba(0,0,0,.5);
  }
}
/* below desktop: two rows of seven, Undo ends row one, New game ends row two */
@media (max-width: 1019px) {
  .pad-keys { grid-template-columns: repeat(7, 1fr); gap: 6px; }
  .pad-keys .key { order: 3; }
  .pad-keys .k-lo { order: 1; }
  .key-undo { order: 2 !important; }
  .key-new { order: 4 !important; }
  .key-act { grid-column: span 1; font-size: .78rem; padding: 0 2px; }
}
@media (max-width: 620px) {
  .pad-keys { gap: 5px; }
  .key { min-height: 44px; font-size: 1.1rem; }
  .pad-panel { padding: 8px 10px 10px; }
  .pad-status { margin-bottom: 6px; font-size: .88rem; min-height: 0; }
  .pad-status .hint { display: none; }
}

/* ---------- Standings ---------- */

.standings table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.standings th, .standings td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.standings th { font-size: .72rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; }
.standings th:nth-child(2), .standings td:nth-child(2) { text-align: left; }
.standings td { font-variant-numeric: tabular-nums; }
.standings td.num { font-family: var(--mono); }
.standings .tot { font-weight: 800; }
.standings .out td { color: var(--muted); }
.standings tr:last-child td { border-bottom: 0; }
.result-line { margin: 10px 0 0; font-size: .9rem; }
.result-line strong { color: var(--good); }

.exports { display: flex; flex-wrap: wrap; gap: 6px; }
.exports .btn { flex: 1 1 auto; font-size: .86rem; min-height: 36px; }
.toast { font-size: .85rem; color: var(--good); margin: 8px 0 0; min-height: 1.3em; }

/* ---------- Content ---------- */

.content { padding: 8px 0 56px; }
.content h2 { font-size: 1.45rem; letter-spacing: -.015em; line-height: 1.25; margin: 2.2em 0 .5em; }
.content h3 { font-size: 1.1rem; margin: 1.6em 0 .4em; }
.content p, .content li { max-width: 68ch; }
.content ul, .content ol { padding-left: 1.3em; }
.content li + li { margin-top: .3em; }
.content code, kbd {
  font-family: var(--mono); font-size: .9em; background: var(--card);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}

.table-wrap { overflow-x: auto; margin: 1em 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.data { border-collapse: collapse; width: 100%; font-size: .93rem; }
.data th, .data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data th { background: var(--paper); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.data tr:last-child td { border-bottom: 0; }
.data td.num, .data th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data .sym { font-family: var(--mono); font-weight: 800; font-size: 1.05rem; }

.callout {
  border-left: 4px solid var(--lane); background: var(--card);
  padding: 12px 16px; border-radius: 0 8px 8px 0; margin: 1.2em 0; max-width: 68ch;
}
.callout p { margin: 0; }

.faq details { border-bottom: 1px solid var(--line); padding: 12px 0; max-width: 72ch; }
.faq summary { font-weight: 700; cursor: pointer; list-style-position: outside; }
.faq details p { margin: .5em 0 0; }

.steps { counter-reset: s; list-style: none; padding: 0 !important; }
.steps li { counter-increment: s; position: relative; padding-left: 2.4em; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: .05em;
  width: 1.7em; height: 1.7em; border-radius: 50%;
  background: var(--ink); color: var(--paper); font-weight: 800; font-size: .85em;
  display: grid; place-items: center;
}

/* mini static score sheet used in the guide */
.mini { margin: 1em 0; max-width: 680px; }
.mini .frames { cursor: default; }
.mini .ball { cursor: default; }
.mini .ball:hover { background: transparent; }

/* ---------- Handicap calculator ---------- */

.calc {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; display: grid; gap: 18px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 760px) { .calc { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.calc-fields { display: grid; gap: 12px; align-content: start; }
.calc-fields label { display: grid; gap: 4px; font-weight: 650; font-size: .92rem; }
.calc-fields .help { font-weight: 400; color: var(--muted); font-size: .82rem; }
.calc-fields input { width: 100%; font-variant-numeric: tabular-nums; }
.calc-out { background: var(--paper); border-radius: 8px; padding: 16px; display: grid; gap: 12px; align-content: start; }
.stat { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border-bottom: 1px dashed var(--line-strong); padding-bottom: 8px; }
.stat:last-child { border-bottom: 0; }
.stat span { color: var(--muted); font-size: .92rem; }
.stat output { font: 800 1.6rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.stat.lead output { font-size: 2.3rem; color: var(--good); }
.formula { font-family: var(--mono); font-size: .88rem; color: var(--muted); margin: 0; }
.avg-helper { margin-top: 18px; }
.table-narrow { max-width: 460px; }
.avg-helper textarea { width: 100%; min-height: 70px; font-family: var(--mono); resize: vertical; }

/* ---------- Legal and 404 ---------- */

.legal h1 { margin-bottom: .2em; }
.legal .updated { color: var(--muted); margin-top: 0; }
.legal h2 { font-size: 1.2rem; margin-top: 1.8em; }

.notfound { padding: 60px 0 80px; text-align: center; }
.notfound .score404 { font: 900 clamp(4rem, 16vw, 8rem)/1 var(--mono); color: var(--strike); margin: 0; letter-spacing: -.04em; }
.notfound p { color: var(--muted); }

/* ---------- Footer ---------- */

.site-foot { border-top: 1px solid var(--line); background: var(--card); font-size: .9rem; color: var(--muted); }
.foot-row { display: flex; justify-content: space-between; gap: 10px 24px; flex-wrap: wrap; padding: 20px 0; align-items: center; }
.foot-row p { margin: 0; }
.foot-row nav { display: flex; gap: 6px 18px; flex-wrap: wrap; }
.foot-row a { color: var(--ink-soft); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .site-head, .site-foot, .side, .toolbar, .type-row, .content, .sheet-remove { display: none !important; }
  body { background: #fff; color: #000; }
  .sheet { box-shadow: none; border-color: #999; break-inside: avoid; }
}

.mini figcaption { font-family: var(--mono); font-size: .85rem; color: var(--muted); margin-top: 6px; }
.mini .ball { display: grid; }
@media (max-width: 620px) { .mini .ball { min-height: 22px; font-size: .9rem; } }
