/* =============================================================
   Cricket Scorer - night-match scoreboard
   Palette: pitch green ground, bone chrome, ball red, sightscreen amber
   ============================================================= */

:root {
  --ground:   #F4F2EA;
  --surface:  #FFFFFF;
  --raised:   #FBFAF5;
  --line:     #DCD8C9;
  --line-soft:#EAE7DB;
  --ink:      #17211C;
  --muted:    #5D6A61;
  --faint:    #8B968C;
  --ball:     #C63F22;
  --ball-ink: #FFFFFF;
  --amber:    #C98A12;
  --amber-bg: #FBEFD2;
  --turf:     #2F6B46;
  --turf-bg:  #E2EFE6;
  --dot:      #97A79B;
  --shadow:   0 1px 2px rgba(23,33,28,.08), 0 8px 24px -16px rgba(23,33,28,.35);

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --pad-h: 52px;
  --f-display: "Oswald", "Haettenschweiler", "Arial Narrow", sans-serif;
  --f-body: "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --f-data: "Barlow Semi Condensed", "Barlow", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground:   #0F1613;
    --surface:  #18211D;
    --raised:   #1E2823;
    --line:     #2A3832;
    --line-soft:#222E29;
    --ink:      #E9EFE9;
    --muted:    #93A69A;
    --faint:    #6C7E73;
    --ball:     #E05A38;
    --ball-ink: #150806;
    --amber:    #E9B949;
    --amber-bg: #33291155;
    --turf:     #6FC28C;
    --turf-bg:  #172C21;
    --dot:      #5C6E63;
    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 10px 28px -18px rgba(0,0,0,.9);
  }
}

:root[data-theme="dark"] {
  --ground:   #0F1613;
  --surface:  #18211D;
  --raised:   #1E2823;
  --line:     #2A3832;
  --line-soft:#222E29;
  --ink:      #E9EFE9;
  --muted:    #93A69A;
  --faint:    #6C7E73;
  --ball:     #E05A38;
  --ball-ink: #150806;
  --amber:    #E9B949;
  --amber-bg: #33291155;
  --turf:     #6FC28C;
  --turf-bg:  #172C21;
  --dot:      #5C6E63;
  --shadow:   0 1px 2px rgba(0,0,0,.4), 0 10px 28px -18px rgba(0,0,0,.9);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: none;
}

body {
  background: var(--ground);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; border-radius: 4px; }

/* ---------------- shell ---------------- */
#app {
  max-width: 780px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  overflow: hidden;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------------- top bar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: .03em;
  text-transform: uppercase;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .sub {
  font-family: var(--f-data);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.iconbtn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--muted);
  font-size: 18px;
  border: 1px solid transparent;
}
.iconbtn:hover { background: var(--raised); border-color: var(--line-soft); color: var(--ink); }

/* ---------------- scoreboard billboard ---------------- */
.board {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.board-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.board-team {
  font-family: var(--f-data);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
  min-width: 90px;
}
.board-score {
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 42px;
  line-height: .95;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 2px;
}
.board-score .wk { color: var(--ball); }
.board-overs {
  font-family: var(--f-data);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.board-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-family: var(--f-data);
  font-size: 13px;
  color: var(--muted);
}
.board-meta b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.board-chase {
  font-family: var(--f-data);
  font-size: 14px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  background: var(--turf-bg);
  color: var(--ink);
  border-left: 3px solid var(--turf);
}
.board-chase b { font-weight: 600; font-variant-numeric: tabular-nums; }

.freehit {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--f-data);
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--ball-ink);
  background: var(--ball);
  padding: 6px 10px;
  border-radius: var(--r-sm);
}

/* ---------------- cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
}
.card > h3 {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--f-data);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card > h3 .spacer { flex: 1; }

/* ---------------- live batter / bowler rows ---------------- */
.crease { display: flex; flex-direction: column; }
.crease-row {
  display: grid;
  grid-template-columns: 1fr 42px 34px 30px 30px 52px;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  font-family: var(--f-data);
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--line-soft);
}
.crease-row:last-child { border-bottom: none; }
.crease-row.head {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  padding-top: 8px; padding-bottom: 6px;
}
.crease-row .nm {
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.crease-row .n { text-align: right; color: var(--muted); }
.crease-row .r { text-align: right; font-weight: 600; font-size: 16px; }
.crease-row.on .nm { color: var(--ink); }
.crease-row.on .r { color: var(--ink); }
.strike-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber);
  flex: none;
}
.tapname { text-decoration: underline dotted var(--faint); text-underline-offset: 3px; }

/* ---------------- over strip ---------------- */
.overstrip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.overstrip::-webkit-scrollbar { display: none; }
.bead {
  flex: none;
  min-width: 32px; height: 32px;
  padding: 0 6px;
  border-radius: 999px;
  display: grid; place-items: center;
  font-family: var(--f-data);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--ink);
}
.bead.dot { color: var(--dot); }
.bead.bnd { border-color: var(--amber); color: var(--amber); background: var(--amber-bg); }
.bead.wkt { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); }
.bead.ext { border-style: dashed; color: var(--muted); }
.bead.ghost { background: transparent; border-style: dashed; border-color: var(--line-soft); color: transparent; }
.overstrip .sep { flex: none; color: var(--faint); font-size: 12px; font-family: var(--f-data); padding: 0 2px; }

/* ---------------- scoring pad ---------------- */
.pad {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 8px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.pad-hint {
  font-family: var(--f-data);
  font-size: 13px;
  color: var(--muted);
  min-height: 16px;
  display: flex; align-items: center; gap: 8px;
}
.pad-hint b { color: var(--ball); font-weight: 600; }
.pad-grid { display: grid; gap: 7px; }
.g6 { grid-template-columns: repeat(6, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }

.key {
  height: var(--pad-h);
  border-radius: var(--r-md);
  background: var(--raised);
  border: 1px solid var(--line);
  font-family: var(--f-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: .02em;
  color: var(--ink);
  display: grid; place-items: center;
  transition: transform .06s ease, background .12s ease;
  user-select: none;
}
.key:active { transform: scale(.96); }
.key.sm { font-family: var(--f-data); font-size: 14px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; height: 42px; }
.key.bnd { color: var(--amber); border-color: var(--amber); }
.key.armed { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); }
.key.wicket { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); font-family: var(--f-display); font-size: 17px; letter-spacing: .12em; text-transform: uppercase; }
.key.ghost { background: transparent; color: var(--muted); }
.key[disabled] { opacity: .35; pointer-events: none; }

/* ---------------- inline picker (openers, new batter, new bowler) ---------------- */
.picker {
  background: var(--surface);
  border-top: 2px solid var(--ball);
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  display: flex; flex-direction: column; gap: 10px;
}
.picker h4 {
  margin: 0;
  font-family: var(--f-data);
  font-size: 12px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
.picklist { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.pick {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  background: var(--raised);
  border: 1px solid var(--line);
  text-align: left;
  width: 100%;
}
.pick .pname { flex: 1; font-weight: 500; }
.pick .pstat { font-family: var(--f-data); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pick[disabled] { opacity: .4; }
.pick .why { font-family: var(--f-data); font-size: 12px; color: var(--ball); }

/* ---------------- generic controls ---------------- */
.btn {
  padding: 12px 16px;
  border-radius: var(--r-md);
  background: var(--raised);
  border: 1px solid var(--line);
  font-family: var(--f-data);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .04em;
  text-transform: uppercase;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); }
.btn.block { width: 100%; }
.btn.slim { padding: 9px 12px; font-size: 13px; }
.btn[disabled] { opacity: .4; pointer-events: none; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label {
  font-family: var(--f-data);
  font-size: 11px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
input[type="text"], input[type="number"], select {
  padding: 11px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--ground);
  color: var(--ink);
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.switch:last-child { border-bottom: none; }
.switch .lab { font-size: 14px; }
.switch .lab small { display: block; color: var(--muted); font-size: 12px; font-family: var(--f-data); }
.toggle {
  width: 46px; height: 27px; border-radius: 999px;
  background: var(--line); border: none; position: relative; flex: none;
  transition: background .15s ease;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--surface); transition: transform .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.toggle[aria-checked="true"] { background: var(--turf); }
.toggle[aria-checked="true"]::after { transform: translateX(19px); }

/* ---------------- squad editor ---------------- */
.squad { display: flex; flex-direction: column; }
.squad-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.squad-row:last-child { border-bottom: none; }
.squad-row .no {
  font-family: var(--f-data); font-size: 12px; color: var(--faint);
  width: 20px; text-align: right; font-variant-numeric: tabular-nums;
}
.squad-row .pn { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.squad-row .tag {
  font-family: var(--f-data); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px;
  background: var(--turf-bg); color: var(--turf);
}
.squad-add { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line-soft); }
.squad-add input { flex: 1; }

/* ---------------- scorecard tables ---------------- */
.tablewrap { overflow-x: auto; }
table.sc {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--f-data);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
table.sc th {
  font-size: 11px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint);
  text-align: right;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.sc th:first-child { text-align: left; }
table.sc td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line-soft);
  text-align: right;
  white-space: nowrap;
}
table.sc td:first-child { text-align: left; white-space: normal; }
table.sc tr:last-child td { border-bottom: none; }
table.sc .pn { font-weight: 600; font-family: var(--f-body); font-size: 14px; }
table.sc .how { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
table.sc .notout { color: var(--turf); }
table.sc td.big { font-weight: 600; font-size: 15px; }
.totalrow td { border-top: 1px solid var(--line); font-weight: 600; font-size: 15px; }

.kv {
  padding: 10px 12px;
  font-family: var(--f-data);
  font-size: 13.5px;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
  line-height: 1.6;
}
.kv b { color: var(--ink); font-weight: 600; }

/* ---------------- manhattan + worm ---------------- */
.manhattan {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding: 12px 12px 0;
  overflow-x: auto;
}
.mbar { flex: none; width: 16px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; }
.mbar .fill { background: var(--turf); border-radius: 3px 3px 0 0; min-height: 2px; }
.mbar .fill.w { background: var(--ball); }
.mbar .lab { font-family: var(--f-data); font-size: 10px; color: var(--faint); text-align: center; }
.maxis { display: flex; gap: 3px; padding: 4px 12px 12px; overflow-x: auto; }
.maxis span { flex: none; width: 16px; text-align: center; font-family: var(--f-data); font-size: 10px; color: var(--faint); }

/* ---------------- over log ---------------- */
.overlog { display: flex; flex-direction: column; }
.overlog-row { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); display: flex; gap: 10px; align-items: center; }
.overlog-row:last-child { border-bottom: none; }
.overlog-row .ono { font-family: var(--f-display); font-size: 17px; width: 30px; color: var(--muted); }
.overlog-row .beads { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.overlog-row .sum { font-family: var(--f-data); font-size: 13px; color: var(--muted); text-align: right; }
.overlog-row .sum b { color: var(--ink); font-weight: 600; }

/* ---------------- match list ---------------- */
.matchrow {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
  width: 100%;
  text-align: left;
}
.matchrow:last-child { border-bottom: none; }
.matchrow .mt { flex: 1; min-width: 0; }
.matchrow .mt .tt { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.matchrow .mt .ms { font-family: var(--f-data); font-size: 13px; color: var(--muted); }
.pill {
  font-family: var(--f-data); font-size: 11px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
  background: var(--raised); border: 1px solid var(--line); color: var(--muted);
}
.pill.live { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); }
.pill.done { background: var(--turf-bg); border-color: transparent; color: var(--turf); }

/* ---------------- tabs ---------------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  padding: 8px 4px 10px;
  font-family: var(--f-data);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--faint);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border-top: 2px solid transparent;
  margin-top: -1px;
}
.tab .ic { font-size: 17px; line-height: 1; }
.tab.on { color: var(--ink); border-top-color: var(--ball); }

/* ---------------- modal ---------------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(10, 16, 13, .6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 40;
  padding: 0;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 780px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--line);
  padding: 14px 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.sheet h2 {
  margin: 0;
  font-family: var(--f-display);
  font-weight: 500; font-size: 20px;
  letter-spacing: .04em; text-transform: uppercase;
}
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 9px 13px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  font-family: var(--f-data);
  font-size: 14px; font-weight: 500;
}
.chip.on { background: var(--ball); border-color: var(--ball); color: var(--ball-ink); }
.chip[disabled] { opacity: .3; pointer-events: none; }

/* ---------------- misc ---------------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--ground);
  padding: 10px 16px;
  border-radius: 999px;
  font-family: var(--f-data);
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow);
}
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  font-family: var(--f-data);
}
.empty .big { font-family: var(--f-display); font-size: 22px; color: var(--ink); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
.note { font-family: var(--f-data); font-size: 13px; color: var(--muted); }
.banner {
  background: var(--turf-bg);
  border: 1px solid var(--turf);
  border-radius: var(--r-md);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.banner h4 { margin: 0; font-family: var(--f-display); font-size: 18px; letter-spacing: .03em; text-transform: uppercase; }
.banner p { margin: 0; font-family: var(--f-data); font-size: 14px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (min-width: 720px) {
  :root { --pad-h: 58px; }
  #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
