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

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #23263a;
  --border:      #2e3250;
  --text:        #e8eaf6;
  --text-muted:  #7b82b0;
  --accent:      #4e9af1;
  --success:     #57cc99;
  --danger:      #ef4444;
  --warning:     #f4a261;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.5);
  --timer-dur:   15s;

  /* map colors */
  --map-land:       #2e3450;
  --map-border:     #1a1d27;
  --map-ocean:      #141726;
  --map-hover:      #5a6aab;
  --map-correct:    #57cc99;
  --map-wrong:      #ef4444;
  --map-highlight:  #3b5bdb;
  --map-found:      #2a9d8f;
}

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

/* ===== SCREENS ===== */
.screen { display: none; width: 100vw; height: 100vh; overflow: auto; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* ===== START SCREEN ===== */
.start-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 48px;
  width: min(700px, 96vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.start-card h1 {
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.5px;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
  margin-top: -16px;
}

.setup-grid { display: flex; flex-direction: column; gap: 20px; }

.setup-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* choice button groups */
.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-choice {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: .88rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-choice:hover { border-color: var(--accent); color: var(--text); }
.btn-choice.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* mode cards */
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.mode-card:hover { border-color: var(--accent); color: var(--text); }
.mode-card.active { border-color: var(--accent); background: rgba(78,154,241,.12); color: var(--text); }

.mode-icon  { font-size: 1.4rem; }
.mode-name  { font-weight: 700; font-size: .9rem; }
.mode-desc  { font-size: .75rem; line-height: 1.3; }

/* primary / secondary buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  align-self: center;
}
.btn-primary:hover  { opacity: .88; }
.btn-primary:active { transform: scale(.97); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s;
}
.btn-secondary:hover { border-color: var(--accent); }

/* stats preview on start */
.stats-preview {
  text-align: center;
  font-size: .82rem;
  color: var(--text-muted);
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: .82rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-link:hover { opacity: .8; }

/* ===== GAME SCREEN ===== */
#screen-game {
  display: none;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}
#screen-game.active { display: flex; }

#game-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#question-box {
  font-size: 1.3rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.question-country {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent);
  margin: 0 4px;
}

#game-info {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

/* timer ring */
#timer-wrap {
  position: relative;
  width: 44px;
  height: 44px;
}
#timer-ring { width: 44px; height: 44px; }
#timer-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
}

#progress-box { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#progress-text { font-size: .8rem; color: var(--text-muted); }
#progress-bar-wrap { width: 80px; height: 5px; background: var(--surface2); border-radius: 999px; overflow: hidden; }
#progress-bar { height: 100%; background: var(--accent); transition: width .3s; border-radius: 999px; }

#score-box {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-size: 1.1rem;
  font-weight: 700;
}
.score-label { font-size: .75rem; color: var(--text-muted); margin-right: 4px; font-weight: 400; }
#score-correct { color: var(--success); }
.score-sep { color: var(--text-muted); margin: 0 1px; }
#score-total { color: var(--text-muted); }

.btn-quit {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
  transition: border-color .15s, color .15s;
}
.btn-quit:hover { border-color: var(--danger); color: var(--danger); }

/* map */
#map-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#world-map {
  width: 100%;
  height: 100%;
  background: var(--map-ocean);
}

.country-path {
  fill: var(--map-land);
  stroke: var(--map-border);
  stroke-width: .5px;
  cursor: pointer;
  transition: fill .2s;
}
.country-path:hover          { fill: var(--map-hover); }
.country-path.highlight      { fill: var(--map-highlight); }
.country-path.found          { fill: var(--map-found); }
.country-path.correct-flash  { fill: var(--map-correct); }
.country-path.wrong-flash    { fill: var(--map-wrong); }
.country-path.disabled       { cursor: default; pointer-events: none; }

/* Mikrostaat-Marker */
.micro-marker {
  fill: var(--map-land);
  stroke: var(--accent);
  cursor: pointer;
  transition: fill .2s;
}
.micro-marker:hover         { fill: var(--map-hover); }
.micro-marker.highlight     { fill: var(--map-highlight); stroke: #7ca8f5; }
.micro-marker.found         { fill: var(--map-found); stroke: #4db89a; }
.micro-marker.correct-flash { fill: var(--map-correct); }
.micro-marker.wrong-flash   { fill: var(--map-wrong); }
.micro-marker.disabled      { cursor: default; pointer-events: none; }

/* toast feedback */
.toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1rem;
  pointer-events: none;
  transition: opacity .3s;
  z-index: 20;
}
.toast.correct { background: var(--success); color: #fff; }
.toast.wrong   { background: var(--danger);  color: #fff; }
.toast.timeout { background: var(--warning); color: #fff; }
.toast.hidden  { opacity: 0; }

/* tooltip */
.tooltip {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .8rem;
  pointer-events: none;
  z-index: 30;
  white-space: nowrap;
  box-shadow: var(--shadow);
}
.tooltip.hidden { display: none; }

/* ===== RESULT SCREEN ===== */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 48px;
  width: min(500px, 94vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.result-emoji { font-size: 3.5rem; }
.result-card h2 { font-size: 1.8rem; font-weight: 700; }
.result-summary { color: var(--text-muted); text-align: center; font-size: 1rem; }

.result-details {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: .88rem;
}
.result-row.correct-row { background: rgba(87,204,153,.1); }
.result-row.wrong-row   { background: rgba(239,68,68,.1); }
.result-row .ri { font-size: 1rem; }
.result-row .rn { flex: 1; }
.result-row .rt { color: var(--text-muted); font-size: .8rem; }

.result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ===== STATS SCREEN ===== */
#screen-stats { align-items: flex-start; justify-content: center; padding: 20px; }

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  width: min(800px, 98vw);
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}

.stats-header { display: flex; align-items: center; justify-content: space-between; }
.stats-header h2 { font-size: 1.4rem; font-weight: 700; }

.stats-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.stats-search-input {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 6px 16px;
  color: var(--text);
  font-size: .88rem;
  outline: none;
  min-width: 160px;
}
.stats-search-input:focus { border-color: var(--accent); }

#stats-table-wrap { overflow-y: auto; max-height: 60vh; }

#stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

#stats-table th, #stats-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

#stats-table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { color: var(--text); }
.sortable.active { color: var(--accent); }

#stats-table tbody tr:hover td { background: var(--surface2); }

.pct-bar-wrap { display: flex; align-items: center; gap: 8px; }
.pct-bar { flex: 1; height: 6px; background: var(--surface2); border-radius: 999px; overflow: hidden; min-width: 60px; }
.pct-bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.pct-label { width: 38px; text-align: right; font-variant-numeric: tabular-nums; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .start-card, .result-card { padding: 24px 18px; }
  .mode-cards { grid-template-columns: 1fr; }
  #question-box { font-size: 1rem; }
  .question-country { font-size: 1.1rem; }
  #game-info { gap: 8px; }
  #progress-box { display: none; }
}
