/* ── Yahtzee theme tokens ──────────────────────────────────── */
:root {
  --yah-bg:          #f1f5f9;
  --yah-surface:     #ffffff;
  --yah-red:         #b91c1c;
  --yah-red-dark:    #991b1b;
  --yah-red-light:   #fef2f2;
  --yah-red-mid:     #fca5a5;
  --yah-navy:        #1e3a8a;
  --yah-navy-dark:   #172554;
  --yah-navy-light:  #eff6ff;
  --yah-text:        #0f172a;
  --yah-muted:       #64748b;
  --yah-border:      #e2e8f0;
  --yah-border-md:   #cbd5e1;
  --yah-green:       #15803d;
  --yah-green-light: #f0fdf4;
  --yah-gold:        #b45309;
  --yah-nav-h:       52px;
}

/* ── Override styles.css body for Yahtzee ─────────────────── */
body {
  background-color: var(--yah-bg);
  color: var(--yah-text);
  font-family: 'DM Sans', sans-serif;
  height: auto;
  min-height: 100svh;
  overflow-x: hidden;
  overflow-y: auto;
  display: block;
  align-items: unset;
  overscroll-behavior: auto;
}

*, *::before, *::after {
  touch-action: manipulation;
}

/* ── Navbar ────────────────────────────────────────────────── */
.yah-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--yah-nav-h);
  background: var(--yah-red);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  z-index: 50;
  box-shadow: 0 2px 12px rgba(185,28,28,0.25);
}

.yah-logo {
  font-family: 'Bebas Neue', cursive;
  font-size: 1.6rem;
  color: #ffffff;
  text-decoration: none;
  letter-spacing: 0.04em;
  line-height: 1;
  flex-shrink: 0;
}

.yah-logo:hover { opacity: 0.85; }

.yah-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
}

.yah-nav-links a {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  padding: 5px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.yah-nav-links a:hover  { background: rgba(255,255,255,0.15); color: #fff; }
.yah-nav-links a.active { background: rgba(255,255,255,0.2);  color: #fff; }

/* ── Setup screen ──────────────────────────────────────────── */
#setup-screen {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.setup-body {
  width: 100%;
  max-width: 440px;
  padding: 36px 24px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* Dice icon in setup */
.setup-dice {
  margin-bottom: 20px;
  opacity: 0.9;
}

.setup-title {
  font-family: 'Bebas Neue', cursive;
  font-size: clamp(4rem, 14vw, 6rem);
  color: var(--yah-red);
  line-height: 0.9;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  text-align: center;
}

.setup-sub {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--yah-muted);
  margin-bottom: 32px;
  text-align: center;
}

.setup-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--yah-muted);
  margin-bottom: 10px;
  align-self: flex-start;
}

#player-list {
  width: 100%;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.yah-player-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.yah-input {
  flex: 1;
  height: 48px;
  padding: 0 14px;
  background: var(--yah-surface);
  border: 2px solid var(--yah-border);
  border-radius: 10px;
  font-family: 'DM Sans', sans-serif;
  font-size: 16px; /* prevents iOS zoom */
  font-weight: 600;
  color: var(--yah-text);
  outline: none;
  transition: border-color 0.15s;
}

.yah-input:focus { border-color: var(--yah-red); }

.yah-del-btn {
  width: 44px;
  height: 44px;
  background: var(--yah-red-light);
  border: 2px solid var(--yah-red-mid);
  color: var(--yah-red-dark);
  border-radius: 10px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.yah-del-btn:hover { background: #fee2e2; }

.add-player-btn {
  background: none;
  border: none;
  color: var(--yah-navy);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  align-self: flex-start;
  padding: 4px 0;
  margin-bottom: 24px;
}

.yah-start-btn {
  width: 100%;
  height: 56px;
  background: var(--yah-red);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-family: 'Bebas Neue', cursive;
  font-size: 1.8rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  margin-top: auto;
  box-shadow: 0 4px 20px rgba(185,28,28,0.3);
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
}

.yah-start-btn:hover {
  background: var(--yah-red-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(185,28,28,0.38);
}

.yah-start-btn:active { transform: translateY(0); }

/* ── Game screen ───────────────────────────────────────────── */
#game-screen {
  height: calc(100svh - var(--tl-nav-h) - env(safe-area-inset-top));
  display: none;
  flex-direction: column;
}

.game-ctrl-bar {
  background: var(--yah-surface);
  border-bottom: 1px solid var(--yah-border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.game-status {
  font-size: 0.7rem;
  color: var(--yah-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-right: auto;
}

.new-game-btn {
  height: 32px;
  padding: 0 14px;
  background: var(--yah-red-light);
  border: 1.5px solid var(--yah-red-mid);
  color: var(--yah-red-dark);
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.15s;
}

.new-game-btn:hover { background: #fee2e2; }

/* ── Score area + table ────────────────────────────────────── */
.score-area {
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.score-table-wrap {
  min-width: max-content;
  padding-bottom: env(safe-area-inset-bottom);
}

#score-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--yah-surface);
}

/* Sticky category column */
#score-table .td-cat,
#score-table .th-cat {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--yah-surface);
}

/* Headers */
.th-row th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--yah-surface);
  border-bottom: 2px solid var(--yah-border-md);
  padding: 10px 8px;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 1px 0 var(--yah-border-md);
}

.th-cat {
  text-align: left !important;
  padding-left: 14px !important;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--yah-muted);
  min-width: 142px;
  max-width: 142px;
}

.th-pl {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--yah-text);
  min-width: 58px;
}

.th-pl.th-done {
  color: var(--yah-green);
}

/* Section header rows */
.sec-hdr td {
  padding: 7px 14px;
  font-family: 'Bebas Neue', cursive;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  border-top: 1px solid var(--yah-border);
}

.sec-hdr span {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  color: #fff;
}

.sec-red  { background: var(--yah-red-light); }
.sec-red  span { background: var(--yah-red); }
.sec-navy { background: var(--yah-navy-light); }
.sec-navy span { background: var(--yah-navy); }

/* Category cells */
.td-cat {
  padding: 0 6px 0 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--yah-text);
  white-space: nowrap;
  border-right: 2px solid var(--yah-border-md);
  background: var(--yah-surface);
}

.cat-sub {
  display: block;
  font-size: 0.58rem;
  font-weight: 400;
  color: var(--yah-muted);
  line-height: 1.2;
}

/* Score cells */
.cat-row { border-bottom: 1px solid var(--yah-border); }

.sc {
  height: 44px;
  min-width: 58px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  border-right: 1px solid var(--yah-border);
  transition: background 0.12s;
  vertical-align: middle;
}

.cell-empty {
  background: var(--yah-surface);
  color: transparent;
  position: relative;
}

/* Subtle dot hint for empty tappable cells */
.cell-empty::after {
  content: '•';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--yah-border-md);
  font-size: 1rem;
}

.cell-empty:hover,
.cell-empty:focus { background: #f0f4ff; outline: none; }

.cell-scored { background: #fff; color: var(--yah-text); }
.cell-scored:hover,
.cell-scored:focus { background: #f8faff; outline: none; }

.cell-scratched { background: var(--yah-border); color: var(--yah-muted); font-weight: 400; }

/* Progress row */
.prog-row td {
  border-bottom: 1px solid var(--yah-border);
}

.td-prog-lbl {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--yah-muted);
  padding: 8px 6px 8px 14px;
}

.td-prog {
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
}

.prog-frac {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--yah-muted);
  margin-bottom: 3px;
}

.prog-track {
  width: 42px;
  height: 5px;
  background: var(--yah-border);
  border-radius: 99px;
  overflow: hidden;
  margin: 0 auto 3px;
}

.prog-fill {
  height: 100%;
  background: var(--yah-red);
  border-radius: 99px;
  transition: width 0.3s ease;
}

.prog-lbl {
  display: block;
  font-size: 0.55rem;
  color: var(--yah-muted);
  white-space: nowrap;
}

.td-prog.prog-done .prog-fill { background: var(--yah-green); }
.td-prog.prog-done .prog-frac,
.td-prog.prog-done .prog-lbl  { color: var(--yah-green); font-weight: 700; }

/* Bonus display row */
.bonus-disp-row { border-bottom: 1px solid var(--yah-border); }

.td-bonus-disp {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 4px;
}

.bonus-yes { color: var(--yah-green); }
.bonus-no  { color: var(--yah-muted); }

/* Subtotal rows */
.sub-row { border-bottom: 2px solid var(--yah-border-md); background: var(--yah-bg); }

.td-sub-lbl {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--yah-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.td-sub {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--yah-navy);
  padding: 8px 4px;
}

/* Yahtzee bonus row */
.yb-row { border-bottom: 1px solid var(--yah-border); }

.td-yb {
  text-align: center;
  cursor: pointer;
  padding: 6px 4px;
  height: 44px;
  vertical-align: middle;
  transition: background 0.12s;
}

.td-yb:hover { background: var(--yah-navy-light); }

.yb-x {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--yah-navy);
}

.yb-pts {
  display: block;
  font-size: 0.6rem;
  color: var(--yah-green);
  font-weight: 700;
}

/* Grand total row */
.grand-row { background: var(--yah-text); }

.td-grand-lbl {
  color: #fff;
  font-family: 'Bebas Neue', cursive;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  background: var(--yah-text) !important;
}

.td-grand {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255,255,255,0.75);
  padding: 10px 4px;
  background: var(--yah-text);
}

.td-winner {
  color: #fbbf24 !important;
  font-size: 1.05rem;
}

/* ── Picker overlay ────────────────────────────────────────── */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.picker-overlay.vis {
  opacity: 1;
  pointer-events: all;
}

/* ── Picker panel ──────────────────────────────────────────── */
.picker-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 500px;
  margin: 0 auto;
  background: var(--yah-surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 32px rgba(15,23,42,0.18);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
  padding: 0 0 calc(16px + env(safe-area-inset-bottom));
  max-height: 72vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.picker-panel.open { transform: translateY(0); }

/* Handle */
.picker-handle {
  width: 38px;
  height: 4px;
  background: var(--yah-border-md);
  border-radius: 99px;
  margin: 12px auto 0;
}

#picker-content {
  padding: 0 20px 8px;
}

/* Picker header */
.pk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 4px;
  border-bottom: 1px solid var(--yah-border);
  margin-bottom: 16px;
}

.pk-player {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--yah-muted);
}

.pk-close {
  width: 32px;
  height: 32px;
  background: var(--yah-border);
  border: none;
  border-radius: 50%;
  color: var(--yah-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.pk-close:hover { background: var(--yah-border-md); }

.pk-cat {
  font-family: 'Bebas Neue', cursive;
  font-size: 1.5rem;
  color: var(--yah-text);
  letter-spacing: 0.04em;
  margin-bottom: 16px;
  line-height: 1;
}

.pk-hint {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--yah-muted);
  letter-spacing: 0;
}

/* Button grid */
.pk-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.pk-grid-2 { grid-template-columns: 1fr 1fr; }

.pk-btn {
  height: 56px;
  border-radius: 10px;
  border: 2px solid var(--yah-border);
  background: var(--yah-bg);
  color: var(--yah-text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
}

.pk-btn small {
  display: block;
  font-size: 0.62rem;
  font-weight: 400;
  color: var(--yah-muted);
}

.pk-btn:hover  { background: var(--yah-navy-light); border-color: var(--yah-navy); }
.pk-btn:active { transform: scale(0.96); }

.pk-btn.pk-sel {
  background: var(--yah-navy);
  border-color: var(--yah-navy-dark);
  color: #fff;
}

.pk-btn.pk-sel small { color: rgba(255,255,255,0.7); }

.pk-btn.pk-scratch       { border-color: var(--yah-red-mid); color: var(--yah-red-dark); }
.pk-btn.pk-scratch:hover { background: var(--yah-red-light); border-color: var(--yah-red); }
.pk-btn.pk-scratch.pk-sel { background: var(--yah-red); border-color: var(--yah-red-dark); color: #fff; }

.pk-btn.pk-main          { border-color: #86efac; color: var(--yah-green); }
.pk-btn.pk-main:hover    { background: var(--yah-green-light); }
.pk-btn.pk-main.pk-sel   { background: var(--yah-green); border-color: #15803d; color: #fff; }

/* Variable score: scratch + strip */
.pk-var-scratch { margin-bottom: 12px; }

.pk-scratch-full {
  width: 100%;
  height: 44px;
}

.pk-strip-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--yah-muted);
  margin-bottom: 8px;
}

.pk-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.pk-strip::-webkit-scrollbar { height: 4px; }
.pk-strip::-webkit-scrollbar-track { background: var(--yah-border); border-radius: 99px; }
.pk-strip::-webkit-scrollbar-thumb { background: var(--yah-border-md); border-radius: 99px; }

.pk-strip-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 2px solid var(--yah-border);
  background: var(--yah-bg);
  color: var(--yah-text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.pk-strip-btn:hover  { background: var(--yah-navy-light); border-color: var(--yah-navy); }
.pk-strip-btn.pk-sel { background: var(--yah-navy); border-color: var(--yah-navy-dark); color: #fff; }

/* Yahtzee bonus picker */
.pk-ybonus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 0 8px;
}

.pk-yb-ctrl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--yah-border-md);
  background: var(--yah-bg);
  color: var(--yah-text);
  font-size: 1.6rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.pk-yb-ctrl:hover:not([disabled]) { background: var(--yah-navy-light); border-color: var(--yah-navy); }
.pk-yb-ctrl[disabled] { opacity: 0.3; cursor: not-allowed; }

.pk-sub { color: var(--yah-red); border-color: var(--yah-red-mid); }
.pk-sub:hover:not([disabled]) { background: var(--yah-red-light) !important; border-color: var(--yah-red) !important; }

.pk-add { color: var(--yah-green); border-color: #86efac; }
.pk-add:hover { background: var(--yah-green-light) !important; border-color: var(--yah-green) !important; }

.pk-yb-mid { text-align: center; min-width: 72px; }

.pk-yb-n {
  font-family: 'Bebas Neue', cursive;
  font-size: 3rem;
  color: var(--yah-navy);
  line-height: 1;
}

.pk-yb-pts {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--yah-green);
}

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .picker-panel,
  .picker-overlay,
  .prog-fill,
  .pk-btn,
  .pk-strip-btn,
  .pk-yb-ctrl { transition: none; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (min-width: 480px) {
  .pk-grid { grid-template-columns: repeat(3, 1fr); }
  .th-cat { min-width: 160px; }
}

@media (min-width: 768px) {
  .yah-nav { padding: 0 24px; }
  .th-pl { min-width: 72px; }
  .sc { min-width: 72px; }
}

/* ══════════════════════════════════════════════
   YAHTZEE OVERLAY
══════════════════════════════════════════════ */
#yah-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#yah-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.yah-ov-dice {
  font-size: 2.6rem;
  letter-spacing: 6px;
  margin-bottom: 18px;
  animation: yahBounceDice 0.45s ease-in-out infinite alternate;
}

.yah-ov-text {
  font-family: 'Bebas Neue', cursive;
  font-size: 5rem;
  letter-spacing: 0.06em;
  line-height: 1;
  animation: yahPulse 0.5s ease-in-out infinite alternate;
}

.yah-ov-sub {
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.55);
}

@keyframes yahBounceDice {
  from { transform: translateY(0) rotate(-8deg); }
  to   { transform: translateY(-18px) rotate(8deg); }
}

@keyframes yahPulse {
  from { color: #fca5a5; text-shadow: 0 0 20px rgba(185, 28, 28, 0.5); }
  to   { color: #ffffff; text-shadow: 0 0 60px rgba(239, 68, 68, 1), 0 0 120px rgba(185, 28, 28, 0.5); }
}

@media (prefers-reduced-motion: reduce) {
  .yah-ov-dice { animation: none; }
  .yah-ov-text { animation: none; color: #fca5a5; }
}
