:root {
  --bg: #14110f;
  --panel: #1f1a17;
  --panel-2: #2a231f;
  --line: #3a302a;
  --ink: #f1e9e1;
  --muted: #a8998c;
  --accent: #e0a96d;
  --good: #8fbf7f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 20px 16px 72px; }

/* ----------------------------------------------------------------- header */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar .back {
  color: var(--muted);
  text-decoration: none;
  font-size: 22px;
  line-height: 1;
  padding: 8px;
  margin: -8px;
}
.topbar .back:hover { color: var(--accent); }
.topbar h1 {
  font-size: clamp(20px, 5vw, 28px);
  margin: 0;
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.iconbtn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  cursor: pointer;
}
.iconbtn:hover { border-color: var(--accent); }

.lede { color: var(--muted); margin: 0 0 22px; }

/* ------------------------------------------------------------------ picker */

.search {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  margin-bottom: 18px;
}
.search:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

h2.section {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 26px 0 10px;
  font-weight: 600;
}

.sheet-list { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .sheet-list { grid-template-columns: 1fr 1fr; } }

.sheet-card {
  display: block;
  text-align: left;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}
.sheet-card:hover { border-color: var(--accent); background: var(--panel-2); }
.sheet-card .name { font-weight: 600; }
.sheet-card .blurb { color: var(--muted); font-size: 14px; margin-top: 2px; }

.resume {
  border-color: var(--accent);
}
.resume .when { color: var(--accent); font-size: 13px; margin-top: 4px; }

.empty { color: var(--muted); padding: 24px 0; }

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

.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }

table.pad {
  border-collapse: collapse;
  width: 100%;
  min-width: max-content;
}
table.pad th, table.pad td {
  border: 1px solid var(--line);
  padding: 0;
  text-align: center;
}
table.pad thead th {
  background: var(--panel-2);
  padding: 10px 8px;
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 2;
}
table.pad th.rowhead {
  background: var(--panel);
  text-align: left;
  padding: 8px 10px;
  font-weight: 500;
  font-size: 14px;
  min-width: 132px;
  position: sticky;
  left: 0;
  z-index: 1;
}
table.pad th.rowhead .hint { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

.cell {
  width: 100%;
  min-width: 68px;
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  text-align: center;
  padding: 12px 6px;
  -moz-appearance: textfield;
}
.cell::-webkit-outer-spin-button, .cell::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell:focus { outline: 0; background: var(--panel-2); box-shadow: inset 0 0 0 2px var(--accent); }

.tick { width: 100%; min-height: 44px; background: transparent; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; }
.tick[aria-pressed="true"] { color: var(--good); }

.playerhead { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.playername {
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: center;
  width: 88px;
  padding: 2px;
}
.playername:focus { outline: 1px solid var(--accent); border-radius: 6px; }

/* The sub-header naming each field, on a sheet where one round takes more than
   one number. Kept quiet: the player names above it are the real heading. */
table.pad thead th.fieldhead {
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 6px;
  top: 44px;
}
table.pad thead th.fieldhead + th.fieldhead { border-left: 1px solid var(--line); }
table.pad tr td .cell { min-width: 56px; }

tr.subtotal td, tr.subtotal th { background: var(--panel); color: var(--muted); font-size: 14px; }
tr.subtotal td { padding: 8px 6px; }

tr.total th, tr.total td {
  background: var(--panel-2);
  font-weight: 700;
  font-size: 18px;
  padding: 12px 6px;
}
tr.total td.leading { color: var(--accent); }

.sectionrow th {
  background: var(--bg);
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px;
}

/* ------------------------------------------------------------------ action */

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0; }
button.btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  min-height: 44px;
  cursor: pointer;
}
button.btn:hover { border-color: var(--accent); }
button.btn.primary { background: var(--accent); color: #241a10; border-color: var(--accent); font-weight: 600; }

.notes { color: var(--muted); font-size: 14px; margin-top: 22px; }
.notes li { margin-bottom: 4px; }

.standings { margin-top: 20px; }
.standings ol { margin: 8px 0 0; padding-left: 22px; }
.standings li { margin-bottom: 4px; }
.standings .win { color: var(--accent); font-weight: 600; }

dialog.sheetdlg {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  max-width: 420px;
  width: calc(100% - 32px);
}
dialog.sheetdlg::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.sheetdlg h3 { margin: 0 0 12px; }
dialog.sheetdlg label { display: block; margin: 10px 0 4px; font-size: 14px; color: var(--muted); }
dialog.sheetdlg input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
}

/* -------------------------------------------------------------------- menu */

.menu {
  position: absolute;
  right: 16px;
  top: 64px;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 200px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.menu button {
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  min-height: 44px;
  cursor: pointer;
}
.menu button:hover { background: var(--panel-2); color: var(--accent); }

.muted { color: var(--muted); }
.right { text-align: right; }
