:root {
  color-scheme: dark;
  --ink: #160d25;
  --panel: #25123d;
  --panel-light: #321752;
  --purple: #7c2bd1;
  --pink: #ff3ea5;
  --yellow: #ffe13b;
  --mint: #70f6c6;
  --paper: #fff9e8;
  --muted: #c9b8db;
  --danger: #ff6b7d;
  --shadow: 0 18px 0 #0c0614;
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--paper); background: var(--ink); background-image: radial-gradient(circle at 12% 18%, #6c2289 0 2px, transparent 3px), radial-gradient(circle at 88% 8%, #f13b9c 0 2px, transparent 3px), linear-gradient(145deg, #160d25 0%, #281040 55%, #11101e 100%); }
button, input, select { font: inherit; }
button, summary, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 4px solid var(--yellow); outline-offset: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header { max-width: 1120px; margin: auto; padding: 1.2rem clamp(1rem, 4vw, 3rem); display: flex; align-items: center; justify-content: space-between; }
.logo { color: var(--paper); text-decoration: none; font-weight: 1000; font-style: italic; letter-spacing: -.08em; font-size: clamp(1.7rem, 5vw, 2.6rem); transform: rotate(-3deg); }
.logo span { color: var(--pink); }
.header-actions { display: flex; align-items: center; gap: clamp(.6rem, 2vw, 1.2rem); }
.text-button { color: var(--paper); border: 0; border-bottom: 2px solid var(--pink); background: transparent; padding: .5rem .2rem; font-weight: 800; }
.guide-button { min-height: 2.8rem; color: var(--ink); background: var(--mint); border: 0; border-radius: 999px; padding: .6rem 1rem; font-weight: 1000; }
main { max-width: 1120px; margin: 0 auto; padding: 0 clamp(1rem, 4vw, 3rem) 4rem; }
.screen { min-height: 62vh; }
.setup-screen { display: grid; grid-template-columns: minmax(0, .9fr) minmax(320px, 1.1fr); gap: clamp(2rem, 6vw, 6rem); align-items: start; padding: clamp(2rem, 8vh, 6rem) 0 4rem; }
.hero-copy { position: sticky; top: 2rem; }
.eyebrow, .step { margin: 0 0 .5rem; color: var(--mint); text-transform: uppercase; letter-spacing: .18em; font-size: .78rem; font-weight: 900; }
h1, h2, p { text-wrap: balance; }
h1 { margin: 0; font-size: clamp(3.4rem, 8vw, 7.8rem); line-height: .82; letter-spacing: -.075em; text-transform: uppercase; font-weight: 1000; }
h1 em { color: var(--yellow); font-style: normal; text-shadow: .06em .06em 0 var(--pink); }
.hero-copy > p:last-child { color: var(--muted); font-size: 1.2rem; max-width: 34ch; line-height: 1.6; }
.setup-card, .score-entry { padding: clamp(1.2rem, 4vw, 2.3rem); background: rgba(37, 18, 61, .96); border: 2px solid #52267d; border-radius: 1.5rem; box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; }
.section-heading h2, dialog h2 { margin: 0; font-size: clamp(1.5rem, 4vw, 2.2rem); }
.count { padding: .35rem .7rem; color: var(--yellow); background: #130a21; border-radius: 999px; font-weight: 900; }
.player-fields { display: grid; gap: .7rem; margin: 1.4rem 0 .9rem; }
.player-row { display: grid; grid-template-columns: 2.4rem 1fr auto; align-items: center; gap: .6rem; }
.player-row > span { display: grid; place-items: center; width: 2.2rem; aspect-ratio: 1; color: var(--ink); background: var(--mint); border-radius: 50%; font-weight: 1000; }
input, select { width: 100%; min-height: 3rem; color: var(--paper); background: #140a22; border: 2px solid #5e347f; border-radius: .7rem; padding: .75rem .9rem; }
.player-row button { color: var(--danger); background: transparent; border: 0; font-size: 1.7rem; }
.secondary-button, .primary-button, .danger-button { min-height: 3rem; border-radius: .75rem; padding: .75rem 1rem; font-weight: 1000; }
.secondary-button { color: var(--paper); background: transparent; border: 2px solid #71459a; }
.primary-button { color: #1b092a; background: var(--yellow); border: 0; box-shadow: 0 5px 0 #aa7112; text-transform: uppercase; letter-spacing: .04em; }
.danger-button { color: #19040b; background: var(--danger); border: 0; }
.setup-card > .primary-button { width: 100%; margin-top: 1.5rem; font-size: 1.05rem; }
.rule-heading { margin-top: 2.2rem; }
.muted, .hint { color: var(--muted); line-height: 1.5; }
.rules-editor { border-top: 1px solid #583076; border-bottom: 1px solid #583076; padding: .8rem 0; }
summary { font-weight: 900; padding: .5rem; }
.rule-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1rem .2rem; }
.rule-fields label { color: var(--muted); font-size: .82rem; font-weight: 800; }
.rule-fields select { margin-top: .35rem; font-size: .9rem; }
.error { min-height: 1.3em; margin: .55rem 0 0; color: #ff9bac; font-weight: 800; }

.game-screen { padding: clamp(2rem, 6vh, 5rem) 0 4rem; }
.game-banner { position: relative; overflow: hidden; padding: clamp(1.6rem, 5vw, 3rem); border-radius: 1.5rem; background: linear-gradient(125deg, #49147b, #8d1f8c); border: 2px solid #b34ec8; }
.game-banner::after { content: "⚄"; position: absolute; right: 3%; top: -35%; color: rgba(255,255,255,.08); font-size: 15rem; transform: rotate(14deg); }
.game-banner.final { background: linear-gradient(125deg, #8a2b13, #a60c62); border-color: var(--yellow); }
.game-banner.finished { background: linear-gradient(125deg, #086e58, #2d7d34); border-color: var(--mint); }
.game-banner h1 { position: relative; z-index: 1; font-size: clamp(3rem, 9vw, 7rem); }
.game-banner h1 span { display: block; color: var(--yellow); font-size: .32em; line-height: 1.2; letter-spacing: -.02em; }
.score-to-beat { position: relative; z-index: 1; font-size: clamp(1rem, 3vw, 1.35rem); font-weight: 800; }
.scoreboard { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .8rem; padding: 0; margin: 1.2rem 0; }
.scoreboard li { min-height: 5.5rem; display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: .7rem; padding: 1rem; border: 2px solid #4a2868; border-radius: 1rem; background: var(--panel); }
.scoreboard li.current { border-color: var(--pink); box-shadow: inset 5px 0 0 var(--pink); }
.scoreboard li.leader { border-color: var(--yellow); }
.scoreboard li.winner { border-color: var(--mint); background: #164938; }
.place { color: var(--muted); font-weight: 900; }
.player-name { overflow: hidden; text-overflow: ellipsis; font-size: 1.1rem; font-weight: 900; }
.player-name small { display: block; color: var(--yellow); font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; }
.scoreboard strong { color: var(--yellow); font-size: clamp(1.5rem, 4vw, 2.2rem); }
.score-entry { max-width: 700px; margin: 1.5rem auto 0; }
.score-entry > label { display: block; margin-bottom: .55rem; font-weight: 900; }
.score-controls { display: grid; grid-template-columns: 1fr auto; gap: .7rem; }
.score-controls input { min-height: 4rem; font-size: 1.8rem; font-weight: 900; }
.score-controls button { min-width: 9rem; }
.undo-button { margin-top: .6rem; }
.learn { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; border-top: 2px dashed #60367b; padding-top: 2rem; }
.learn details { background: rgba(37, 18, 61, .8); border: 1px solid #583076; border-radius: 1rem; padding: .5rem; }
.learn summary { font-size: 1.1rem; }
.details-body { padding: 0 .7rem .8rem; color: var(--muted); line-height: 1.6; }
.preset-name { color: var(--yellow); font-weight: 900; }
.rules-list dl { margin: 0; }
.rules-list dl > div { padding: .65rem 0; border-bottom: 1px solid #4c2a64; }
.rules-list dt { color: var(--paper); font-weight: 900; }
.rules-list dd { margin: .15rem 0 0; }
dialog { max-width: 500px; color: var(--paper); background: var(--panel); border: 2px solid var(--pink); border-radius: 1.2rem; padding: 2rem; box-shadow: 0 24px 70px #000; }
dialog::backdrop { background: rgba(8, 3, 14, .82); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; margin-top: 1.5rem; }
#table-guide-dialog { width: min(920px, calc(100% - 2rem)); max-width: 920px; max-height: calc(100% - 2rem); overflow: auto; }
.guide-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.guide-heading h2 { margin: 0; font-size: clamp(2rem, 5vw, 3.4rem); text-transform: uppercase; }
.guide-close { width: 2.8rem; min-width: 2.8rem; aspect-ratio: 1; color: var(--paper); background: transparent; border: 2px solid #71459a; border-radius: 50%; font-size: 1.7rem; line-height: 1; }
.guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.guide-grid section { padding: 1rem; background: var(--panel-light); border: 1px solid #583076; border-radius: 1rem; line-height: 1.55; }
.guide-grid h3 { margin: 0 0 .5rem; color: var(--yellow); font-size: 1.2rem; }
.guide-grid ol { margin: .5rem 0; padding-left: 1.4rem; }
.guide-grid li + li { margin-top: .4rem; }
.guide-rules { grid-row: span 2; }

@media (max-width: 760px) {
  .setup-screen { grid-template-columns: 1fr; padding-top: 2rem; }
  .hero-copy { position: static; }
  .hero-copy h1 { font-size: clamp(3rem, 15vw, 5.4rem); }
  .rule-fields, .learn, .guide-grid { grid-template-columns: 1fr; }
  .guide-rules { grid-row: auto; }
  .score-controls { grid-template-columns: 1fr; }
  .score-controls button { min-height: 3.8rem; }
  .scoreboard { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .current { animation: current-pulse 1.8s ease-in-out infinite alternate; }
  .primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #aa7112; }
  @keyframes current-pulse { from { box-shadow: inset 5px 0 0 var(--pink); } to { box-shadow: inset 9px 0 0 var(--pink), 0 0 24px rgba(255,62,165,.25); } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
