*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #b0b0b0;
  font-family: 'Nunito', sans-serif;
  touch-action: manipulation;
}
#app {
  width: 100vw; height: 100vh;
  display: flex; align-items: center; justify-content: center;
}

/* ══════════════════════════════════════
   CARD
══════════════════════════════════════ */
#card {
  width:  100vw;
  height: 100vh;
  background: linear-gradient(155deg, #fefcf8 0%, #f2ece0 100%);
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  position: relative;
}

/* Rainbow top stripe */
#card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: clamp(4px, 0.75vh, 8px);
  background: linear-gradient(90deg,
    #9b59b6 0%, #8e44ad 8%, #2980b9 17%, #3498db 25%,
    #27ae60 33%, #2ecc71 42%, #c9a800 50%, #e8c200 58%,
    #ca6f1e 67%, #e67e22 75%, #c0392b 83%, #e74c3c 100%);
  z-index: 10;
  pointer-events: none;
}

/* ══════════════════════════════════════
   SIDEBAR — vertical buttons left
══════════════════════════════════════ */
.sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(4px, 0.7vw, 8px);
  padding: clamp(14px, 2.5vh, 22px) clamp(4px, 0.6vw, 8px) clamp(6px,1vh,10px);
  flex-shrink: 0;
  background: rgba(0,0,0,0.04);
  border-right: 1px solid rgba(0,0,0,0.06);
}

.ctrl-btn {
  width:  clamp(32px, 5vw, 52px);
  height: clamp(32px, 5vw, 52px);
  border-radius: 10px;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.13);
  transition: background 0.16s, transform 0.09s;
  flex-shrink: 0;
}
.ctrl-btn:active { transform: scale(0.86); }
.ctrl-btn svg { width: 58%; height: 58%; fill: rgba(0,0,0,0.55); }
.ctrl-btn:hover { background: rgba(0,0,0,0.2); }
#resetBtn:hover { background: rgba(168,30,25,0.75); }
#resetBtn:hover svg { fill: white; }

/* ══════════════════════════════════════
   CONTENT AREA
══════════════════════════════════════ */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: clamp(4px,0.7vw,8px) clamp(4px,0.7vw,8px) clamp(3px,0.5vw,7px) clamp(3px,0.5vw,6px);
  gap: clamp(2px,0.35vh,4px);
  min-width: 0;
  margin-top: clamp(4px, 0.75vh, 8px);
}

/* ══════════════════════════════════════
   SHARED GRID
   Grid cols: [9 token] [mid-gap] [3 token] [small-gap] [score col]
   ALL columns are 1fr — score col same width as a token.
══════════════════════════════════════ */
.main-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: clamp(2px, 0.38vh, 4px);

  --g:  clamp(2px, 0.3vw, 3px);
  --mg: clamp(5px, 0.9vw, 10px);
}

.grid-row {
  display: grid;
  /* 9 token cols | mid-gap | 3 token cols | small-gap | score col (same 1fr) */
  grid-template-columns:
    repeat(9, 1fr)
    var(--mg)
    repeat(3, 1fr)
    var(--g)
    1fr;
  gap: var(--g);
  column-gap: var(--g);
  align-items: stretch;
}

/* The mid-gap placeholder cell sits at grid col 10 */
.gap-cell { /* no styling needed, just spacing via grid */ }

/* ══════════════════════════════════════
   GAME ROWS
══════════════════════════════════════ */
.rows-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.38vh, 4px);
  min-height: 0;
}

.game-row {
  flex: 1;
  min-height: 0;
}

/* ── Token ── */
.token {
  position: relative;
  cursor: pointer;
  user-select: none; -webkit-user-select: none;
  transition: transform 0.09s ease;
  border-radius: clamp(3px, 0.45vw, 5px);
  overflow: hidden;
  min-width: 0; min-height: 0;
}
.token:active { transform: scale(0.83); }

.token-bg {
  position: absolute; inset: 0;
  border-radius: inherit;
  transition: opacity 0.15s;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.16);
}

.token-num {
  position: relative; z-index: 2;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 32px);
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
  line-height: 1;
  pointer-events: none;
  transition: opacity 0.15s;
}

/* Diagonal cross mark (SVG overlay, shown when crossed) */
.token-cross {
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
.token-cross line {
  stroke: rgba(0,0,0,0.82);
  stroke-width: 5;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

/* ── States ── */

/* Crossed: keep full colour, overlay diagonal line */
.token.crossed .token-cross { opacity: 1; }
.token.crossed .token-num   { opacity: 0.55; }

/* Blocked (locked, can't cross yet): subtle desaturation */
.token.blocked {
  cursor: default;
}
.token.blocked .token-bg  { opacity: 0.45; filter: saturate(0.5); }
.token.blocked .token-num { opacity: 0.5; }

/* Row closed: remaining un-crossed target cols */
.token.row-closed {
  cursor: default; pointer-events: none;
}
.token.row-closed .token-bg  { opacity: 0.35; filter: saturate(0.3); }
.token.row-closed .token-num { opacity: 0.35; }

/* Row colors */
.r0 .token-bg { background: #8e44ad; }
.r1 .token-bg { background: #2980b9; }
.r2 .token-bg { background: #27ae60; }
.r3 .token-bg { background: #c9a800; }
.r4 .token-bg { background: #ca6f1e; }
.r5 .token-bg { background: #c0392b; }

/* ── Row score box — direct grid child ── */
.row-score {
  /* fills the 1fr grid column completely */
  min-width: 0;
  border: 2px solid;
  border-radius: clamp(3px, 0.45vw, 5px);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 32px);
  background: rgba(255,255,255,0.85);
  overflow: hidden;
}
.r0 .row-score { border-color: #8e44ad; color: #8e44ad; }
.r1 .row-score { border-color: #2980b9; color: #2980b9; }
.r2 .row-score { border-color: #27ae60; color: #27ae60; }
.r3 .row-score { border-color: #c9a800; color: #c9a800; }
.r4 .row-score { border-color: #ca6f1e; color: #ca6f1e; }
.r5 .row-score { border-color: #c0392b; color: #c0392b; }
.row-done .row-score {
  border-color: #c9a800 !important;
  color: #c9a800 !important;
}

/* ══════════════════════════════════════
   COLUMN SCORE ROW
   Lives inside rows-area with flex:1 so it's
   the same height as every game row.
══════════════════════════════════════ */
.col-scores-row {
  flex: 1;       /* same as .game-row — equal height to token rows */
  min-height: 0;
}

.col-score-box {
  width: 100%;
  min-width: 0; min-height: 0;
  border: 2px solid #c0bbb0;
  border-radius: clamp(3px, 0.45vw, 5px);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 32px);  /* same as token-num */
  color: #aaa;
  background: rgba(255,255,255,0.70);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  overflow: hidden;
}
.col-score-box.earned {
  color: #27ae60; border-color: #27ae60;
  background: rgba(39,174,96,0.08);
}
.col-score-empty { min-width: 0; min-height: 0; } /* invisible spacer */

/* ══════════════════════════════════════
   TOTAL — direct grid child spanning last 3 tracks
   (col12 token + small-gap + score col)
══════════════════════════════════════ */
.grand-total-box {
  min-width: 0;
  border: 3px solid #222;
  border-radius: clamp(3px, 0.45vw, 5px);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 32px);
  color: #222;
  background: rgba(255,255,255,0.95);
  overflow: hidden;
}

/* Empty spacer box in last col of col-score row */
.col-score-spacer-last {
  display: flex; align-items: stretch;
}

/* Hide scores toggle */
.scores-hidden .row-score,
.scores-hidden .col-score-box,
.scores-hidden .grand-total-box {
  color: transparent !important;
  border-color: rgba(0,0,0,0.15) !important;
  background: rgba(0,0,0,0.06) !important;
}
#hideScoresBtn.active svg { fill: rgba(0,0,0,0.25); }
#hideScoresBtn.active { background: rgba(0,0,0,0.07); }

/* ══════════════════════════════════════
   MODALS
══════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.52);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: #fefcf8;
  border-radius: 16px;
  max-width: 450px; width: 100%;
  max-height: 88vh; overflow-y: auto;
  padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  transform: translateY(14px) scale(0.97);
  transition: transform 0.2s ease;
  position: relative;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-close {
  position: absolute; top: 11px; right: 11px;
  width: 27px; height: 27px; border-radius: 50%;
  border: none; background: #eee; cursor: pointer;
  font-size: 0.85rem; display: flex; align-items: center; justify-content: center;
  color: #666; transition: background 0.15s;
}
.modal-close:hover { background: #ddd; }

.modal h2 {
  font-weight: 900; font-size: 1.3rem; color: #222;
  margin-bottom: 11px;
}
.modal h3 {
  font-size: 0.75rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1.5px;
  color: #aaa; margin: 12px 0 5px;
}
.modal p, .modal li {
  font-family: 'Nunito Sans', sans-serif;
  font-size: 0.85rem; color: #444; line-height: 1.55;
}
.modal ul { padding-left: 16px; }
.modal li { margin-bottom: 3px; }

.score-table-visual {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px;
}
.stv-cell {
  display: flex; flex-direction: column; align-items: center;
  min-width: 28px; background: #f0ece3;
  border-radius: 5px; padding: 3px 4px;
}
.stv-cell .stv-h { font-size: 0.63rem; color: #aaa; font-weight: 700; font-family: 'Nunito Sans', sans-serif; }
.stv-cell .stv-v { font-size: 0.76rem; font-weight: 900; color: #333; }
.stv-cell .stv-v.red { color: #e74c3c; }

.cdot {
  display: inline-block; width: 9px; height: 9px;
  border-radius: 2px; vertical-align: middle; margin-right: 4px;
}

/* Reset modal */
.reset-modal .modal { max-width: 320px; text-align: center; }
.modal-btn-row { display: flex; gap: 10px; margin-top: 16px; }
.modal-btn {
  flex: 1; padding: 10px 0;
  border-radius: 10px; border: none;
  font-family: 'Nunito', sans-serif; font-weight: 800;
  font-size: 0.9rem; cursor: pointer; transition: filter 0.15s;
}
.modal-btn:active { filter: brightness(0.9); }
.modal-btn.cancel  { background: #eee; color: #555; }
.modal-btn.confirm { background: #c0392b; color: white; }

/* ── Zwevende knoppen linksonder ── */
.playo-home {
  top: auto !important;
  bottom: 64px !important; left: 14px !important;
}
.playo-rules {
  top: auto !important;
  bottom: 14px !important; left: 14px !important;
}