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

:root {
  --bg: #0f1923;
  --surface: #1a2535;
  --surface2: #223040;
  --accent: #3ecfcf;
  --accent2: #f97316;
  --text: #e8f0f7;
  --muted: #7a9ab5;
  --border: #2a3f55;
  --correct: #4ade80;
  --incorrect: #f87171;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

#start-screen {
  justify-content: flex-start;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.screen { display: none; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.screen.active { display: flex; }

.back-link {
  position: absolute; top: 20px; left: 24px;
  color: var(--muted); text-decoration: none; font-size: 0.9rem;
  transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

.how-to {
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  margin-top: 20px;
  background: var(--panel);
  max-width: 520px;
  width: 100%;
  text-align: left;
}

.how-to-summary {
  display: block;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.how-to-summary::-webkit-details-marker { display: none; }
.how-to-summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
}
details.how-to[open] > .how-to-summary::before { transform: rotate(90deg); }
.how-to-summary:hover { color: var(--text); }

.how-to-body { padding: 0 16px 12px; }
.how-to-body p {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 10px;
}
.how-to-body p:last-child { margin-bottom: 0; }
.how-to-body strong { color: var(--text); }

h1 { font-size: 2.4rem; font-weight: 800; margin-bottom: 8px; }
.subtitle { color: var(--muted); margin-bottom: 32px; text-align: center; max-width: 460px; line-height: 1.5; }

.option-group { margin-bottom: 20px; text-align: center; }
.option-label { display: block; font-size: 0.75rem; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.option-row { display: flex; gap: 8px; margin-bottom: 10px; }
.option-btn {
  padding: 10px 22px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.option-btn:hover { border-color: var(--accent); }
.option-btn.selected { background: rgba(62,207,207,0.15); border-color: var(--accent); color: var(--accent); }

.diff-desc { font-size: 0.82rem; color: var(--muted); font-style: italic; }

.country-select {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 36px 10px 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a9ab5' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: border-color 0.15s;
}
.country-select:hover, .country-select:focus { border-color: var(--accent); outline: none; }
.option-row { flex-wrap: wrap; }


.controls-info {
  margin-bottom: 28px; text-align: center; color: var(--muted); font-size: 0.85rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 20px;
}
.controls-info b { color: var(--accent); }

.primary-btn {
  padding: 14px 48px; border-radius: 12px; border: none;
  background: var(--accent); color: var(--bg); font-size: 1.1rem; font-weight: 700;
  cursor: pointer; transition: transform 0.12s, box-shadow 0.12s;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(62,207,207,0.3); }

/* ── HUD ── */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px;
  background: rgba(15,25,35,0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 0.95rem;
}

#country-label-hud {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  z-index: 100; font-size: 1.1rem; font-weight: 700; color: var(--accent);
  background: rgba(15,25,35,0.9); padding: 6px 20px; border-radius: 8px;
  border: 1px solid var(--border); pointer-events: none;
  transition: opacity 0.2s;
}
#country-label-hud:empty { opacity: 0; }

/* ── Canvas ── */
#game-canvas {
  position: fixed; inset: 0; top: 48px;
  width: 100%; height: calc(100vh - 48px);
}

/* ── Feedback ── */
.feedback-banner {
  position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%);
  padding: 12px 28px; border-radius: 12px; font-weight: 700; font-size: 1.05rem;
  z-index: 200; opacity: 0; transition: opacity 0.25s;
  pointer-events: none;
}
.feedback-banner.show { opacity: 1; }
.feedback-banner.correct { background: rgba(78,222,128,0.15); color: var(--correct); border: 1px solid var(--correct); }
.feedback-banner.incorrect { background: rgba(248,113,113,0.15); color: var(--incorrect); border: 1px solid var(--incorrect); }

/* ── Duels ── */
.hidden { display: none !important; }

.duel-hud {
  display: flex; align-items: center; gap: 10px;
}
.duel-player-chip {
  display: flex; flex-direction: column; align-items: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 12px; min-width: 70px;
  opacity: 0.5; transition: opacity 0.2s, background 0.2s;
}
.duel-player-chip.active {
  background: var(--accent); opacity: 1; color: #000;
  border-color: var(--accent);
}
.duel-player-name { font-size: 0.7rem; font-weight: 600; white-space: nowrap; overflow: hidden; max-width: 90px; text-overflow: ellipsis; }
.duel-player-score { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.duel-vs { font-size: 0.8rem; color: var(--muted); font-weight: 600; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10,18,28,0.85); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem 2.5rem; max-width: 380px; width: 90%;
  text-align: center;
}
.modal-box h2 { margin-bottom: 1rem; }
.modal-box ul { padding-left: 1.2rem; color: var(--text); font-size: 0.95rem; }
.player-name-input {
  width: 100%; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 1rem; font-family: inherit;
  text-align: center; outline: none;
}
.player-name-input:focus { border-color: var(--accent); }

/* Pass overlay */
.pass-overlay {
  position: fixed; inset: 0; z-index: 600;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.pass-box { text-align: center; padding: 2rem; }
.pass-emoji { font-size: 3.5rem; margin-bottom: 0.5rem; }
.pass-box h2 { font-size: 2rem; margin-bottom: 0.5rem; }
.pass-sub { color: var(--muted); margin-bottom: 2rem; }

/* P2 chip is orange in duel mode */
#dhud-p1.active { background: var(--accent2); border-color: var(--accent2); }

/* ── Results ── */
.final-score {
  font-size: 3rem; font-weight: 800; margin: 16px 0 24px;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.results-list {
  max-width: 400px; width: 100%; max-height: 50vh; overflow-y: auto;
  margin-bottom: 24px;
}

.result-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.result-row .r-name { font-weight: 600; }
.result-row .r-status { font-weight: 700; }
.result-row .r-status.ok { color: var(--correct); }
.result-row .r-status.fail { color: var(--incorrect); }
