@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --ink: #081218;
  --surface: #101c25;
  --surface-bright: #172833;
  --surface-soft: #1d3340;
  --line: rgba(164, 218, 225, 0.16);
  --line-strong: rgba(164, 218, 225, 0.32);
  --text: #eef7f5;
  --muted: #9bb0b6;
  --cyan: #48d8e6;
  --cyan-deep: #197988;
  --coral: #ff665e;
  --gold: #f1c86a;
  --shadow: rgba(0, 0, 0, 0.36);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  display: flex;
  flex-direction: column;
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Manrope, sans-serif;
  background-color: var(--ink);
  background-image: linear-gradient(rgba(101, 181, 189, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(101, 181, 189, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, [role='button']:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.main-menu { display: grid; flex: 1; min-height: 0; padding: 24px; place-items: center; }
.menu-panel { width: min(100%, 510px); padding: clamp(26px, 6vw, 44px); border: 1px solid var(--line-strong); border-top: 3px solid var(--cyan); border-radius: 8px; background: linear-gradient(145deg, rgba(24, 46, 58, 0.96), rgba(11, 25, 34, 0.98)); box-shadow: 0 28px 62px var(--shadow); }
.menu-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.menu-brand .brand-mark { flex: 0 0 64px; width: 64px; height: 64px; }
.menu-brand h1 { font-size: clamp(1.65rem, 5vw, 2.25rem); line-height: 1; }
.menu-form { display: grid; gap: 18px; }
.form-field { display: grid; gap: 7px; color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.form-field input, .form-field select { width: 100%; height: 46px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--text); background: #0c1a22; font-size: 0.88rem; font-weight: 700; letter-spacing: 0; text-transform: none; }
.form-field select { appearance: auto; }
.menu-message { min-height: 1.35em; margin: -8px 0 0; color: var(--coral); font-size: 0.74rem; font-weight: 700; }
.menu-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; margin-top: 4px; }
.menu-actions .button { min-height: 46px; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  max-width: 1680px;
  margin: 0 auto;
}

.site-footer { flex: 0 0 auto; padding: 9px 16px 12px; color: var(--muted); text-align: center; }
.site-footer small { font-size: 0.68rem; letter-spacing: 0.04em; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px 18px 18px;
  border-right: 1px solid var(--line);
  background: rgba(11, 27, 36, 0.94);
}

.brand { display: flex; align-items: center; gap: 12px; min-height: 84px; }
.brand-mark { width: 70px; height: 70px; color: var(--cyan); filter: drop-shadow(0 0 12px rgba(72, 216, 230, 0.18)); }
.brand-mark svg { display: block; width: 100%; height: 100%; }
.eyebrow, .section-label { margin: 0; color: var(--muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: 'Space Grotesk', sans-serif; font-size: 1.65rem; letter-spacing: 0; }

.place-card, .player-card, .control-section, .sidebar-footer {
  border: 1px solid var(--line);
  background: linear-gradient(135deg, rgba(34, 57, 70, 0.68), rgba(18, 31, 40, 0.8));
  box-shadow: 0 14px 34px var(--shadow);
}

.place-card { padding: 16px; border-left: 3px solid var(--cyan); }
.place-card h2 { margin: 9px 0 3px; font-family: 'Space Grotesk', sans-serif; font-size: 1.28rem; line-height: 1.2; }
.place-card p:last-child { margin-bottom: 0; color: var(--muted); font-size: 0.78rem; }
.player-card { padding: 12px 16px; border-left: 3px solid var(--gold); }
.player-card strong { display: block; margin-top: 6px; overflow: hidden; font-family: 'Space Grotesk', sans-serif; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }

.scoreboard { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.stat-card { min-width: 0; padding: 11px 6px 9px; border: 1px solid var(--line); border-radius: 6px; text-align: center; background: var(--surface-bright); }
.stat-card span { display: block; color: var(--muted); font-size: 0.58rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-card strong { display: block; margin-top: 3px; font-family: 'Space Grotesk', sans-serif; font-size: 1.1rem; }
.stat-card--round { border-bottom: 2px solid var(--cyan); }
.stat-card--streak { border-bottom: 2px solid var(--coral); }
.stat-card--score { border-bottom: 2px solid var(--gold); }

.control-section { padding: 13px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 11px; }
.points-badge { padding: 3px 7px; border: 1px solid rgba(241, 200, 106, 0.35); border-radius: 4px; color: var(--gold); background: rgba(241, 200, 106, 0.1); font-size: 0.68rem; font-weight: 800; }
.grid-controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.grid-button { min-height: 38px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: #13242e; font-size: 0.72rem; font-weight: 800; }
.grid-button:hover:not(:disabled) { border-color: var(--cyan); color: var(--text); }
.grid-button.is-active { border-color: var(--cyan); color: var(--ink); background: var(--cyan); box-shadow: 0 0 15px rgba(72, 216, 230, 0.25); }
.grid-button:disabled { cursor: not-allowed; opacity: 0.45; }

.joker-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.joker-button { display: grid; place-items: center; gap: 4px; min-height: 66px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: #142630; font-size: 0.62rem; font-weight: 800; }
.joker-button:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.joker-button:disabled { cursor: not-allowed; color: #60737b; opacity: 0.55; }
.joker-icon { display: grid; width: 24px; height: 24px; place-items: center; border: 1px solid currentColor; border-radius: 50%; color: var(--gold); font-family: 'Space Grotesk', sans-serif; font-size: 0.68rem; }

.sidebar-footer { display: grid; gap: 7px; margin-top: auto; padding: 12px; }
.sidebar-footer output { display: block; min-height: 36px; margin-bottom: 1px; color: var(--muted); font-size: 0.72rem; line-height: 1.45; }
.text-button { width: 100%; border: 0; color: var(--muted); background: transparent; font-size: 0.72rem; font-weight: 800; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.text-button--leaderboard { color: var(--cyan); }
.text-button--danger { color: var(--coral); }
.text-button:hover { color: var(--text); }

.game-stage { display: flex; min-width: 0; flex-direction: column; padding: 30px clamp(18px, 3vw, 50px); }
.stage-header { display: flex; align-items: end; justify-content: space-between; gap: 16px; max-width: 1200px; width: 100%; margin: 0 auto 20px; }
.stage-header h2 { margin: 4px 0 0; font-family: 'Space Grotesk', sans-serif; font-size: 1.45rem; }
.stage-legend { display: flex; flex-wrap: wrap; justify-content: end; gap: 12px; color: var(--muted); font-size: 0.7rem; }
.stage-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 2px; }
.legend-swatch--selected { border: 2px solid var(--cyan); background: rgba(72, 216, 230, 0.3); }
.legend-swatch--blocked { border: 1px solid var(--coral); background: repeating-linear-gradient(135deg, rgba(255, 102, 94, 0.62) 0 2px, transparent 2px 4px); }

.map-panel { position: relative; width: min(100%, 1180px); margin: auto; padding: 24px 18px 8px; border: 1px solid var(--line); border-radius: 8px; background: rgba(10, 25, 34, 0.72); box-shadow: 0 28px 55px var(--shadow); }
.map-corner { position: absolute; top: 29px; left: 23px; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
#map-svg { display: block; width: 100%; max-height: calc(100vh - 138px); min-height: 480px; }
.map-backdrop { fill: #0b1922; stroke: var(--line-strong); stroke-width: 2; }
.country-reference-map { opacity: 0.92; pointer-events: none; }
.grid-line { stroke: rgba(181, 229, 230, 0.2); stroke-width: 1.4; pointer-events: none; }
.grid-labels { fill: #dcefee; font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 700; pointer-events: none; }
.grid-cell { fill: transparent; stroke: transparent; stroke-width: 2; cursor: crosshair; pointer-events: all; }
.grid-cell:hover:not(.is-blocked) { fill: rgba(72, 216, 230, 0.12); stroke: rgba(72, 216, 230, 0.72); }
.grid-cell.is-selected { fill: rgba(72, 216, 230, 0.28); stroke: var(--cyan); stroke-width: 4; }
.grid-cell.is-blocked { fill: rgba(255, 102, 94, 0.2); stroke: rgba(255, 102, 94, 0.76); cursor: not-allowed; }
.grid-cell.is-blocked + .blocked-cross { pointer-events: none; }
.blocked-cross { stroke: var(--coral); stroke-width: 2.3; opacity: 0.88; pointer-events: none; }
.solution-cell-frame { pointer-events: none; }
.solution-cell-frame__glow { fill: rgba(72, 216, 230, 0.1); stroke: rgba(72, 216, 230, 0.78); stroke-width: 7; filter: drop-shadow(0 0 10px rgba(72, 216, 230, 0.82)); animation: solution-frame-pulse 1.35s ease-in-out infinite; }
.solution-cell-frame__edge { fill: none; stroke: #d7ffff; stroke-width: 2.5; vector-effect: non-scaling-stroke; }
.city-marker { pointer-events: none; }
.city-marker__halo { fill: rgba(255, 102, 94, 0.2); stroke: rgba(255, 102, 94, 0.5); stroke-width: 2; animation: marker-pulse 1.5s ease-out infinite; }
.city-marker__pulse { fill: rgba(255, 102, 94, 0.34); stroke: var(--coral); stroke-width: 3; filter: drop-shadow(0 0 9px var(--coral)); }
.city-marker__core { fill: #fff4ed; stroke: var(--coral); stroke-width: 4; filter: drop-shadow(0 0 8px var(--coral)); }
.resolution-panel { position: absolute; right: 28px; bottom: 42px; z-index: 2; min-width: 220px; padding: 14px; border: 1px solid var(--line-strong); border-left: 4px solid var(--coral); border-radius: 6px; background: rgba(9, 24, 33, 0.94); box-shadow: 0 16px 34px var(--shadow); }
.resolution-panel.is-correct { border-left-color: var(--cyan); }
.resolution-title { margin: 0 0 3px; color: var(--coral); font-family: 'Space Grotesk', sans-serif; font-size: 1.05rem; font-weight: 700; }
.resolution-panel.is-correct .resolution-title { color: var(--cyan); }
.resolution-detail { margin: 0 0 11px; color: var(--muted); font-size: 0.7rem; }
.resolution-panel .button { width: 100%; }
.map-note { margin: 0; padding: 6px 5px 0 45px; color: var(--muted); font-size: 0.7rem; }

@keyframes marker-pulse {
  0% { opacity: 0.85; transform: scale(0.55); transform-origin: center; }
  100% { opacity: 0; transform: scale(1.45); transform-origin: center; }
}

@keyframes solution-frame-pulse {
  0%, 100% { opacity: 0.5; stroke-width: 5; }
  50% { opacity: 1; stroke-width: 12; }
}

.game-dialog { width: min(440px, calc(100vw - 32px)); padding: 28px; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); background: #142630; box-shadow: 0 26px 70px rgba(0, 0, 0, 0.55); }
.game-dialog::backdrop { background: rgba(2, 9, 13, 0.78); }
.game-dialog h2 { margin: 6px 0 10px; font-family: 'Space Grotesk', sans-serif; }
.game-dialog p { color: var(--muted); font-size: 0.88rem; line-height: 1.55; }
.dialog-icon { display: grid; width: 36px; height: 36px; place-items: center; margin-bottom: 14px; border: 1px solid var(--coral); border-radius: 50%; color: var(--coral); font-family: 'Space Grotesk', sans-serif; font-size: 1.2rem; font-weight: 800; }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 20px; }
.button { min-height: 40px; padding: 0 14px; border: 1px solid transparent; border-radius: 5px; font-size: 0.78rem; font-weight: 800; }
.button--primary { color: #061318; background: var(--cyan); }
.button--primary:hover { background: #8cebf0; }
.button--quiet { border-color: var(--line-strong); color: var(--text); background: transparent; }
.button--quiet:hover { border-color: var(--text); }
.leaderboard-dialog { max-height: min(720px, calc(100vh - 32px)); overflow: auto; }
.leaderboard-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.leaderboard-header h2 { margin-bottom: 0; }
.icon-button { display: grid; flex: 0 0 34px; width: 34px; aspect-ratio: 1; padding: 0; place-items: center; border: 1px solid var(--line-strong); border-radius: 5px; color: var(--muted); background: transparent; font-family: 'Space Grotesk', sans-serif; font-size: 1.4rem; line-height: 1; }
.icon-button:hover { border-color: var(--text); color: var(--text); }
.final-score-summary { margin: 20px 0 14px; padding: 11px; border-left: 3px solid var(--gold); color: var(--text) !important; background: rgba(241, 200, 106, 0.08); font-size: 0.78rem !important; font-weight: 700; }
.leaderboard-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 20px 0 12px; padding: 4px; border: 1px solid var(--line); background: rgba(9, 22, 29, 0.55); }
.leaderboard-tab { min-height: 34px; border: 0; border-radius: 3px; color: var(--muted); background: transparent; font-size: 0.72rem; font-weight: 800; }
.leaderboard-tab:hover { color: var(--text); }
.leaderboard-tab.is-active { color: var(--ink); background: var(--cyan); }
.leaderboard-status { margin: 12px 0; color: var(--muted); font-size: 0.78rem !important; }
.empty-leaderboard { margin: 22px 0; color: var(--muted); font-size: 0.8rem !important; }
.leaderboard-list { display: grid; gap: 5px; padding: 0; margin: 20px 0; list-style: none; counter-reset: ranks; }
.leaderboard-list li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto auto; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); background: rgba(9, 22, 29, 0.68); font-size: 0.76rem; }
.leaderboard-list li::before { content: counter(ranks); counter-increment: ranks; color: var(--gold); font-family: 'Space Grotesk', sans-serif; font-weight: 700; }
.leaderboard-list strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard-list span { color: var(--muted); font-size: 0.67rem; }
.leaderboard-list .rank-score { color: var(--cyan); font-family: 'Space Grotesk', sans-serif; font-weight: 700; }
#back-to-menu { width: 100%; }

@media (min-width: 1200px) {
  .main-menu { padding: 42px; }
  .menu-panel { width: min(100%, 620px); padding: 52px; }
  .menu-brand { gap: 18px; margin-bottom: 40px; }
  .menu-brand .brand-mark { flex-basis: 78px; width: 78px; height: 78px; }
  .menu-brand h1 { font-size: 2.5rem; }
  .menu-form { gap: 22px; }
  .form-field { font-size: 0.8rem; }
  .form-field input, .form-field select, .menu-actions .button { min-height: 54px; font-size: 0.98rem; }

  .app-shell { grid-template-columns: minmax(330px, 400px) minmax(0, 1fr); width: 100%; max-width: none; }
  .sidebar { gap: 24px; padding: 34px 26px 24px; }
  .brand { gap: 16px; min-height: 102px; }
  .brand-mark { width: 86px; height: 86px; }
  .eyebrow, .section-label { font-size: 0.75rem; }
  h1 { font-size: 2rem; }
  .place-card, .player-card, .control-section { padding: 18px; }
  .place-card h2 { font-size: 1.55rem; }
  .place-card p:last-child { font-size: 0.92rem; }
  .player-card strong { font-size: 1.18rem; }
  .scoreboard { gap: 10px; }
  .stat-card { padding: 14px 8px 12px; }
  .stat-card span { font-size: 0.68rem; }
  .stat-card strong { font-size: 1.35rem; }
  .points-badge { font-size: 0.78rem; }
  .grid-controls { gap: 9px; }
  .grid-button { min-height: 48px; font-size: 0.86rem; }
  .joker-controls { gap: 10px; margin-top: 12px; }
  .joker-button { min-height: 80px; font-size: 0.72rem; }
  .joker-icon { width: 30px; height: 30px; font-size: 0.78rem; }
  .sidebar-footer { gap: 10px; padding: 16px; }
  .sidebar-footer output, .text-button { font-size: 0.84rem; }

  .game-stage { padding: 42px clamp(34px, 4vw, 80px); }
  .stage-header { width: 100%; max-width: none; margin-bottom: 28px; }
  .stage-header h2 { font-size: 1.9rem; }
  .stage-legend { gap: 16px; font-size: 0.84rem; }
  .legend-swatch { width: 15px; height: 15px; }
  .map-panel { width: 100%; padding: 30px 24px 12px; }
  .map-corner { top: 36px; left: 30px; font-size: 0.9rem; }
  #map-svg { min-height: 620px; max-height: calc(100vh - 170px); }
  .map-note { padding-top: 10px; font-size: 0.82rem; }
  .site-footer { padding: 13px 20px 16px; }
  .site-footer small { font-size: 0.78rem; }
}

@media (min-width: 861px) {
  body { min-height: 0; height: 100dvh; overflow: hidden; }
  .app-shell { min-height: 0; }
  .sidebar { min-height: 0; overflow-y: auto; scrollbar-width: thin; }
  .game-stage { min-height: 0; overflow: hidden; }
  .map-panel { display: flex; flex-direction: column; align-items: center; width: min(100%, calc(116.279dvh - 298.837px)); max-width: 100%; }
  #map-svg { width: min(100%, calc(116.279dvh - 348.837px)); height: calc(100dvh - 300px); min-height: 0; max-width: 100%; max-height: calc(100dvh - 300px); }
  .map-note { align-self: stretch; }
}

@media (min-width: 861px) and (max-height: 1100px) {
  .sidebar { gap: 12px; padding: 14px 18px 12px; }
  .brand { gap: 12px; min-height: 64px; }
  .brand-mark { width: 60px; height: 60px; }
  .eyebrow, .section-label { font-size: 0.62rem; }
  h1 { font-size: 1.55rem; }
  .place-card, .player-card, .control-section { padding: 12px; }
  .place-card h2 { margin: 6px 0 2px; font-size: 1.2rem; }
  .place-card p:last-child { font-size: 0.7rem; }
  .player-card strong { margin-top: 4px; font-size: 0.9rem; }
  .stat-card { padding: 8px 4px 7px; }
  .stat-card span { font-size: 0.52rem; }
  .stat-card strong { font-size: 1rem; }
  .control-section { padding: 10px; }
  .section-heading { margin-bottom: 8px; }
  .points-badge { font-size: 0.62rem; }
  .grid-controls { gap: 6px; }
  .grid-button { min-height: 34px; font-size: 0.68rem; }
  .joker-controls { gap: 7px; margin-top: 8px; }
  .joker-button { min-height: 54px; font-size: 0.58rem; }
  .joker-icon { width: 22px; height: 22px; font-size: 0.62rem; }
  .sidebar-footer { gap: 6px; padding: 10px; }
  .sidebar-footer output { min-height: 20px; font-size: 0.66rem; }
  .text-button { font-size: 0.68rem; }
}

@media (min-width: 861px) and (max-height: 650px) {
  .sidebar { gap: 4px; padding: 8px 12px; }
  .brand { gap: 8px; min-height: 42px; }
  .brand-mark { width: 42px; height: 42px; }
  .eyebrow, .section-label { font-size: 0.48rem; }
  h1 { font-size: 1.25rem; }
  .place-card, .player-card, .control-section { padding: 8px; }
  .place-card h2 { margin: 3px 0 1px; font-size: 1rem; }
  .place-card p:last-child { font-size: 0.58rem; }
  .player-card strong { margin-top: 3px; font-size: 0.8rem; }
  .scoreboard { gap: 5px; }
  .stat-card { padding: 4px 3px; }
  .stat-card span { font-size: 0.45rem; }
  .stat-card strong { margin-top: 2px; font-size: 0.9rem; }
  .control-section { padding: 8px; }
  .section-heading { margin-bottom: 5px; }
  .points-badge { padding: 2px 5px; font-size: 0.56rem; }
  .grid-controls { gap: 4px; }
  .grid-button { min-height: 26px; font-size: 0.58rem; }
  .joker-controls { gap: 5px; margin-top: 5px; }
  .joker-button { min-height: 42px; font-size: 0.5rem; }
  .joker-icon { width: 18px; height: 18px; font-size: 0.55rem; }
  .sidebar-footer { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 8px; }
  .sidebar-footer output { grid-column: 1 / -1; min-height: 0; margin-bottom: 0; font-size: 0.56rem; }
  .text-button { font-size: 0.58rem; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { min-height: 54px; }
  .brand-mark { width: 50px; height: 50px; }
  .sidebar-footer { margin-top: 0; }
  .game-stage { padding-top: 22px; }
  #map-svg { min-height: 410px; max-height: none; }
  .resolution-panel { right: 18px; bottom: 38px; }
}

@media (max-width: 520px) {
  .main-menu { padding: 14px; }
  .menu-panel { padding: 25px 20px; }
  .menu-brand { margin-bottom: 25px; }
  .menu-actions { grid-template-columns: 1fr; }
  .sidebar { padding: 16px 12px; gap: 12px; }
  .place-card, .player-card, .control-section { padding: 12px; }
  .game-stage { padding: 18px 10px; }
  .stage-header { align-items: start; flex-direction: column; gap: 8px; }
  .stage-legend { justify-content: start; }
  .map-panel { padding: 16px 7px 7px; border-radius: 6px; }
  .map-corner { top: 20px; left: 13px; }
  #map-svg { min-height: 330px; }
  .resolution-panel { right: 12px; bottom: 33px; min-width: 190px; padding: 10px; }
  .grid-labels { font-size: 17px; }
  .map-note { padding-left: 34px; font-size: 0.64rem; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; }
}
