:root {
  --ice: #eef4fb;
  --ice-2: #dce9f7;
  --ink: #142a42;
  --ink-soft: #56708c;
  --paper: #ffffff;
  --red: #d64545;
  --red-dark: #b53434;
  --red-light: #f6c9c9;
  --correct: #4caf7d;
  --wrong: #e2596b;
  --shadow: rgba(20, 42, 66, 0.16);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 4%, rgba(214,69,69,0.10), transparent 45%),
    radial-gradient(circle at 90% 96%, rgba(20,42,66,0.08), transparent 45%),
    var(--ice);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
}

.hidden { display: none !important; }

/* Background image behind the start screen only — a fixed, full-viewport
   pseudo-element so it fills the browser window regardless of the panel's
   own narrow width. Naturally disappears when #startScreen gets .hidden,
   since pseudo-elements don't render on display:none elements. If the
   image file doesn't exist yet, this just renders transparent and the
   body's existing gradient shows through underneath — no broken look. */
#startScreen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(rgba(238,244,251,0.22), rgba(238,244,251,0.22)),
    url('images/background.png');
  background-size: cover;
  background-position: center 15%;
}
#startScreen { padding-top: 100px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 20px; max-width: 720px; margin: 0 auto;
}
.back-link { color: var(--ink-soft); text-decoration: none; font-weight: 600; font-size: 14px; }
.back-link:hover { color: var(--ink); }
.brand { font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.stats { display: flex; align-items: center; gap: 14px; }
.lives { display: flex; gap: 4px; font-size: 18px; }
.lives .lost { opacity: 0.25; filter: grayscale(1); }
.score {
  font-family: 'Space Mono', monospace; font-weight: 700;
  background: #fff; border: 1px solid var(--ice-2); border-radius: 999px;
  padding: 4px 12px; font-size: 14px;
}

/* ---------- Panels ---------- */
.panel { max-width: 640px; margin: 0 auto; padding: 20px 20px 60px; }
#playScreen, #standingsScreen { max-width: 800px; }

.start-card {
  background: var(--paper); border-radius: var(--radius); padding: 32px 28px; text-align: center;
  box-shadow: 0 18px 40px -20px var(--shadow); border: 1px solid var(--ice-2);
}
.tag {
  display: inline-block; font-family: 'Space Mono', monospace; font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--red-dark);
  background: rgba(214,69,69,0.12); border-radius: 999px; padding: 4px 12px; margin-bottom: 14px;
}
.start-card h1 { font-family: 'Baloo 2', sans-serif; font-size: clamp(28px, 5vw, 38px); margin: 0 0 14px; }
.start-card p { color: var(--ink-soft); line-height: 1.6; font-size: 15px; max-width: 48ch; margin: 0 auto 18px; }
.example {
  background: var(--ice-2); border-radius: 12px; padding: 14px 18px;
  margin: 0 auto 22px; max-width: 44ch; text-align: left;
}
.example-label { font-family: 'Space Mono', monospace; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--red-dark); }
.example p { margin: 6px 0 0; font-size: 14px; color: var(--ink); }

.primary-btn {
  font-family: 'Inter', sans-serif; font-weight: 700; font-size: 16px; color: #fff;
  background: linear-gradient(180deg, var(--red), var(--red-dark)); border: none;
  border-radius: 14px; padding: 14px 30px; cursor: pointer;
  box-shadow: 0 10px 20px -8px rgba(181,52,52,0.5);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.primary-btn:hover:not(:disabled) { transform: translateY(-2px); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.primary-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.secondary-btn {
  display: inline-block; font-weight: 600; font-size: 15px; color: var(--ink-soft);
  text-decoration: none; padding: 14px 22px; border-radius: 14px; border: 1px solid var(--ice-2);
}
.secondary-btn:hover { border-color: var(--ink-soft); }
.hint { margin-top: 18px; font-size: 13px; color: var(--ink-soft); }

.mode-choice {
  display: flex; gap: 12px; justify-content: center; margin-bottom: 4px; flex-wrap: wrap;
}
.mode-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; min-width: 160px;
}
.mode-sub {
  font-family: 'Inter', sans-serif; font-weight: 500; font-size: 12px; opacity: 0.85;
}

.badges-link { margin-top: 14px; }

.badge-list {
  display: flex; flex-direction: column; gap: 10px;
  margin: 0 auto 22px; max-width: 46ch; text-align: left;
}
.badge-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--ice-2); background: var(--ice);
}
.badge-item.unlocked { background: rgba(76,175,125,0.12); border-color: var(--correct); }
.badge-icon { font-size: 26px; flex: none; opacity: 0.35; }
.badge-item.unlocked .badge-icon { opacity: 1; }
.badge-text { flex: 1; }
.badge-label { font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink); }
.badge-item:not(.unlocked) .badge-label { color: var(--ink-soft); }
.badge-desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.badge-progress {
  font-family: 'Space Mono', monospace; font-size: 12px; font-weight: 700; color: var(--ink-soft); flex: none;
}

.badge-section { margin: 0 auto 18px; max-width: 46ch; text-align: left; }
.badge-section-heading {
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink);
  margin-bottom: 10px; text-align: center;
}
.badge-item.just-unlocked { border-color: var(--red); box-shadow: 0 0 0 2px rgba(214,69,69,0.15); }
.badge-new-tag {
  font-family: 'Space Mono', monospace; font-size: 10px; font-weight: 700; color: #fff;
  background: var(--red); border-radius: 999px; padding: 2px 8px; flex: none;
}

.end-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }

.celebration { display: flex; justify-content: center; gap: 12px; margin-bottom: 10px; }
.celebration.hidden { display: none; }
.celebration span {
  font-size: 32px; opacity: 0; transform: scale(0.3) rotate(-15deg);
  animation: popIn 0.5s ease forwards;
}
@keyframes popIn { to { opacity: 1; transform: scale(1) rotate(0deg); } }

/* ---------- Team select ---------- */
.team-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 4px auto 22px; max-width: 50ch;
}
.team-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--ice); border: 2px solid var(--ice-2); border-radius: 14px;
  padding: 20px 12px; cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease;
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink);
}
.team-card:hover { transform: translateY(-2px); border-color: var(--red); }
.team-card .team-emoji { font-size: 64px; }
.team-logo-wrap {
  width: 128px; height: 128px; display: flex; align-items: center; justify-content: center;
}
.team-logo { width: 100%; height: 100%; object-fit: contain; }
.team-card.selected { border-color: var(--red-dark); background: rgba(214,69,69,0.10); }
.team-card:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* ---------- Roster board (persistent during play) ---------- */
.roster-board {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  margin-bottom: 16px;
}
.roster-slot {
  background: var(--paper); border: 1.5px dashed var(--ice-2); border-radius: 12px;
  padding: 8px 6px; text-align: center; font-size: 11px; color: var(--ink-soft);
  box-shadow: 0 6px 14px -10px var(--shadow);
}
.roster-slot .slot-role {
  font-family: 'Space Mono', monospace; text-transform: uppercase; letter-spacing: 0.04em;
  font-size: 10px; display: block; margin-bottom: 3px;
}
.roster-slot .slot-name { font-weight: 700; font-size: 12px; color: var(--ink); display: block; }
.roster-slot.filled { border-style: solid; border-color: var(--correct); background: rgba(76,175,125,0.08); }
.roster-slot.open .slot-name { color: var(--ink-soft); font-weight: 500; font-style: italic; }

@media (max-width: 480px) {
  .roster-board { grid-template-columns: repeat(4, 1fr); }
  .roster-slot { font-size: 10px; padding: 6px 4px; }
}

/* ---------- Need tag / quirk ---------- */
.need-tag {
  font-family: 'Space Mono', monospace; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--red-dark); margin-bottom: 10px;
}
.player-quirk { font-size: 12.5px; color: var(--ink-soft); font-style: italic; margin-top: 3px; }

/* ---------- Roster recap (end screen) ---------- */
.roster-recap {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
  margin: 0 auto 22px; max-width: 46ch; text-align: left;
}
.roster-recap .recap-slot {
  background: var(--ice-2); border-radius: 10px; padding: 8px 10px; font-size: 12.5px;
}
.roster-recap .recap-slot.filled { background: rgba(76,175,125,0.15); }
.roster-recap .recap-role {
  display: block; font-family: 'Space Mono', monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft);
}
.roster-recap .recap-name { font-weight: 700; color: var(--ink); }

.insight-box {
  background: rgba(20,42,66,0.06); border-left: 3px solid var(--ink-soft); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; color: var(--ink); margin: 4px 0 14px; line-height: 1.5;
}
.measure-choice-block { margin-top: 4px; }

/* ---------- Season tabs ---------- */
.season-tabs {
  display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--ice-2);
}
.tab-btn {
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink-soft);
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: 8px 14px; cursor: pointer; transition: color 0.12s ease, border-color 0.12s ease;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--red-dark); border-bottom-color: var(--red); }
.tab-panel.hidden { display: none; }

/* ---------- Roster stat table ---------- */
.roster-stat-table {
  background: var(--paper); border-radius: var(--radius); padding: 18px 20px;
  box-shadow: 0 14px 30px -18px var(--shadow); border: 1px solid var(--ice-2);
}
.roster-section-heading {
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink);
  margin: 16px 0 6px;
}
.roster-section-heading:first-child { margin-top: 0; }
.roster-stat-row {
  display: grid; gap: 8px; align-items: center;
  padding: 7px 6px; border-bottom: 1px dashed var(--ice-2); font-size: 13px;
}
.roster-stat-row.skater-row { grid-template-columns: 34px 1.3fr 0.5fr 0.5fr 0.5fr 0.55fr; }
.roster-stat-row.goalie-row { grid-template-columns: 34px 1.6fr 0.7fr; }
.roster-stat-row:last-child { border-bottom: none; }
.roster-stat-row.header {
  font-family: 'Space Mono', monospace; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-soft); font-weight: 700;
}
.roster-stat-name { font-weight: 700; color: var(--ink); }
.roster-stat-row span:not(.roster-stat-name) { text-align: center; font-family: 'Space Mono', monospace; }
.roster-avatar-inline { border-radius: 6px; object-fit: cover; flex: none; }
.roster-avatar-fallback { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; font-size: 18px; }

/* ---------- Standings ---------- */
.standings-table {
  margin: 0 auto 18px; max-width: 52ch; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--ice-2);
}
.standings-row {
  display: grid; grid-template-columns: 24px 1.7fr repeat(4, 0.6fr) 0.7fr; gap: 6px; align-items: center;
  padding: 9px 12px; font-size: 12.5px; background: var(--paper); border-bottom: 1px solid var(--ice-2);
}
.standings-row:last-child { border-bottom: none; }
.standings-row.header {
  font-family: 'Space Mono', monospace; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-soft); font-weight: 700; background: var(--ice-2);
}
.standings-row.student-row { background: rgba(76,175,125,0.12); font-weight: 700; }
.standings-rank {
  font-family: 'Space Mono', monospace; font-weight: 700; color: var(--ink-soft); text-align: center;
}
.standings-row.student-row .standings-rank { color: var(--correct); }
.standings-team { text-align: left; }
.standings-row span:not(.standings-team) { text-align: center; font-family: 'Space Mono', monospace; }
.standings-pts { font-weight: 700; }
.standings-row.playoff-line { border-bottom: 2px dashed var(--red); }
.bracket-line {
  font-size: 14px; color: var(--ink); font-weight: 600; margin: 0 auto 20px; max-width: 44ch;
}

/* ---------- Awards recap ---------- */
.awards-recap {
  display: flex; flex-direction: column; gap: 8px;
  margin: 0 auto 18px; max-width: 46ch; text-align: left;
}
.award-row {
  background: rgba(214,69,69,0.08); border-radius: 10px; padding: 10px 14px;
  font-size: 13.5px; display: flex; justify-content: space-between; gap: 10px;
}
.award-label { font-weight: 700; color: var(--red-dark); }
.award-name { color: var(--ink); }

/* ---------- Roster card ---------- */
.roster-card {
  background: var(--paper); border-radius: var(--radius); padding: 20px 22px 22px;
  box-shadow: 0 14px 30px -18px var(--shadow); border: 1px solid var(--ice-2);
}

.card-top {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px dashed var(--ice-2);
}
.team-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: 'Space Mono', monospace; font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--red-dark); background: rgba(214,69,69,0.1);
  border-radius: 999px; padding: 4px 10px;
}
.team-logo-inline { border-radius: 3px; object-fit: contain; flex: none; vertical-align: middle; }
.player-jersey.team-mode img { object-fit: contain; }
.progress-pill { font-family: 'Space Mono', monospace; font-size: 12px; font-weight: 700; color: var(--ink-soft); }

.roster-columns {
  display: grid; grid-template-columns: minmax(200px, 240px) 1fr; gap: 22px;
  align-items: start;
}
.roster-right { display: flex; flex-direction: column; }

/* ---------- Trading card (left column) ---------- */
.roster-left {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--paper); border-radius: 8px; padding: 14px;
  border: 3px solid var(--card-accent, var(--ice-2));
  box-shadow: 4px 4px 0 var(--card-accent, var(--ice-2));
}
.roster-left.pos-forward { --card-accent: #D85A30; --card-accent-bg: #FAECE7; --card-accent-text: #712B13; }
.roster-left.pos-defense { --card-accent: #378ADD; --card-accent-bg: #E6F1FB; --card-accent-text: #0C447C; }
.roster-left.pos-goalie  { --card-accent: #1D9E75; --card-accent-bg: #E1F5EE; --card-accent-text: #085041; }
.roster-left.pos-team    { --card-accent: var(--red); --card-accent-bg: rgba(214,69,69,0.12); --card-accent-text: var(--red-dark); }

.player-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; }

.player-jersey-wrap { position: relative; width: 100%; max-width: 180px; margin: 0 auto; }
.player-jersey {
  font-size: 64px; width: 100%; aspect-ratio: 1 / 1; border-radius: 6px;
  background: var(--card-accent-bg, var(--ice-2)); display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.player-jersey img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.player-team-badge {
  position: absolute; bottom: -6px; right: -6px; width: 34px; height: 34px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--card-accent, var(--ice-2)); object-fit: contain; padding: 3px;
}
.player-team-badge.hidden { display: none; }

.player-name {
  font-family: 'Press Start 2P', monospace; font-size: 11px; line-height: 1.7;
  color: var(--ink); word-break: break-word;
}
.player-badges { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.player-position {
  font-family: 'Space Mono', monospace; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 3px 10px; border-radius: 999px;
  background: var(--card-accent-bg, var(--ice-2)); color: var(--card-accent-text, var(--ink-soft));
}
.player-jersey-number {
  font-family: 'Space Mono', monospace; font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--ice-2); color: var(--ink-soft);
}
.player-jersey-number.hidden { display: none; }

.request-line {
  background: var(--ice-2); border-radius: 12px; padding: 12px 16px;
  font-size: 14.5px; line-height: 1.5; color: var(--ink); margin-bottom: 16px;
}
.request-line strong { color: var(--red-dark); }

.log-grid { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.log-chip {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--ice); border-radius: 8px; padding: 6px 9px; min-width: 30px;
}
.log-chip-label {
  font-family: 'Space Mono', monospace; font-size: 9px; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--ink-soft); font-weight: 700;
}
.log-chip-value { font-weight: 700; font-size: 15px; color: var(--ink); }

.next-btn-left {
  width: 100%; font-size: 14.5px; padding: 12px 14px; margin-top: 4px;
  white-space: normal; line-height: 1.3;
}

@media (max-width: 640px) {
  .roster-columns { grid-template-columns: 1fr; }
}

.stat-question {
  font-family: 'Baloo 2', sans-serif; font-size: 17px; text-align: center; margin: 0 0 12px;
}

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.answer-btn {
  font-family: 'Space Mono', monospace; font-weight: 700; font-size: 16px; color: var(--ink);
  background: var(--ice); border: 2px solid var(--ice-2); border-radius: 14px; padding: 13px 10px;
  cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease;
}
.answer-btn:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--red); }
.answer-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.answer-btn:disabled { cursor: default; }
.answer-btn.wrong-flash { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.answer-btn.locked-correct { background: var(--correct); border-color: var(--correct); color: #fff; }

.decision-block { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--ice-2); }
.decision-line {
  font-family: 'Baloo 2', sans-serif; font-size: 17px; text-align: center; margin: 0 0 14px; color: var(--ink);
}
.decision-line strong { color: var(--red-dark); }

.decision-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 340px; margin: 0 auto; }
.decision-btn {
  font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 18px; color: var(--ink);
  background: var(--ice); border: 2px solid var(--ice-2); border-radius: 14px; padding: 16px 10px;
  cursor: pointer; transition: transform 0.12s ease, border-color 0.12s ease;
}
.decision-btn:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--red); }
.decision-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.decision-btn:disabled { cursor: default; }
.decision-btn.wrong-flash { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.decision-btn.locked-correct { background: var(--correct); border-color: var(--correct); color: #fff; }

.feedback { min-height: 22px; text-align: center; font-weight: 700; margin: 14px 0 4px; font-size: 15px; }
.feedback.good { color: var(--correct); }
.feedback.bad { color: var(--wrong); }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
.shake { animation: shake 0.5s; }

@media (max-width: 480px) {
  .answers { grid-template-columns: 1fr; }
  .decision-answers { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .primary-btn, .answer-btn, .decision-btn { transition: none; }
  .shake { animation: none; }
  .celebration span { animation: none; opacity: 1; transform: none; }
}
