:root {
  --bg: #0f1a12;
  --panel: #16241a;
  --panel-2: #1d2f22;
  --text: #e8f0e9;
  --muted: #9db3a2;
  --home: #e0453a;
  --home-dark: #47201d;
  --away: #3a6fe0;
  --away-dark: #1c2947;
  --accent: #f2c14e;
  --grass-a: #2e7d3a;
  --grass-b: #2a7335;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: var(--panel-2);
  border: 1px solid #345c3f;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }
button.primary { background: var(--accent); color: #201700; border-color: var(--accent); font-weight: 700; }

.screen { display: none; height: 100%; }
.screen.visible { display: flex; flex-direction: column; }

/* ---------------- Menu ---------------- */
#screen-menu.visible { align-items: center; justify-content: center; }
.menu-inner { display: flex; flex-direction: column; gap: 14px; width: min(320px, 86vw); text-align: center; }
.menu-inner h1 { font-size: 2.2rem; }
.tagline { color: var(--muted); margin-bottom: 12px; }
.menu-btn { font-size: 1.1rem; padding: 14px; }
.menu-btn-quiet { background: transparent; }
.menu-toggle {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  color: var(--muted); font-size: 0.9rem; cursor: pointer; padding: 4px;
}
.menu-toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------------- Draft & lineup ---------------- */
.setup-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 12px 16px; background: var(--panel); gap: 12px;
}

/* Whole setup screen tints to whoever is picking — no wrong-team picks. */
#screen-draft, #screen-assign { transition: background-color 0.35s ease; }
#screen-draft.for-home, #screen-assign.for-home { background-color: #331411; }
#screen-draft.for-away, #screen-assign.for-away { background-color: #101b36; }
.for-home .setup-head { background: var(--home-dark); border-bottom: 3px solid var(--home); }
.for-away .setup-head { background: var(--away-dark); border-bottom: 3px solid var(--away); }
.for-home #draft-title, .for-home #assign-title { color: var(--home); }
.for-away #draft-title, .for-away #assign-title { color: var(--away); }
.setup-head p { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
#draft-quit, #assign-quit { padding: 4px 10px; }

#draft-rosters { display: flex; gap: 8px; padding: 8px 12px; }
.draft-roster {
  flex: 1; border-radius: 10px; padding: 8px 10px; min-height: 74px;
  font-size: 0.78rem; line-height: 1.5;
  column-count: 2; column-gap: 10px;
}
.draft-roster h3 { column-span: all; font-size: 0.9rem; margin-bottom: 2px; }
.roster-home { background: var(--home-dark); }
.roster-away { background: var(--away-dark); }
.roster-line { break-inside: avoid; }

#draft-pool {
  flex: 1; overflow-y: auto; padding: 8px 12px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 8px; align-content: start;
}
.pcard {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: left; padding: 8px 10px; line-height: 1.2;
}
.pcard .portrait { align-self: center; border-radius: 8px; }
.pc-ability {
  display: block; font-size: 0.7rem; color: var(--accent); line-height: 1.25;
  border-top: 1px dashed rgba(242, 193, 78, 0.3); padding-top: 3px; margin-top: 2px;
}
.pc-ability b { font-weight: 800; }
.pc-ability i { display: block; font-style: normal; color: var(--muted); font-size: 0.66rem; }
.assign-row .pc-ability i { display: none; }

.tp-charges {
  display: flex; align-items: center; gap: 6px; font-weight: 800;
  color: var(--accent); font-size: 0.9rem;
}
.tp-charges span { display: flex; gap: 3px; }
.tp-charges i {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.tp-charges .pip-on { background: var(--accent); box-shadow: 0 0 4px var(--accent); }
.tp-charges .pip-off { background: rgba(255, 255, 255, 0.15); }

/* active-player card in the team panel */
.tp-player {
  width: 100%; background: rgba(0, 0, 0, 0.28); border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16); padding: 8px; text-align: left;
  animation: tray-in 0.2s ease;
}
.tp-player-head { display: flex; gap: 8px; align-items: center; }
.tp-player-head .portrait { flex: none; border-radius: 6px; }
.tp-player-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tp-player-info b { font-size: 0.78rem; line-height: 1.15; }
.tp-player-info span { display: flex; flex-wrap: wrap; gap: 2px 6px; font-size: 0.68rem; color: var(--muted); }
.tp-ability-row { display: flex; gap: 4px; margin-top: 7px; }
.tp-ability-btn {
  flex: 1; padding: 5px 4px; font-size: 0.72rem; font-weight: 700;
  border-radius: 8px; border-color: var(--accent); color: var(--accent);
  background: rgba(242, 193, 78, 0.08); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tp-ability-btn:not(:disabled) { background: var(--accent); color: #201700; }
.tp-flip { padding: 5px 8px; font-size: 0.72rem; border-radius: 8px; flex: none; }
.tp-ability-when { display: block; margin-top: 3px; font-size: 0.64rem; color: var(--muted); }
.tp-ability-when.tp-ready { color: #7fe09a; font-weight: 700; }
.tp-player.flipped .tp-player-front { display: none; }
.tp-player-back { display: none; }
.tp-player.flipped .tp-player-back { display: block; animation: flip-in 0.25s ease; }
.tp-player-back b { font-size: 0.76rem; color: var(--accent); }
.tp-player-back p { font-size: 0.7rem; color: var(--text); margin: 5px 0 7px; line-height: 1.35; }
@keyframes flip-in { from { transform: rotateY(80deg); opacity: 0.3; } }

/* ability target picking: victims pulse red and light up under the cursor */
.meeple-target svg {
  filter: drop-shadow(0 0 6px rgba(255, 82, 60, 0.95));
  animation: target-pulse 0.9s ease-in-out infinite;
}
.meeple-target .meeple-hit { cursor: crosshair; }
.meeple-target:has(.meeple-hit:hover) svg {
  filter: drop-shadow(0 0 10px rgba(255, 82, 60, 1)) brightness(1.3);
  animation: none;
}
.piece.is-target .disc {
  stroke: #ff523c; stroke-width: 3.5;
  animation: target-pulse 0.9s ease-in-out infinite;
}
@keyframes target-pulse { 50% { opacity: 0.65; } }

/* fouled/frozen players */
.piece.is-frozen { opacity: 0.55; filter: grayscale(0.8); }
.meeple-frozen svg { transform: rotate(80deg) translateY(6px); filter: grayscale(0.75) brightness(0.8); }
.meeple-frozen { pointer-events: auto; }
.assign-row .portrait { flex: none; width: 36px; height: 36px; border-radius: 6px; }
.pcard:not(:disabled):hover { border-color: var(--accent); }
.pc-name { font-size: 0.88rem; }
.pc-stats { color: var(--muted); font-size: 0.72rem; display: flex; flex-wrap: wrap; gap: 2px 8px; }

.stat-chip { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.stat-chip i { font-style: normal; font-size: 0.86em; color: var(--muted); }
.stat-chip b { font-weight: 700; color: var(--text); }
.stat-ico { width: 11px; height: 11px; fill: currentColor; opacity: 0.85; flex: none; }
.chip-stats { color: var(--muted); display: inline-flex; gap: 8px; }
.stats-ico { fill: var(--muted); }
.pc-role {
  font-style: normal; font-size: 0.66rem; font-weight: 800; padding: 1px 6px;
  border-radius: 999px; color: #10240f;
}
.pc-GK { background: var(--accent); }
.pc-DF { background: #7fb3e0; }
.pc-MF { background: #9fe0b0; }
.pc-FW { background: #e0a67f; }

#assign-list {
  flex: 1; overflow-y: auto; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.assign-row {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 8px 12px; width: 100%;
}
.assign-row .pc-name { flex: 1; }
.assign-row .pc-stats { text-align: right; }
.assign-gk { background: rgba(242, 193, 78, 0.08); border: 1px solid #3a5c44; border-radius: 10px; }
.assign-selected { border-color: var(--accent); background: #2b2413; }
.slot-label { min-width: 84px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.assign-buttons { display: flex; gap: 10px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.assign-buttons button { flex: 1; padding: 12px; }

/* ---------------- Topbar: clock + progress ---------------- */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--panel);
}
#clock { display: flex; align-items: baseline; gap: 8px; min-width: 110px; }
#clock b { font-size: 1.3rem; }
#clock span { color: var(--muted); font-size: 0.8rem; }
#progress {
  position: relative; flex: 1; height: 8px; border-radius: 4px;
  background: #0a130c; overflow: hidden;
}
#progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #3f8f4f, var(--accent));
  transition: width 0.4s ease;
}
#progress-mid {
  position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
  background: rgba(255, 255, 255, 0.4);
}
#turn-label { color: var(--muted); font-size: 0.75rem; min-width: 74px; text-align: right; }
#btn-quit, #btn-speed, #btn-pause { padding: 4px 10px; border-radius: 8px; }

/* ---------------- Match body: side panels + board ---------------- */
#match-body {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(120px, 158px) 1fr minmax(120px, 158px);
  gap: 6px; padding: 6px;
}

.team-panel {
  border-radius: 12px; padding: 10px; display: flex; flex-direction: column;
  gap: 6px; align-items: center; text-align: center;
  border: 2px solid transparent; transition: border-color 0.3s ease;
}
.team-panel-home { background: var(--home-dark); }
.team-panel-away { background: var(--away-dark); }
.team-panel.tp-active { border-color: var(--accent); }
.tp-name { font-weight: 800; font-size: 1.05rem; }
.team-panel-home .tp-name { color: var(--home); }
.team-panel-away .tp-name { color: var(--away); }
.tp-score { font-size: 2.1rem; font-weight: 900; line-height: 1; }
.tp-controller { color: var(--muted); font-size: 0.72rem; }
.tp-active .tp-controller { color: var(--accent); }

.tp-card {
  width: 100%; display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 8px 4px; font-size: 0.72rem; line-height: 1.15;
  background: rgba(0, 0, 0, 0.28); border-color: rgba(255, 255, 255, 0.18);
  margin-top: auto;
}
.tp-card:not(:disabled):hover { border-color: var(--accent); }
.tp-card b { font-size: 0.95rem; }
.tp-card span { color: var(--muted); }
.tp-card em { color: var(--accent); font-style: normal; font-size: 0.68rem; }
.tp-card:disabled { opacity: 0.8; }

#board-wrap {
  position: relative; min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#board { width: 100%; height: 100%; }

/* ---------------- 3D view: tilted table + standing meeples ---------------- */
body.view3d #board {
  /* pure affine, vertical-only scale so goals never clip the container;
     meeples.js project() matches this exactly */
  transform: rotateX(38deg) scale(1, 1.14);
  transition: transform 0.4s ease;
}
body.view3d #board .piece,
body.view3d #board .ball { opacity: 0; pointer-events: none; }
/* ring + stats render as HTML above the meeples in 3D view */
body.view3d .layer-ring,
body.view3d .layer-stats { display: none; }

#hud-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.hud-ring {
  position: absolute; display: flex; gap: 6px; pointer-events: auto;
  transform: translate(-50%, -100%);
}
.hud-pill {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 12px; border-radius: 14px; line-height: 1.1;
  background: rgba(10, 20, 12, 0.94); border: 1.5px solid var(--accent);
}
.hud-pill b { font-size: 0.85rem; }
.hud-pill span { font-size: 0.66rem; color: var(--accent); }
.hud-pill { transition: transform 0.12s ease, background 0.12s ease; cursor: pointer; }
.hud-pill:hover { background: #2d260c; transform: translateY(-2px) scale(1.05); }
.hud-stats {
  position: absolute; display: flex; gap: 8px; align-items: center;
  padding: 8px 12px 8px 8px; border-radius: 10px; pointer-events: auto;
  background: rgba(8, 16, 10, 0.95); border: 1px solid rgba(255,255,255,0.35);
  max-width: 250px; cursor: pointer; transition: border-color 0.15s ease;
}
.hud-stats:hover { border-color: var(--accent); }
.hud-ability-line {
  text-decoration: none; color: var(--accent); font-size: 0.72rem; font-weight: 700;
}
.hud-ability-line em { color: var(--muted); font-style: normal; font-weight: 400; }
.hud-stats.hud-flipped { animation: flip-in 0.25s ease; }
.hud-stats-ability { max-width: 220px; }
.hud-stats-ability b { color: var(--accent); font-size: 0.8rem; }
.hud-stats-ability p { color: var(--text); font-size: 0.74rem; margin: 4px 0; line-height: 1.35; }
.hud-stats-ability em { color: var(--muted); font-style: normal; font-size: 0.66rem; }
.hud-stats.team-home { border-top: 4px solid var(--home); }
.hud-stats.team-away { border-top: 4px solid var(--away); }
.hud-stats .portrait { border-radius: 8px; flex: none; }
.hud-stats-body { display: flex; flex-direction: column; gap: 3px; }
.hud-stats-body b { font-size: 0.82rem; white-space: nowrap; }
.hud-stats-body i { color: var(--muted); font-style: normal; font-weight: 400; }
.hud-stats-body span { display: flex; gap: 8px; font-size: 0.78rem; color: var(--muted); }

/* natural materials: wooden tabletop, felt-toned pitch, soft warm light */
body.view3d #board-wrap {
  background:
    repeating-linear-gradient(90deg,
      rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 84px),
    linear-gradient(180deg, #6d4a2a, #55381f 55%, #452c17);
}
body.view3d .grass-bg { fill: transparent; }
body.view3d .stripe-a { fill: #5f7f4c; }
body.view3d .stripe-b { fill: #587847; }
body.view3d .grid { stroke: rgba(40, 28, 12, 0.14); }
body.view3d .chalk { stroke: rgba(246, 238, 218, 0.8); }
body.view3d .goal-box { fill: #3e2a17; stroke: #e8dcc4; }
body.view3d .net { stroke: rgba(240, 230, 205, 0.3); }
body.view3d #board-wrap::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none; z-index: 4;
  background:
    linear-gradient(165deg, rgba(255, 243, 205, 0.12), transparent 45%),
    radial-gradient(ellipse 120% 90% at 50% 30%, transparent 55%, rgba(20, 10, 4, 0.28));
}
#meeple-layer { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
body:not(.view3d) #meeple-layer { display: none; }
.meeple {
  position: absolute; pointer-events: none; cursor: pointer;
  transition: left 0.45s ease, top 0.45s ease;
}
.meeple svg { width: 100%; height: 100%; overflow: visible; }
.meeple-hit {
  position: absolute; left: 12%; right: 12%; bottom: 0; height: 52%;
  pointer-events: auto; cursor: pointer;
}
.meeple:has(.meeple-hit:hover) svg {
  filter: brightness(1.18) drop-shadow(0 0 5px rgba(255, 255, 255, 0.55));
}
.meeple-active svg { animation: meeple-bob 1.3s ease-in-out infinite; }
.meeple-active .meeple-body { filter: drop-shadow(0 0 5px rgba(255,255,255,0.9)); }
.meeple-ai-active .meeple-body { filter: drop-shadow(0 0 4px rgba(255,255,255,0.45)); }
@keyframes meeple-bob { 50% { transform: translateY(-5px); } }
.meeple-ball {
  position: absolute; pointer-events: none;
  transition: left 0.45s ease, top 0.45s ease;
}
.meeple-ball svg { width: 100%; height: 100%; }

/* 3D dice canvas inside the roll cinematic */
.do-dice.do-dice3d { width: 250px; height: 120px; margin: 8px auto 2px; display: block; }
.do-dice.do-dice3d canvas { width: 100%; height: 100%; display: block; }
.do-dice.do-dice3d .die { display: none; }

/* fullscreen shot cutscene */
#cutscene {
  position: fixed; inset: 0; z-index: 9; display: none;
  background: #0a140c; cursor: pointer;
}
#cutscene.visible { display: block; }
#cutscene canvas { width: 100%; height: 100%; display: block; }

/* ---------------- Board SVG ---------------- */
.grass-bg { fill: #14301a; }
.stripe-a { fill: var(--grass-a); }
.stripe-b { fill: var(--grass-b); }
.grid { stroke: rgba(255, 255, 255, 0.10); stroke-width: 1; }
.chalk { stroke: rgba(255, 255, 255, 0.75); stroke-width: 2; fill: none; }

.goal-box { fill: #10240f; stroke: #fff; stroke-width: 2.5; }
.net { stroke: rgba(255, 255, 255, 0.18); stroke-width: 1; }
.goal-cell-rect { fill: transparent; stroke: transparent; }
.goal-cell.aimable .goal-cell-rect {
  fill: rgba(242, 193, 78, 0.25);
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: pointer;
  animation: pulse 1.2s ease-in-out infinite;
}
.goal-cell-tn { fill: #ffe9b0; font-size: 12px; font-weight: 700; text-anchor: middle; pointer-events: none; }

.piece { cursor: pointer; transition: transform 0.45s ease; }
.piece .disc { stroke: rgba(0, 0, 0, 0.55); stroke-width: 2; }
.team-home .disc { fill: var(--home); }
.team-away .disc { fill: var(--away); }
.piece .num {
  fill: #fff; font-size: 16px; font-weight: 800; text-anchor: middle;
  dominant-baseline: middle; pointer-events: none;
  paint-order: stroke; stroke: rgba(0,0,0,0.45); stroke-width: 2px;
}
.piece .gk-ring { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4; }
.piece .active-ring { fill: none; stroke: transparent; stroke-width: 3; }
.piece.is-active .active-ring {
  stroke: #fff; stroke-dasharray: 8 6;
  animation: spin-ring 3s linear infinite;
}
.piece.is-ai-active .active-ring { stroke: rgba(255,255,255,0.5); stroke-dasharray: 3 5; }
@keyframes spin-ring { to { stroke-dashoffset: -56; } }

.ball { transition: transform 0.45s ease; pointer-events: none; }
.ball-outer { fill: #fff; stroke: #222; stroke-width: 1.5; }
.ball-inner { fill: #222; }

.hl { cursor: pointer; }
.hl-move { fill: rgba(255, 255, 255, 0.22); stroke: rgba(255,255,255,0.5); stroke-width: 1; }
.hl-move:hover { fill: rgba(255, 255, 255, 0.38); }
.hl-pass { fill: rgba(242, 193, 78, 0.15); stroke: rgba(255, 255, 255, 0.22); stroke-width: 1; }
.hl-offside {
  fill: rgba(214, 60, 40, 0.4); stroke: rgba(255, 96, 70, 0.85); stroke-width: 1.5;
  cursor: not-allowed;
}
.hl-offside:hover { fill: rgba(214, 60, 40, 0.6); }
/* tight-angle warning bands: mild, permanent, never in the way */
.hl-angle { stroke: none; pointer-events: none; }

/* out-of-bounds ring */
.oob-seg {
  fill: rgba(24, 14, 6, 0.45); stroke: rgba(240, 230, 205, 0.15); stroke-width: 1;
}
body.view3d .oob-seg { fill: rgba(20, 11, 4, 0.5); }
.oob-seg.oob-open {
  fill: rgba(96, 178, 70, 0.4); stroke: var(--accent); stroke-width: 1.5;
  cursor: pointer; animation: pulse 1.2s ease-in-out infinite;
}
.oob-seg.oob-open:hover { fill: rgba(96, 178, 70, 0.65); }
.hl-pass:hover { stroke: rgba(255, 255, 255, 0.6); stroke-width: 2; }
.hl-tn { fill: rgba(255, 233, 176, 0.9); font-size: 10px; text-anchor: end; pointer-events: none; }

.target-ghost { opacity: 0.5; pointer-events: none; }
.target-ghost.team-home { fill: none; stroke: var(--home); stroke-width: 2; }
.target-ghost.team-away { fill: none; stroke: var(--away); stroke-width: 2; }

/* hover path preview */
.layer-path { pointer-events: none; }
.path-line {
  fill: none; stroke: #fff; stroke-width: 3; stroke-dasharray: 7 5;
  stroke-linejoin: round; opacity: 0.9;
}
.path-dot { fill: #fff; opacity: 0.9; }
.path-count {
  fill: #fff; font-size: 11px; font-weight: 800; text-anchor: middle;
  paint-order: stroke; stroke: rgba(0, 0, 0, 0.7); stroke-width: 3px;
}
.path-count-final { font-size: 14px; fill: var(--accent); }
.path-challenge path { fill: var(--accent); stroke: rgba(0,0,0,0.6); stroke-width: 0.8; }
.path-challenge-mark {
  fill: #201700; font-size: 13px; font-weight: 900; text-anchor: middle;
}

.drift-arrow { stroke-width: 3; opacity: 0.85; pointer-events: none; }
.drift-arrow.team-home { stroke: #ffb3ad; }
.drift-arrow.team-away { stroke: #a9c4ff; }
.arrowhead { fill: #fff; }

/* action ring */
.ring-item { cursor: pointer; }
.ring-item rect {
  fill: rgba(10, 20, 12, 0.92); stroke: var(--accent); stroke-width: 1.5;
}
.ring-item:hover rect { fill: rgba(45, 38, 12, 0.95); }
.ring-item.ring-disabled rect { stroke: #555; }
.ring-label {
  fill: var(--text); font-size: 12px; font-weight: 800; text-anchor: middle;
  pointer-events: none;
}
.ring-sub { fill: var(--accent); font-size: 9px; text-anchor: middle; pointer-events: none; }

/* stats card */
.stats-box { pointer-events: none; }
.stats-bg { fill: rgba(8, 16, 10, 0.94); stroke: rgba(255,255,255,0.35); stroke-width: 1; }
.stats-box.team-home .stats-head { fill: var(--home); }
.stats-box.team-away .stats-head { fill: var(--away); }
.stats-name { fill: #fff; font-size: 11px; font-weight: 800; }
.stats-line { fill: var(--text); font-size: 12px; }

@keyframes pulse { 50% { opacity: 0.55; } }

/* ---------------- Banner ---------------- */
#banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(0.8);
  font-size: 2rem; font-weight: 900; padding: 12px 26px; border-radius: 16px;
  background: rgba(10, 20, 12, 0.88); border: 2px solid var(--accent);
  opacity: 0; pointer-events: none; transition: all 0.25s ease; white-space: nowrap;
  z-index: 5;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner.goal { color: var(--accent); border-color: var(--accent); }
#banner.save { color: #9fe0b0; border-color: #9fe0b0; }
#banner.team-home { color: var(--home); border-color: var(--home); }
#banner.team-away { color: var(--away); border-color: var(--away); }

/* ---------------- Dice cinematic overlay ---------------- */
#dice-overlay {
  position: absolute; inset: 0; display: none;
  align-items: center; justify-content: center; z-index: 6;
  background: rgba(5, 10, 6, 0.45);
}
#dice-overlay.visible { display: flex; }
.do-box {
  background: rgba(8, 16, 10, 0.96); border-radius: 18px; padding: 18px 30px;
  text-align: center; border-top: 5px solid transparent; min-width: 250px;
  animation: tray-in 0.2s ease;
}
.do-box.team-home { border-top-color: var(--home); }
.do-box.team-away { border-top-color: var(--away); }
.do-title { font-weight: 900; font-size: 1.15rem; letter-spacing: 0.04em; }
.do-target { font-size: 1rem; color: var(--muted); margin-top: 4px; }
.do-target b { font-size: 1.9rem; color: var(--accent); }
.do-math { font-size: 0.75rem; color: var(--muted); }
.do-opp { margin-top: 6px; font-size: 0.8rem; color: var(--muted);
  display: flex; gap: 5px; align-items: center; justify-content: center; }
.do-opp .die { width: 18px; height: 18px; }
.do-dice { display: flex; gap: 12px; justify-content: center; margin: 14px 0 4px; }
.do-dice .die { width: 44px; height: 44px; border-radius: 9px; }
.do-dice .die .pip { width: 8px; height: 8px; }
.do-dice .die.rolling { animation: tumble 0.25s linear infinite; }
@keyframes tumble {
  0% { transform: rotate(-7deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-3px); }
  100% { transform: rotate(-7deg) translateY(0); }
}
.do-mod { font-size: 0.85rem; color: var(--text); }
.do-result { min-height: 30px; font-size: 1.1rem; margin-top: 6px; opacity: 0; }
.do-result.shown { opacity: 1; transition: opacity 0.15s ease; }
.do-result b { font-size: 1.5rem; }
.do-result .ok { color: #7fe09a; font-weight: 900; }
.do-result .no { color: #e08a7f; font-weight: 900; }
.do-result .mid { color: var(--accent); font-weight: 900; }

/* ---------------- Bottom panel ---------------- */
#panel {
  background: var(--panel);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}

#panel-top { display: flex; align-items: center; gap: 10px; min-height: 34px; }
#hint-bar { flex: 1; min-width: 0; }
.chip-hint { color: var(--accent); font-size: 0.78rem; }

#actions { display: flex; gap: 6px; flex: none; }
#actions button { padding: 6px 12px; font-weight: 700; font-size: 0.85rem; }
#btn-end { padding: 6px 16px; }

#log {
  height: 64px; overflow-y: auto; font-size: 0.75rem; line-height: 1.45;
  background: var(--bg); border-radius: 8px; padding: 6px 8px; color: var(--muted);
}
.log-entry.team-home { border-left: 3px solid var(--home); padding-left: 6px; }
.log-entry.team-away { border-left: 3px solid var(--away); padding-left: 6px; }
.log-turn { color: #5e7263; font-size: 0.68rem; }
.log-goal, .log-score { color: var(--accent); font-weight: 700; }
.log-save { color: #9fe0b0; }
.log-dice { font-size: 0.95rem; }

/* ---------------- Dice tray (compact history) ---------------- */
#dice-tray {
  position: absolute; top: 8px; left: 8px; z-index: 4;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.tray-roll {
  display: flex; align-items: center; gap: 7px;
  background: rgba(8, 16, 10, 0.88); border-radius: 10px; padding: 5px 9px;
  border-left: 4px solid transparent; font-size: 0.8rem;
  animation: tray-in 0.25s ease;
}
.tray-roll.team-home { border-left-color: var(--home); }
.tray-roll.team-away { border-left-color: var(--away); }
.tray-roll:nth-child(2) { opacity: 0.6; transform: scale(0.92); transform-origin: top left; }
.tray-roll:nth-child(3) { opacity: 0.35; transform: scale(0.85); transform-origin: top left; }
@keyframes tray-in { from { opacity: 0; transform: translateY(-6px); } }
.tray-label { font-weight: 700; min-width: 58px; }
.tray-math { color: var(--muted); }
.tray-math b { color: var(--text); font-size: 0.95rem; }
.tray-result { font-weight: 900; }
.tray-result.ok { color: #7fe09a; }
.tray-result.no { color: #e08a7f; }

.die {
  position: relative; display: inline-block; width: 22px; height: 22px;
  background: #f5f2ea; border-radius: 5px; box-shadow: inset 0 -2px 0 rgba(0,0,0,0.2);
}
.pip {
  position: absolute; width: 5px; height: 5px; border-radius: 50%;
  background: #222; transform: translate(-50%, -50%);
}

/* ---------------- Modals ---------------- */
.modal {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(5, 10, 6, 0.82); z-index: 10; padding: 16px;
}
.modal.visible { display: flex; }
.modal-box {
  background: var(--panel-2); border: 1px solid #3a5c44; border-radius: 16px;
  padding: 20px; width: min(460px, 94vw); max-height: 86vh; overflow-y: auto;
}
.modal-box h2 { margin-bottom: 8px; }
.modal-box h2.team-home { color: var(--home); }
.modal-box h2.team-away { color: var(--away); }
.modal-box p { margin-bottom: 12px; color: var(--muted); }
.final-score { font-size: 1.5rem; font-weight: 800; color: var(--text) !important; }

.formation-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; font-size: 0.72rem; line-height: 1.1; border-radius: 8px;
}
.card b { font-size: 0.95rem; }
.card span { color: var(--muted); }
.card-active { border-color: var(--accent); background: #2b2413; }
.card-active span { color: var(--accent); }

.mini-pitch { width: 100%; max-width: 84px; }
.mini-field { fill: #1c4a26; stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; }
.mini-line { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; }
.card-home .mini-dot, .team-panel-home .mini-dot { fill: var(--home); }
.card-away .mini-dot, .team-panel-away .mini-dot { fill: var(--away); }
.formation-grid.card-home .mini-dot { fill: var(--home); }
.formation-grid.card-away .mini-dot { fill: var(--away); }
.mini-gk { fill: var(--accent); }

.overlay-buttons { display: flex; gap: 10px; }
.overlay-buttons button { flex: 1; padding: 12px; }

.help-box h3 { margin: 10px 0 4px; color: var(--accent); font-size: 0.95rem; }
.help-box li { margin: 0 0 6px 18px; color: var(--muted); }
.help-box .help-paper { margin-top: 12px; }
#help-close { width: 100%; margin-top: 8px; }

/* Narrow screens: team panels become a row above the board */
@media (max-width: 760px) {
  #match-body {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
  }
  .team-panel { flex-direction: row; flex-wrap: wrap; justify-content: space-between; padding: 6px 10px; }
  .team-panel .tp-card { width: auto; margin-top: 0; }
  .team-panel .mini-pitch { max-width: 56px; }
  #board-wrap { grid-column: 1 / -1; }
}

.chip-ability { color: var(--accent); font-size: 0.78rem; font-weight: 700; }

.stats-ability { fill: var(--accent); font-size: 11px; font-weight: 700; }
