:root {
  --canvas: #000;
  --surface: #05080c;
  --surface-2: #09121b;
  --surface-3: #0d1d2b;
  --line: #142637;
  --line-strong: #1e4c6c;
  --text: #eef8ff;
  --muted: #91adbf;
  --faint: #587589;
  --tile: #25a9ff;
  --tile-dark: #0874c5;
  --green: #65d29a;
  --red: #ff6f79;
  --focus: #8dd7ff;
  --radius: 7px;
  --font: "Sarabun", system-ui, sans-serif;
  --display: "Bebas Neue", Impact, sans-serif;
  --mono: "IBM Plex Mono", monospace;
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--text); font-family: var(--font); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 5px; background: #121611; color: var(--text); padding: 10px 11px; outline: none; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { border-color: var(--tile); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tile) 20%, transparent); outline: none; }
input:disabled { opacity: .45; cursor: not-allowed; }
code, .mono { font-family: var(--mono); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.topbar { min-height: 78px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 16px clamp(18px, 3vw, 44px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--canvas) 94%, transparent); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; }
.brand > span:last-child { display: grid; gap: 2px; }
.brand strong { font-family: var(--display); color: var(--tile); letter-spacing: .09em; font-size: 24px; line-height: 1; }
.brand > span > small { color: var(--faint); font: 9px var(--mono); letter-spacing: .16em; }
.tiles { display: flex; gap: 3px; }
.tiles b { position: relative; width: 30px; height: 30px; display: grid; place-items: center; color: #00101d; background: var(--tile); border-radius: 3px; box-shadow: 0 3px 0 var(--tile-dark); font: 19px var(--display); }
.tiles small { position: absolute; right: 3px; bottom: 2px; font: 6px var(--mono); }
.top-actions { display: flex; gap: 8px; }
.button { min-height: 42px; border: 1px solid var(--line); border-radius: 5px; padding: 9px 15px; background: var(--surface-2); cursor: pointer; font-weight: 600; transition: background .15s, border-color .15s, transform .15s; }
.button:hover { background: var(--surface-3); border-color: var(--line-strong); }
.button:active { transform: translateY(1px); }
.button.primary { border-color: var(--tile-dark); background: var(--tile); color: #00101d; }
.button.primary:hover { background: #65c6ff; border-color: var(--tile); }
.button.quiet { background: transparent; }
.button.danger { color: var(--red); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; max-width: 1680px; margin: 0 auto; }
.board { min-width: 0; padding: clamp(34px, 4vw, 58px) clamp(18px, 4vw, 64px) 80px; border-right: 1px solid var(--line); }
.summary { padding: 42px 28px; }
.summary-sticky { position: sticky; top: 120px; }
.eyebrow { margin: 0 0 10px; color: var(--tile); font: 600 10px var(--mono); letter-spacing: .2em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: var(--display); font-size: clamp(48px, 6vw, 88px); line-height: .88; letter-spacing: .015em; font-weight: 400; }
h1 span { color: var(--muted); }
h2 { margin-bottom: 0; font-size: 22px; }
.step { color: var(--tile); font: 600 11px var(--mono); }

.importer { border: 1px solid var(--line-strong); border-left: 3px solid var(--tile); padding: 18px; display: grid; grid-template-columns: minmax(250px, .8fr) minmax(360px, 1.2fr); gap: 22px; background: var(--surface); }
.import-copy { display: flex; gap: 16px; }
.import-copy h2 { font-size: 17px; margin-bottom: 5px; }
.import-copy p { margin: 0; color: var(--muted); font-size: 13px; }
.import-copy code { color: var(--text); font-size: 11px; }
.import-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.notice { grid-column: 1 / -1; border: 1px solid var(--line); padding: 10px 12px; color: var(--muted); background: #121611; font-size: 13px; }
.notice.success { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.notice.error { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }

.identity-strip { display: grid; grid-template-columns: 1.3fr 1fr 100px; gap: 1px; margin: 24px 0 44px; background: var(--line); border: 1px solid var(--line); }
.identity-strip label { background: var(--surface); padding: 11px 13px; color: var(--faint); font: 10px var(--mono); letter-spacing: .08em; }
.identity-strip input { border: 0; background: transparent; padding: 5px 0 0; color: var(--text); font-family: var(--font); box-shadow: none; }
.identity-strip input:focus { box-shadow: none; }
.section-heading, .section-heading > div { display: flex; align-items: center; gap: 12px; }
.section-heading { justify-content: space-between; margin-bottom: 14px; }
.game-columns { display: grid; grid-template-columns: 100px minmax(250px, 1.1fr) 170px minmax(220px, 1fr) 90px; gap: 14px; padding: 0 14px 8px; color: var(--faint); font: 9px var(--mono); letter-spacing: .1em; text-transform: uppercase; }
.games-list { display: grid; gap: 7px; }
.game-row { display: grid; grid-template-columns: 100px minmax(250px, 1.1fr) 170px minmax(220px, 1fr) 90px; gap: 14px; padding: 14px; align-items: center; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); background: var(--surface); }
.game-row.win { border-left-color: var(--green); }
.game-row.loss { border-left-color: var(--red); }
.game-row.bye { border-left-color: var(--tile); }
.game-row.pending { border-left-color: var(--tile); }
.game-index { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 5px; }
.game-number { color: var(--faint); font: 20px var(--display); }
.result-badge { justify-self: end; min-width: 34px; padding: 3px 7px; text-align: center; border: 1px solid currentColor; border-radius: 3px; font: 16px var(--display); }
.win .result-badge { color: var(--green); }
.loss .result-badge { color: var(--red); }
.bye .result-badge { color: var(--tile); }
.pending .result-badge { color: var(--tile); }
.bye-check { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; color: var(--muted); font: 10px var(--mono); cursor: pointer; }
.bye-check input { width: 16px; height: 16px; accent-color: var(--tile); }
.opponent-fields label, .score-fields label { display: grid; gap: 4px; }
.opponent-fields span, .score-fields span { color: var(--faint); font: 9px var(--mono); }
.opponent-fields > div { display: grid; grid-template-columns: minmax(130px, 1fr) 90px; gap: 7px; margin-top: 7px; }
.score-fields { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 6px; }
.score-fields input { text-align: center; font: 600 16px var(--mono); padding-inline: 5px; }
.score-fields b { padding-bottom: 10px; color: var(--faint); }
.score-diff { grid-column: 1 / -1; justify-self: center; color: var(--muted); font: 10px var(--mono); }
.game-details { min-width: 0; display: grid; gap: 8px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; min-height: 20px; }
.chip { border: 1px solid var(--line-strong); background: var(--surface-2); padding: 3px 6px; font: 9px var(--mono); }
.chip button { border: 0; padding: 0 0 0 5px; background: none; color: var(--red); cursor: pointer; }
.detail-actions { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.detail-actions label { color: var(--faint); font: 9px var(--mono); white-space: nowrap; }
.detail-actions input { width: 60px; padding: 5px; color: var(--red); }
.text-button { padding: 0; border: 0; background: none; color: var(--tile); font-size: 12px; cursor: pointer; }
.phony-inline { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 7px; color: var(--faint); font: 9px var(--mono); }
.phony-inline input { padding: 5px 7px; font: 11px var(--mono); }
.money-cell { text-align: right; }
.money-cell strong { display: block; color: var(--green); font: 600 16px var(--mono); }
.money-cell > span { color: var(--faint); font-size: 10px; }
.remove-game { display: block; margin: 7px 0 0 auto; padding: 0; border: 0; color: var(--faint); background: none; font-size: 10px; cursor: pointer; }
.remove-game:hover { color: var(--red); }
.empty-state { padding: 56px 20px; border: 1px dashed var(--line); text-align: center; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-state h3 { margin: 14px 0 5px; color: var(--text); }
.empty-state p { margin: 0; }
.empty-tile { display: inline-grid; place-items: center; width: 48px; height: 48px; border: 1px solid var(--tile-dark); color: var(--tile); font: 28px var(--display); }

.summary h2 { font-family: var(--display); font-size: 36px; font-weight: 400; letter-spacing: .05em; }
.record { margin: 22px 0; padding: 16px 0; display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; border-block: 1px solid var(--line); }
.record > div { text-align: center; }
.record strong { display: block; font: 44px var(--display); line-height: 1; }
.record span { color: var(--faint); font: 9px var(--mono); letter-spacing: .15em; }
.record > div:first-child strong { color: var(--green); }
.record > div:nth-child(3) strong { color: var(--red); }
.record i { color: var(--line-strong); }
.record .bye-record { grid-column: 1 / -1; display: flex; justify-content: center; gap: 8px; align-items: baseline; }
.record .bye-record strong { color: var(--tile); font-size: 22px; }
.breakdown { display: grid; gap: 0; margin: 0; }
.breakdown div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.breakdown dt { color: var(--muted); font-size: 12px; }
.breakdown dd { margin: 0; font: 11px var(--mono); }
.breakdown .negative dd { color: var(--red); }
.breakdown .positive dd { color: var(--green); }
.grand-total { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 22px 0 16px; }
.grand-total span { color: var(--muted); }
.grand-total strong { color: var(--green); font: 600 23px var(--mono); }
.export { width: 100%; }
.rates-toggle { width: 100%; display: flex; justify-content: space-between; border: 0; border-bottom: 1px solid var(--line); padding: 16px 0 8px; background: none; cursor: pointer; font-size: 12px; }
.rates-toggle span { color: var(--faint); }
.rates { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding-top: 10px; }
.rates[hidden] { display: none; }
.rates label { color: var(--faint); font-size: 9px; }
.rates input { margin-top: 3px; padding: 6px; font: 11px var(--mono); }

dialog { width: min(560px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--text); background: var(--surface); box-shadow: 0 24px 90px #000a; }
dialog::backdrop { background: #070907c9; backdrop-filter: blur(5px); }
.dialog-card { padding: clamp(20px, 4vw, 30px); }
.dialog-card > p { color: var(--muted); line-height: 1.65; }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.dialog-head h2 { font-size: 26px; }
.icon-button { align-self: start; width: 38px; height: 38px; border: 1px solid var(--line); background: transparent; font-size: 25px; cursor: pointer; }
.field { display: grid; gap: 7px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.export-text { min-height: 350px; resize: vertical; font: 12px/1.65 var(--mono); }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .board { border-right: 0; }
  .summary { border-top: 1px solid var(--line); padding: 32px clamp(18px, 4vw, 64px) 60px; }
  .summary-sticky { position: static; max-width: 680px; margin: 0 auto; }
  .game-columns { display: none; }
  .game-row { grid-template-columns: 78px minmax(220px, 1fr) 160px minmax(210px, 1fr) 75px; }
}

@media (max-width: 820px) {
  .topbar { align-items: flex-start; }
  .brand > span:last-child { display: none; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .top-actions .button { min-height: 38px; padding: 7px 10px; font-size: 12px; }
  .importer { grid-template-columns: 1fr; }
  .game-row { grid-template-columns: 72px 1fr 145px; }
  .game-details { grid-column: 2 / 4; }
  .money-cell { grid-column: 3; grid-row: 1; align-self: start; margin-top: 54px; }
}

@media (max-width: 560px) {
  .topbar { min-height: 68px; padding: 13px 14px; }
  .tiles b { width: 25px; height: 25px; font-size: 16px; }
  .top-actions .danger { display: none; }
  .board { padding-inline: 14px; }
  h1 { font-size: 48px; }
  .importer { padding: 14px; }
  .import-form { grid-template-columns: 1fr; }
  .identity-strip { grid-template-columns: 1fr 80px; }
  .identity-strip label:first-child { grid-column: 1 / -1; }
  .section-heading { align-items: flex-end; }
  .game-row { grid-template-columns: 58px 1fr; gap: 10px; padding: 12px; }
  .opponent-fields, .score-fields, .game-details, .money-cell { grid-column: 2; }
  .score-fields { width: 180px; }
  .money-cell { grid-row: auto; margin-top: 0; display: flex; justify-content: flex-end; align-items: baseline; gap: 5px; }
  .remove-game { margin-left: 8px; }
  .record strong { font-size: 36px; }
  .form-grid { grid-template-columns: 1fr; }
}

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