:root {
  --blue: #0a3d91;
  --blue-dark: #072c6b;
  --blue-bright: #1e6fe0;
  --ice: #e8f1fc;
  --white: #ffffff;
  --ink: #0e2244;
  --line: #c5d7f2;
  --muted: #4d648a;
  --finish: #0c8a38;
  --bogey: #d21b28;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--ice);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--blue); }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) 14px calc(20px + env(safe-area-inset-left));
  background: var(--white);
  border-bottom: 4px solid var(--blue);
}

.brand {
  color: var(--blue);
  font-weight: 800;
  font-size: 1.25rem;
  text-decoration: none;
  letter-spacing: -0.03em;
}

nav { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
nav a, nav .linkish { text-decoration: none; font-weight: 650; }

.inline { margin: 0; }

.linkish {
  background: none;
  border: 0;
  color: var(--blue);
  font: inherit;
  font-weight: 650;
  padding: 0;
  cursor: pointer;
}

main {
  padding: 24px max(16px, env(safe-area-inset-right)) calc(64px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.page main { max-width: 1100px; margin: 0 auto; }
.board main { max-width: 1200px; margin: 0 auto; }

.lead { color: var(--muted); max-width: 62ch; }
.muted { color: var(--muted); }
.kicker { color: var(--blue); font-weight: 700; margin-top: 0; }

.flash {
  max-width: 1100px;
  margin: 12px auto 0;
  padding: 12px 16px;
  background: var(--white);
  border-left: 6px solid var(--blue);
  font-weight: 650;
}
.flash.warn { border-left-color: var(--blue-dark); background: #d7e6fa; }

.menu, .split { display: grid; gap: 16px; }
.menu { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin: 20px 0 32px; }
.menu a, .panel, .pairing, .statgrid article {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.menu a {
  display: block;
  padding: 22px 16px;
  text-decoration: none;
  font-size: 1.15rem;
  font-weight: 750;
  color: var(--blue-dark);
}
.menu a:hover { border-color: var(--blue); }

.split { grid-template-columns: 1.3fr 0.9fr; align-items: start; }
.narrow { max-width: 520px; }
.panel { padding: 16px 18px 20px; }

label, .seed { display: grid; gap: 6px; font-weight: 650; }
.stack { display: grid; gap: 14px; }
input, select, button {
  font: inherit;
  color: var(--ink);
}
input, select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--white);
  max-width: 100%;
}
.stack input, .stack select { width: 100%; min-width: 0; }
button, .ghost {
  border-radius: 6px;
  border: 0;
  background: var(--blue);
  color: var(--white);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.ghost {
  background: var(--white);
  color: var(--blue);
  border: 1px solid var(--blue);
}
.ghost.off { color: var(--muted); border-color: var(--line); }

.people, .matchlist { list-style: none; padding: 0; margin: 16px 0; }
.people li, .matchlist li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.matchlist a {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  flex: 1;
  text-decoration: none;
  color: var(--ink);
  align-items: center;
}
.matchlist a span { color: var(--blue); font-weight: 800; text-align: center; }
.matchlist small, .people a { color: var(--muted); }
.people a.ghost, .people a.person { color: var(--blue); }
.people a.person { color: var(--ink); }
.person-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.person-actions form { margin: 0; }

.seed {
  grid-template-columns: auto 1fr 88px;
  align-items: center;
  font-weight: 550;
}
fieldset { border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 8px; }
legend { padding: 0 6px; color: var(--blue); font-weight: 700; }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.scoreboard article {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px 12px;
  min-height: 240px;
  min-width: 0;
}
.scoreboard article.turn {
  background: var(--blue);
  color: var(--white);
  border-color: var(--blue-dark);
}
.scoreboard header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: start; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who p { margin: 2px 0 0; }
.who h2 a { color: inherit; text-decoration: none; }
.person {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--ice);
  flex: none;
  display: grid;
  place-items: center;
  color: var(--blue);
  font-weight: 800;
}
.portrait {
  width: 112px;
  height: 112px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--ice);
}
.player-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.player-head h1 { margin: 0 0 8px; }
.photo-form { max-width: 420px; margin: 8px 0 18px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.scoreboard h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font-size: 1.6rem; }
.scoreboard header p { margin: 4px 0 0; opacity: 0.8; }
.badge {
  background: var(--white);
  color: var(--blue);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 800;
}
.badge.quiet {
  background: var(--blue);
  color: var(--white);
}
.scoreboard article.turn .badge.quiet {
  background: var(--white);
  color: var(--blue);
}
.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}
.remain {
  margin: 8px 0 0;
  font-family: "Arial Narrow", "Segoe UI", sans-serif;
  font-size: clamp(4.2rem, 10vw, 8rem);
  line-height: 0.9;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.remain.small { font-size: 4rem; }
.legs { margin: 0; font-weight: 750; }
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 12px;
  margin: 14px 0 0;
}
.stats div { display: grid; }
.stats dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.75; }
.stats dd { margin: 0; font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats.plain { background: var(--white); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.stats.plain.big { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin: 16px 0; }
.stats.plain dd { color: var(--blue); font-size: 1.6rem; }

.board .player-main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 6px;
}
.board .score-alone { text-align: center; }
.board .score-alone .remain { margin: 0; font-size: clamp(6.4rem, 13vw, 10.5rem); }
.board .remain.finish { color: var(--finish); }
.board .remain.bogey { color: var(--bogey); }
.scoreboard article.turn .remain.finish { color: #8cffb0; }
.scoreboard article.turn .remain.bogey { color: #ff9b9b; }
.board .score-alone .legs { margin-top: 4px; }
.board .stats.side {
  margin: 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.scoreboard article.turn .stats.side { border-top-color: rgba(255, 255, 255, 0.35); }
.protocol {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px clamp(6px, 2vw, 14px);
  align-items: center;
}
.leg-name { margin: 0; font-weight: 800; color: var(--blue); text-align: center; overflow-wrap: break-word; }
.proto {
  container-type: inline-size;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  gap: clamp(4px, 4cqi, 16px);
  min-width: 0;
  min-height: 0;
  padding: 6px 8px;
  padding: clamp(4px, 3cqi, 8px) clamp(4px, 4cqi, 16px);
  border-radius: 10px;
  background: var(--ice);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.proto.blank { background: transparent; padding: 0; min-height: 0; }
.proto form { width: 100%; margin: 0; }
.proto .score {
  font-size: clamp(1.15rem, 4.2vw, 3.4rem);
  font-size: clamp(1.05rem, 22cqi, 3.4rem);
  line-height: 0.95;
  white-space: nowrap;
}
.proto .rest {
  font-size: clamp(0.85rem, 2.6vw, 1.9rem);
  font-size: clamp(0.75rem, 13cqi, 1.9rem);
  font-weight: 700;
  opacity: 0.62;
  white-space: nowrap;
}
.board .scoreboard article { min-height: 0; }

.desk { display: grid; grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
.shortcut-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.shortcut-row button {
  min-width: 58px;
  min-height: 40px;
  padding: 3px 6px;
  background: var(--white);
  color: var(--blue-dark);
  border: 1px solid var(--line);
  display: grid;
  justify-items: center;
  align-content: center;
  line-height: 1.05;
}
.shortcut-row small { font-size: 0.62rem; letter-spacing: 0.04em; opacity: 0.7; }
.shortcut-row span { font-size: 0.95rem; }

.legboard {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.legboard h3 { margin: 0 0 12px; }
.visit-input {
  width: 100%;
  max-width: 8.5rem;
  height: clamp(3.4rem, 16vw, 5.2rem);
  margin: 0 auto;
  display: block;
  padding: 0 8px;
  border: 2px solid var(--blue);
  border-radius: 10px;
  background: var(--white);
  text-align: center;
  font-size: clamp(1.35rem, 6vw, 2.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.proto .rest.finish { color: var(--finish); opacity: 1; }
.proto .rest.bogey { color: var(--bogey); opacity: 1; }
.proto.bust .score { text-decoration: line-through; }
.proto.checkout { color: var(--blue); background: #d7e6fa; }
.proto-darts {
  text-align: center;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}
.proto-darts.head {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.visit-input:focus { outline: 2px solid var(--blue-bright); outline-offset: 1px; }
.history, .entry {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.history ol { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow: auto; }
.history li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid var(--ice);
}
.history li.bust strong { text-decoration: line-through; }
.history li.checkout strong { color: var(--blue); }
.share { word-break: break-all; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.keys button, .choices button {
  min-height: 72px;
  font-size: 1.6rem;
  background: var(--ice);
  color: var(--blue-dark);
}
.keys button.ok, .prompt button { background: var(--blue); color: var(--white); }
.prompt h3 { margin-top: 0; }

.banner {
  background: var(--blue);
  color: var(--white);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 1.4rem;
  font-weight: 800;
}
.banner:empty { display: none; }

.tablewrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--white); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { background: var(--blue); color: var(--white); font-weight: 700; }
th a { color: var(--white); text-decoration: none; }
tbody tr:nth-child(even) { background: var(--ice); }

.bracket { display: flex; gap: 16px; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; }
.bracket section { min-width: 240px; display: grid; gap: 12px; align-content: start; }
.pairing { padding: 12px; display: grid; gap: 4px; }
.pairing .win { color: var(--blue); font-weight: 800; }
.legs-line { color: var(--blue); font-weight: 800; margin: 4px 0; }

.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.statgrid article, .leg { padding: 14px; }
.statgrid.compact { grid-template-columns: 1fr 1fr; }
.leg { margin-bottom: 10px; }

.last { font-weight: 700; }

body.overlay {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--blue);
  color: var(--white);
  padding: calc(12px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
  display: grid;
  align-content: center;
}
.ov-kicker { margin: 0 0 8px; font-weight: 700; opacity: 0.85; overflow-wrap: anywhere; }
.ov-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.ov-bar section { min-width: 0; padding: 8px 12px; border-radius: 8px; }
.ov-bar section p { overflow-wrap: anywhere; }
.ov-bar section.turn { background: var(--white); color: var(--blue); }
.ov-bar h2 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.4rem); }
.ov-remain {
  margin: 0;
  font-size: clamp(3rem, 10vw, 7rem);
  line-height: 0.9;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.ov-last { margin: 8px 0 0; font-size: 1.1rem; }

@media (max-width: 860px) {
  .split, .desk, .scoreboard, .statgrid, .statgrid.compact, .board .player-main { grid-template-columns: 1fr; }
  .stats, .board .stats.side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board .stats.side dd, .stats dd { font-size: 1.05rem; }
  .top { align-items: flex-start; flex-direction: column; }
  nav a, nav .linkish { display: inline-flex; align-items: center; min-height: 44px; }
  .shortcut-row button { min-height: 44px; }
  .people li, .matchlist li { flex-direction: column; align-items: stretch; }
  .person-actions { width: 100%; }
  .board .score-alone .remain { font-size: clamp(4.8rem, 24vw, 8rem); }
}
@media (max-width: 520px) {
  .choices { grid-template-columns: 1fr 1fr; }
  .choices button, .keys button { min-height: 56px; font-size: 1.2rem; }
  .ov-bar { grid-template-columns: 1fr; gap: 10px; }
  .legboard { padding: 10px; }
}
@media (min-width: 861px) {
  .board .stats.side > div:nth-child(8) { grid-column: 1; }
}
