/* Kings Seat Ledger.
   Layout: summary scoreboard on top, then the season as month-grouped game rows
   with one cell per seat pair; tap a cell to edit it. Ported from the original
   prototype, with an added lock/unlock control for the shared edit password. */
:root {
  --bg: #f6f5f9;
  --surface: #ffffff;
  --surface-2: #efedf4;
  --line: #dedbe7;
  --fg: #1d1a26;
  --muted: #6b6679;
  --accent: #5a2d9c;
  --accent-soft: #ece4f8;
  --gain: #17804a;
  --gain-soft: #e1f3e8;
  --loss: #b4322b;
  --loss-soft: #f8e3e1;
  --listed: #9a6a00;
  --listed-soft: #fbf0d4;
  --attend: #2a5fae;
  --attend-soft: #e2ebf8;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15131b; --surface: #1e1b26; --surface-2: #272333; --line: #353044;
    --fg: #ece9f3; --muted: #a29cb2; --accent: #b591ee; --accent-soft: #33264a;
    --gain: #5cc98d; --gain-soft: #1d3527; --loss: #f07e74; --loss-soft: #3d2221;
    --listed: #e3b54a; --listed-soft: #3a3020; --attend: #85aef0; --attend-soft: #212d42;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15131b; --surface: #1e1b26; --surface-2: #272333; --line: #353044;
  --fg: #ece9f3; --muted: #a29cb2; --accent: #b591ee; --accent-soft: #33264a;
  --gain: #5cc98d; --gain-soft: #1d3527; --loss: #f07e74; --loss-soft: #3d2221;
  --listed: #e3b54a; --listed-soft: #3a3020; --attend: #85aef0; --attend-soft: #212d42;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.45;
}
.wrap { max-width: 1080px; margin: 0 auto; padding-inline: 16px; padding-block: 24px 64px; display: grid; gap: 28px; }
.num { font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; text-wrap: balance; letter-spacing: .01em; }
h1 { font-size: 2.4rem; line-height: 1; text-transform: uppercase; }
.eyebrow { font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: end; justify-content: space-between; }
header p { margin: 6px 0 0; color: var(--muted); max-width: 60ch; }
.lockbox { display: grid; gap: 6px; justify-items: end; }
.lockbox .ro-note { font-size: .82rem; color: var(--muted); }

/* Scoreboard */
.board { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { padding: 16px 18px; display: grid; gap: 4px; align-content: start; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .v { font-family: var(--display); font-weight: 700; font-size: 2.2rem; line-height: 1; font-variant-numeric: tabular-nums; }
.stat.hero .v { font-size: 3rem; }
.stat .s { color: var(--muted); font-size: .8rem; }
.pos { color: var(--gain); } .neg { color: var(--loss); }
.pairs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pairsum { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; min-width: 0; }
.pairsum .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pairsum .name { font-family: var(--display); font-weight: 700; font-size: 1.3rem; }
.bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--surface-2); }
.bar span { display: block; height: 100%; }
.pairsum .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: .78rem; }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); font: 600 .8rem var(--body); padding: 6px 11px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.seg button:focus-visible, .cell:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
label.chk { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: .85rem; cursor: pointer; }

/* Season grid */
.season { display: grid; gap: 22px; }
.month { display: grid; gap: 6px; }
.mhead { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px; gap: 12px; }
.mhead h2 { font-size: 1.35rem; text-transform: uppercase; }
.mhead .mt { font-size: .82rem; color: var(--muted); }
.cols, .game { display: grid; grid-template-columns: 34px 92px minmax(120px, 1fr) repeat(var(--pc, 3), minmax(0, 150px)) 84px; gap: 8px; align-items: center; }
.cols { padding: 0 12px; font-size: .7rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cols .r, .game .gpl { text-align: right; }
.game { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
.game.past { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.game .gn { color: var(--muted); font-size: .8rem; }
.game .gd { display: grid; line-height: 1.2; }
.game .gd b { font-weight: 600; }
.game .gd small { color: var(--muted); font-size: .76rem; }
.opp { display: flex; align-items: center; gap: 8px; min-width: 0; }
.opp .ab { font-family: var(--display); font-weight: 700; font-size: 1.15rem; min-width: 2.6em; }
.opp .full { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tier { font-size: .66rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tier.t-top { background: var(--accent-soft); color: var(--accent); }
.cell { display: grid; gap: 1px; text-align: left; border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px; padding: 5px 8px; cursor: pointer; font: inherit; min-width: 0; }
.cell:hover { border-color: var(--accent); }
.cell[aria-disabled="true"] { cursor: default; }
.cell[aria-disabled="true"]:hover { border-color: var(--line); }
.cell .st { font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.cell .amt { font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .pl { font-weight: 600; }
.cell .pn { display: none; font-size: .68rem; color: var(--muted); font-weight: 600; }
.cell.s-undecided { border-style: dashed; }
.cell.s-undecided .st { color: var(--muted); }
.cell.s-listed { background: var(--listed-soft); border-color: transparent; } .cell.s-listed .st { color: var(--listed); }
.cell.s-sold { background: var(--gain-soft); border-color: transparent; } .cell.s-sold .st { color: var(--gain); }
.cell.s-sold.loss { background: var(--loss-soft); } .cell.s-sold.loss .st { color: var(--loss); }
.cell.s-attending { background: var(--attend-soft); border-color: transparent; } .cell.s-attending .st { color: var(--attend); }
.cell.s-unused { background: var(--surface-2); border-color: transparent; } .cell.s-unused .st { color: var(--muted); }
.gpl { font-weight: 600; font-size: .9rem; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .board { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .cols { display: none; }
  .game { grid-template-columns: 30px 1fr auto; grid-template-areas: "n d pl" "n o o" "c c c"; row-gap: 6px; }
  .game .gn { grid-area: n; align-self: start; padding-top: 2px; }
  .game .gd { grid-area: d; grid-template-columns: auto auto; justify-content: start; gap: 8px; align-items: baseline; }
  .game .opp { grid-area: o; }
  .game .gpl { grid-area: pl; }
  .game .cells { grid-area: c; display: grid; grid-template-columns: repeat(var(--pc, 3), minmax(0, 1fr)); gap: 6px; }
  .cell .pn { display: block; }
  header { gap: 12px; }
  .lockbox { justify-items: start; }
}
@media (min-width: 861px) { .game .cells { display: contents; } }
@media (max-width: 560px) {
  .pairs { grid-template-columns: 1fr; }
  .stat .v { font-size: 1.8rem; } .stat.hero .v { font-size: 2.3rem; }
  h1 { font-size: 2rem; }
}

/* Editor */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--fg); padding: 0; width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
dialog::backdrop { background: rgb(10 6 20 / .45); }
.dlg { display: grid; gap: 16px; padding: 20px; }
.dlg h3 { font-size: 1.6rem; line-height: 1.05; }
.dlg .sub { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.field { display: grid; gap: 5px; }
.field > span { font-size: .75rem; font-weight: 600; color: var(--muted); letter-spacing: .03em; }
.field input, .field select, .field textarea { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.field textarea { min-height: 56px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.statusPick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.statusPick button { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 8px; padding: 8px 2px; font: 600 .74rem var(--body); cursor: pointer; }
.statusPick button[aria-pressed="true"] { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.preview { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; display: flex; justify-content: space-between; gap: 12px; font-size: .88rem; }
.preview b { font-variant-numeric: tabular-nums; }
.actions { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px; padding: 9px 16px; font: 600 .88rem var(--body); cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--surface); border-color: var(--accent); }
.btn.small { padding: 6px 12px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
details.gameedit summary { cursor: pointer; color: var(--muted); font-size: .82rem; }
details.gameedit .row2 { margin-top: 10px; }
.err { color: var(--loss); font-size: .82rem; min-height: 1em; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-weight: 600; font-size: .85rem; }
@media (prefers-reduced-motion: no-preference) { .cell, .seg button { transition: border-color .15s, background .15s; } }
