/* ================================================
   RESET & VARIABLES
================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

:root {
  --col-yellow: #FFD700;
  --col-blue: #5B8DEF;
  --col-white: #D8D8D8;
  --col-green: #4CAF50;
  --col-red: #E53935;
  --col-purple: #9B59B6;

  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-card: #21262d;
  --bg-card2: #2d333b;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #388bfd;
  --accent-hover: #4f9bfd;
  --positive: #3fb950;
  --negative: #f85149;

  --radius-sm: 5px;
  --radius: 10px;
  --radius-lg: 16px;
  --ease: 0.15s ease;
}

/* ================================================
   BASE
================================================ */
html {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ================================================
   SCREEN SYSTEM
================================================ */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
}

/* ================================================
   BUTTONS
================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background var(--ease), border-color var(--ease), opacity var(--ease);
  white-space: nowrap;
  line-height: 1.3;
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn-sub {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.75;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:not(:disabled):hover {
  background: var(--bg-card);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  font-size: 0.8rem;
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 0.975rem;
  border-radius: var(--radius);
  width: 100%;
}

/* ================================================
   HOME SCREEN
================================================ */
#screen-home {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
  background: radial-gradient(ellipse at 50% 0%, #1c2d52 0%, var(--bg) 65%);
}

.home-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 340px;
  width: 100%;
  gap: 0;
}

.home-exp-dots {
  display: flex;
  gap: 7px;
  margin-bottom: 1.25rem;
}

.home-exp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.home-icon {
  font-size: 3rem;
  margin-bottom: 0.4rem;
  line-height: 1;
}

.home-title {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #FFD700 0%, #E53935 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.2rem;
}

.home-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2.25rem;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

.home-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

/* ================================================
   SETUP SCREEN
================================================ */
#screen-setup {
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.setup-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.setup-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.setup-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.75rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.form-group input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.575rem 0.825rem;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--ease);
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.setup-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

/* ================================================
   ROUND SCREEN — FIXED VIEWPORT HEIGHT
   Lock to screen height so card columns stretch to fill
================================================ */
#screen-round {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

#panels-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ================================================
   ROUND SCREEN — TOP BAR
================================================ */
.round-topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.625rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.round-topbar-left .round-name {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
}

.round-topbar-left .round-of {
  font-size: 0.73rem;
  color: var(--text-muted);
  line-height: 1;
}

.round-pips {
  display: flex;
  gap: 5px;
}

.round-pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  transition: background var(--ease);
}

.round-pip.done {
  background: var(--accent);
}

.round-pip.current {
  background: var(--text);
}

/* ================================================
   ROUND SCREEN — PLAYER PANELS (stacked vertically)
================================================ */
.player-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 2px solid var(--border);
}

.player-panel:last-child {
  border-bottom: none;
}

.panel-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.panel-name {
  font-weight: 700;
  font-size: 0.9rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel-total-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.panel-total-score {
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 44px;
  text-align: right;
}

.btn-invert {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
  flex-shrink: 0;
}

.btn-invert:hover {
  background: var(--bg-card);
  color: var(--text);
}

.btn-invert.active {
  background: var(--bg-card2);
  color: var(--text);
  border-color: var(--text-muted);
}

/* ================================================
   EXPEDITION GRID
   6 columns (one per expedition), cards stacked vertically
================================================ */
.exp-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 4px;
  padding: 6px;
  align-items: flex-start;
  overflow-y: auto;
}

.exp-grid.inverted {
  flex-direction: row-reverse;
}

.exp-col {
  flex: 1;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* --exp-color set inline by JS */
}

/* Coloured header band */
.exp-col-header {
  background: var(--exp-color, #888);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  font-weight: 800;
  color: #0d1117;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

/* White expedition: use dark text since bg is light */
.exp-col.exp-white .exp-col-header {
  color: #1a1a1a;
}

/* Shared card base styles */
.game-card {
  flex: 1;
  min-height: 50px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1.5px solid color-mix(in srgb, var(--exp-color, #888) 40%, var(--border));
  background: transparent;
  color: color-mix(in srgb, var(--exp-color, #888) 70%, var(--text));
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
  overflow: hidden;
  font-size: clamp(8px, 1.8cqh, 13px);
}

.game-card:hover {
  border-color: var(--exp-color, #888);
  background: color-mix(in srgb, var(--exp-color, #888) 18%, transparent);
}

.game-card.on {
  background: var(--exp-color, #888);
  border-color: var(--exp-color, #888);
  color: #0d1117;
}

/* White expedition on dark bg: keep text readable */
.exp-col.exp-white .game-card {
  border-color: color-mix(in srgb, var(--exp-color) 60%, var(--border));
  color: var(--col-white);
}

.exp-col.exp-white .game-card.on {
  color: #1a1a1a;
}

/* Wager cards: dashed border when empty */
.wager-card {
  border-style: dashed;
  opacity: 0.8;
}

.wager-card.on {
  border-style: solid;
  opacity: 1;
}

/* Expedition score chip at bottom of column */
.exp-col-score {
  flex-shrink: 0;
  height: 22px;
  line-height: 22px;
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
  color: var(--text-muted);
}

.exp-col-score.pos {
  color: var(--positive);
}

.exp-col-score.neg {
  color: var(--negative);
}

/* ================================================
   ROUND FOOTER
================================================ */
.round-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  position: sticky;
  bottom: 0;
  z-index: 20;
}

/* ================================================
   ROUND SUMMARY SCREEN
================================================ */
#screen-round-summary {
  align-items: center;
  padding: 1.25rem 1rem;
}

.summary-inner {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.summary-head h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.summary-head p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.score-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.score-table th {
  background: var(--bg-card2);
  padding: 0.55rem 0.875rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.score-table th:not(:first-child) {
  text-align: right;
}

.score-table td {
  padding: 0.45rem 0.875rem;
  border-bottom: 1px solid var(--border);
}

.score-table td:not(:first-child) {
  text-align: right;
  font-weight: 600;
}

.score-table tbody tr:last-child td {
  border-bottom: none;
}

.row-sep td {
  border-top: 2px solid var(--border);
  background: var(--bg-card);
  font-weight: 700;
  font-size: 0.9rem;
}

.row-running td {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
}

.exp-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.sc-pos {
  color: var(--positive);
}

.sc-neg {
  color: var(--negative);
}

.sc-zer {
  color: var(--text-muted);
}

.summary-footer {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ================================================
   GAME OVER SCREEN
================================================ */
#screen-game-over {
  align-items: center;
  padding: 1.25rem 1rem;
}

.gameover-inner {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.winner-card {
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
}

.winner-card.tie {
  background: color-mix(in srgb, #FFD700 10%, var(--bg-surface));
  border-color: color-mix(in srgb, #FFD700 35%, transparent);
}

.winner-trophy {
  font-size: 2.5rem;
  margin-bottom: 0.4rem;
  line-height: 1;
}

.winner-name {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 0.2rem;
}

.winner-detail {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.final-table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.final-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.final-table th {
  background: var(--bg-card2);
  padding: 0.55rem 0.875rem;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.final-table th:not(:first-child) {
  text-align: right;
}

.final-table td {
  padding: 0.55rem 0.875rem;
  border-bottom: 1px solid var(--border);
}

.final-table td:not(:first-child) {
  text-align: right;
  font-weight: 600;
}

.final-table tbody tr:last-child td {
  border-bottom: none;
}

.final-table .grand-row td {
  background: var(--bg-card);
  font-weight: 800;
  font-size: 1rem;
  border-top: 2px solid var(--border);
}

.is-winner {
  color: var(--accent);
}

.gameover-footer {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ================================================
   MODE TOGGLE (Player Score / Game Score)
================================================ */
.mode-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
  margin-bottom: 1.5rem;
}

.mode-opt {
  flex: 1;
  cursor: pointer;
  position: relative;
}

.mode-opt input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.mode-opt span {
  display: block;
  text-align: center;
  padding: 0.45rem 0.5rem;
  border-radius: calc(var(--radius-sm) - 1px);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: background var(--ease), color var(--ease);
  user-select: none;
}

.mode-opt input:checked + span {
  background: var(--accent);
  color: #fff;
}

/* Hide P2 input when Player Score mode is selected */
.setup-card:has(input[name="game-mode"][value="player"]:checked) .form-group-p2 {
  display: none;
}

/* ================================================
   FONT SCALING: card font scales with actual rendered width
   using container queries if supported, else small override
================================================ */
@container (max-width: 52px) {
  .num-card {
    font-size: 0.72em;
  }

  .wager-card {
    font-size: 0.6em;
  }
}

/* ================================================
   RESPONSIVE
================================================ */
@media (max-width: 360px) {
  .exp-grid {
    gap: 3px;
    padding: 4px;
  }

  .exp-col {
    gap: 2px;
  }
}
