/* Yardzee - phone / player view.
   Light is the default on purpose: dark mode is unreadable outdoors in sun. */

:root {
  --bg: #f2f4ef;
  --surface: #ffffff;
  --surface-2: #e9ece3;
  --ink: #12180f;
  --ink-soft: #5b6355;
  --line: #c9cfc0;
  --accent: #2f7d32;
  --accent-ink: #ffffff;
  --accent-soft: #dff0d8;
  --warn: #a8560c;
  --warn-soft: #fdeedd;
  --danger: #b02020;
  --good: #1d6f2b;
  --zero: #9aa294;
  --shadow: 0 6px 24px rgba(10, 20, 8, 0.14);
  --radius: 14px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1411;
  --surface: #17201b;
  --surface-2: #1f2a23;
  --ink: #eef3ea;
  --ink-soft: #9aa894;
  --line: #33413a;
  --accent: #5fbf62;
  --accent-ink: #06170a;
  --accent-soft: #1d3020;
  --warn: #e0a45c;
  --warn-soft: #2d2416;
  --danger: #ef6b6b;
  --good: #6fd077;
  --zero: #616d5e;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

button, input { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.15; }
h2 { font-size: 1.15rem; letter-spacing: -0.01em; }
p { margin: 0 0 10px; line-height: 1.4; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.spacer { flex: 1; }

/* --------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar > * + * { margin-left: 8px; }
.brand { display: flex; align-items: center; font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em; }
.brand-dice { font-size: 1.5rem; margin-right: 6px; color: var(--accent); }
.code-chip {
  font-weight: 800;
  letter-spacing: 0.18em;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 6px 10px 6px 14px;
  border-radius: 999px;
  font-size: 1rem;
}
.round-chip {
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: var(--surface-2);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.offline-dot { color: var(--warn); font-size: 0.8rem; }
.icon-btn {
  min-width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:disabled { opacity: 0.35; }

/* ----------------------------------------------------------------- home */
.home-main { padding: 14px 12px 40px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.panel-quiet { background: transparent; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.row-between + .row-between { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.row-between p { margin: 0; }

.roster { display: flex; flex-wrap: wrap; margin: 0 -4px 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  margin: 4px;
  padding: 12px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.chip.is-on { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.chip-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.75rem; margin-right: 8px;
}
.chip-x { margin-left: 10px; color: var(--ink-soft); font-size: 1.1rem; padding: 0 4px; }

.add-row, .join-row { display: flex; margin-bottom: 12px; }
.add-row input, .join-row input {
  flex: 1;
  min-width: 0; /* let the input shrink instead of pushing the button off-card */
  min-height: 52px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}
.add-row > * + *, .join-row > * + * { margin-left: 8px; }
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.25em;
  text-indent: 0.25em; /* centres the tracked-out text */
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
}

.btn {
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0 18px;
  min-height: 52px;
  font-weight: 700;
  cursor: pointer;
  background: var(--surface-2);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); border-color: var(--line); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-xl { min-height: 62px; font-size: 1.15rem; width: 100%; }
.btn-wide { width: 100%; }
.btn-tiny { min-height: 34px; padding: 0 10px; font-size: 0.8rem; border-color: var(--line); }
.btn:disabled { opacity: 0.45; }

/* ------------------------------------------------------------ turn bar */
.turnbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
}
.turnbar.is-done { background: var(--surface-2); justify-content: center; }
.turn-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-soft); }
.turn-name {
  flex: 1;
  text-align: left;
  margin-left: 10px;
  background: none;
  border: none;
  font-size: 1.25rem;
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 4px;
}

/* ------------------------------------------------------------ scorecard */
.game-main { flex: 1; padding: 0 0 30px; }
.grid-wrap { overflow: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.card-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.card-table th, .card-table td { border-bottom: 1px solid var(--line); }
.card-table .cat {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 8px;
  min-width: 108px;
  border-right: 1px solid var(--line);
}
.section-row .cat {
  background: var(--surface-2);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  padding: 5px 8px;
}
.player-th {
  background: var(--surface);
  padding: 6px 4px;
  min-width: 64px;
  border-right: 1px solid var(--line);
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 3;
}
.player-th.is-current { background: var(--accent-soft); }
.player-th.is-focused { box-shadow: inset 0 -4px 0 var(--accent); }
.corner { z-index: 4; top: 0; }
.player-name { display: block; font-size: 0.92rem; font-weight: 700; }
.player-total { display: block; font-size: 0.78rem; color: var(--ink-soft); }
.cell { padding: 0; border-right: 1px solid var(--line); }
.cell-btn {
  width: 100%;
  min-width: 62px;
  height: 46px;
  border: none;
  background: transparent;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
}
.cell-btn.is-open { background: repeating-linear-gradient(45deg, transparent, transparent 6px, var(--surface-2) 6px, var(--surface-2) 7px); }
.cell-btn.is-open:active { background: var(--accent-soft); }
.cell-btn.is-zero { color: var(--zero); }
.total-row td, .total-row th { background: var(--surface-2); font-weight: 800; }
.total-row .num { text-align: center; font-size: 1rem; }
.total-row.grand td, .total-row.grand th { background: var(--accent-soft); font-size: 1.15rem; }
.num.good { color: var(--good); }
.num.pending { color: var(--ink-soft); }

/* -------------------------------------------------------- entry sheet */
.sheet-wrap {
  position: fixed;
  inset: 0;
  background: rgba(8, 16, 6, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 40;
}
.sheet {
  width: 100%;
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.sheet-player { font-size: 1.35rem; font-weight: 800; }
.sheet-cat { color: var(--ink-soft); }
.note { padding: 9px 12px; border-radius: 10px; margin-bottom: 10px; font-size: 0.92rem; }
.note-warn { background: var(--warn-soft); color: var(--warn); }
.note-good { background: var(--accent-soft); color: var(--good); font-weight: 600; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg-btn {
  flex: 1; min-height: 42px; border: none; background: transparent;
  border-radius: 9px; font-weight: 700; cursor: pointer; color: var(--ink-soft);
}
.seg-btn.is-on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

.dice-slots { display: flex; justify-content: space-between; margin-bottom: 12px; }
.die {
  flex: 1;
  margin: 0 3px;
  height: 58px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
  color: var(--ink-soft);
}
.die.is-set { border-style: solid; border-color: var(--accent); color: var(--ink); background: var(--surface-2); }
.dice-keys { display: flex; flex-wrap: wrap; margin: 0 -4px; }
.die-key {
  width: calc(33.333% - 8px);
  margin: 4px;
  height: 68px;
  font-size: 2.1rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  cursor: pointer;
}
.die-key:active { background: var(--accent-soft); }
.die-key-alt { font-size: 1.4rem; }

.value-pad .typed {
  text-align: center; font-size: 2.6rem; font-weight: 800; padding: 6px 0 12px;
}
.num-keys { display: flex; flex-wrap: wrap; margin: 0 -4px; }
.num-key {
  width: calc(33.333% - 8px);
  margin: 4px;
  height: 58px;
  font-size: 1.5rem;
  font-weight: 700;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
  cursor: pointer;
}
.quick-values { text-align: center; margin-top: 8px; }

.preview { margin: 12px 0; padding: 12px; background: var(--surface-2); border-radius: 12px; }
.preview-score { font-size: 1.5rem; }
.preview-score.is-zero { color: var(--danger); }
.alts { margin-top: 8px; display: flex; flex-wrap: wrap; align-items: center; }
.alt {
  margin: 4px 6px 0 0; padding: 6px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 0.85rem; cursor: pointer;
}
.sheet-actions { display: flex; margin: 14px 0 8px; }
.sheet-actions > * + * { margin-left: 10px; }
.sheet-actions .btn-xl { flex: 1; }

/* ------------------------------------------------------------- overlays */
.overlay {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(8, 16, 6, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 12px;
}
.overlay-card {
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: 18px; padding: 14px; box-shadow: var(--shadow);
}
.needs-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }

.menu-backdrop { position: fixed; inset: 0; z-index: 30; }
.menu-pop {
  position: absolute; right: 8px; top: 60px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; min-width: 230px;
}
.menu-item {
  display: block; width: 100%; text-align: left; padding: 14px 16px;
  background: none; border: none; border-bottom: 1px solid var(--line);
  cursor: pointer; text-decoration: none; color: inherit;
}
.menu-item.danger { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 999px; z-index: 60; font-weight: 600;
  max-width: 92vw; text-align: center; box-shadow: var(--shadow);
}

.loading { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink-soft); }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------- shared "needs" component */
.needs-head { display: flex; align-items: flex-start; justify-content: space-between; }
.needs-name { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }
.needs-sub { color: var(--ink-soft); font-size: 0.9rem; }
.needs-close { border: none; background: var(--surface-2); width: 40px; height: 40px; border-radius: 10px; font-size: 1.4rem; cursor: pointer; }
.needs-bonus { margin: 12px 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.bonus-line strong { font-size: 1.05rem; }
.bonus-line.is-good strong { color: var(--good); }
.bonus-line.is-bad strong { color: var(--danger); }
.bonus-line.is-tight strong { color: var(--warn); }
.bonus-pace { color: var(--ink-soft); font-size: 0.85rem; margin-top: 4px; }
.needs-cols { display: flex; margin: 0 -6px; }
.needs-col { flex: 1; padding: 0 6px; min-width: 0; }
.needs-col h4 {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink-soft); margin-bottom: 6px;
}
.need-row {
  position: relative; margin-bottom: 6px; border-radius: 9px;
  background: var(--surface-2); overflow: hidden; min-height: 40px;
  display: flex; align-items: center;
}
.need-bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-soft); }
.need-row.is-dump .need-bar { background: var(--surface-2); }
.need-body { position: relative; display: flex; align-items: baseline; padding: 8px 10px; width: 100%; }
.need-label { font-weight: 700; flex: 1; }
.need-max { color: var(--ink-soft); font-size: 0.82rem; margin-left: 6px; white-space: nowrap; }
.need-tag {
  margin-left: 8px; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--warn); border: 1px solid var(--warn); border-radius: 6px; padding: 1px 5px;
}
.needs-empty { color: var(--ink-soft); font-size: 0.9rem; padding: 8px 0; }
.needs-foot, .needs-done { margin-top: 10px; color: var(--ink-soft); font-size: 0.88rem; }
.needs-done { color: var(--good); font-weight: 700; }
