:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --ink: #16202a;
  --muted: #65717d;
  --line: #dfe4e8;
  --accent: #176b5a;
  --accent-dark: #105346;
  --answer: #c46b32;
  --danger: #b23b2e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.header {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 8px rgba(22, 32, 42, 0.04);
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

body.in-game .header { display: none; }

.screen { display: none; }
.screen.is-active { display: block; }

.kicker {
  margin: 0 0 12px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.button {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(22, 32, 42, 0.06);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button:disabled { opacity: 0.45; cursor: not-allowed; }

.button.primary {
  background: var(--accent);
  color: #fff;
}
.button.primary:hover:not(:disabled) { background: var(--accent-dark); }

.button.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
.button.secondary:hover { border-color: var(--accent); color: var(--accent); }

.button.wide { width: 100%; }

.text-button {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  padding: 4px;
}
.text-button:hover { color: var(--ink); text-decoration: underline; }

/* Menu */

.menu-panel {
  max-width: 800px;
  margin: 0 auto;
  padding: 76px 24px 96px;
}

.menu-panel h1 {
  margin: 0;
  font-size: clamp(42px, 6vw, 62px);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.intro {
  max-width: 550px;
  margin: 20px 0 28px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.6;
}

.setup-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 28px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(22, 32, 42, 0.05);
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 600; }

.field select {
  min-width: 210px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.check-field input { accent-color: var(--accent); }

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.menu-actions .button { min-width: 150px; }

/* Game */

#gameScreen {
  position: fixed;
  inset: 0;
  z-index: 10;
  max-width: none;
  padding: 0;
  background: #d9dde0;
}

.game-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 50px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(22, 32, 42, 0.12);
  backdrop-filter: blur(8px);
  font-size: 14px;
}

.game-info {
  padding: 4px 16px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.game-info:first-child { padding-left: 0; }
.game-info strong { font-weight: 700; font-variant-numeric: tabular-nums; }
.mode-label { color: var(--muted); font-size: 13px; }
#homeBtn { margin-left: auto; }

.timer {
  padding: 4px 16px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.timer strong { color: var(--ink); font-family: var(--mono); }
.timer.is-low strong { color: var(--danger); }

.progress-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 16px;
  border-right: 1px solid var(--line);
}

.progress-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
}
.progress-dot.is-done { background: var(--accent); }
.progress-dot.is-current {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 90, 0.16);
}

.progress-infinity {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
}

.game-layout {
  position: absolute;
  inset: 0;
  display: block;
  margin: 0;
  height: 100%;
  min-height: 0;
}

.satellite-card {
  position: absolute;
  inset: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #d9dde0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.satellite-map { position: absolute; inset: 0; }

.target-node-marker {
  background: transparent;
  border: 0;
  pointer-events: none;
}

.target-node-marker span {
  display: block;
  width: 24px;
  height: 24px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgba(22, 32, 42, 0.82);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.35);
  position: relative;
}

.target-node-marker span::before,
.target-node-marker span::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  background: #fff;
  transform: translate(-50%, -50%);
}
.target-node-marker span::before { width: 2px; height: 8px; }
.target-node-marker span::after { width: 8px; height: 2px; }

.sat-help {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  pointer-events: none;
}

.leaflet-container {
  background: #eef2f4;
  font-family: var(--sans);
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.92) !important;
  color: #5c6873 !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }

.leaflet-control-zoom { border: 1px solid var(--line) !important; border-radius: 6px !important; }
.leaflet-control-zoom a {
  background: #fff !important;
  color: var(--ink) !important;
  border-bottom-color: var(--line) !important;
}
.leaflet-control-zoom a:hover { background: #f7f8f9 !important; color: var(--accent) !important; }
#satMap .leaflet-control-zoom-out { display: none !important; }
#satMap .leaflet-control-zoom a:last-child { border-bottom: 0 !important; }

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 590;
  display: grid;
  place-items: center;
  background: rgba(245, 244, 240, 0.94);
  color: var(--muted);
  font-size: 13px;
  padding: 24px;
  text-align: center;
}

.map-loading > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loading-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  animation: loading-pulse 1.1s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.7); }
  50% { opacity: 1; transform: scale(1); }
}

.map-error {
  position: absolute;
  inset: 0;
  z-index: 600;
  display: grid;
  place-items: center;
  background: rgba(245, 244, 240, 0.96);
  text-align: center;
  padding: 24px;
}
.map-error strong { font-size: 18px; }
.map-error p { color: var(--muted); margin: 8px 0 18px; }

.guess-card {
  position: absolute;
  top: 74px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: 260px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 88px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 38px rgba(22, 32, 42, 0.2);
  padding: 14px;
  transition: width 0.28s ease, padding 0.28s ease;
}

.guess-card:hover,
.guess-card:focus-within,
.guess-card.is-open {
  width: min(440px, calc(100vw - 24px));
  padding: 18px;
}

.guess-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.guess-card h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.guess-hint {
  display: none;
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.guess-card:hover .guess-hint,
.guess-card:focus-within .guess-hint,
.guess-card.is-open .guess-hint { display: block; }

.world-map-wrap {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #eef2f4;
}

.guess-map {
  width: 100%;
  height: 160px;
  background: #eef2f4;
  transition: height 0.28s ease;
}

.guess-card:hover .guess-map,
.guess-card:focus-within .guess-map,
.guess-card.is-open .guess-map {
  height: min(340px, 48vh);
}

.sg-marker-wrap { background: transparent; border: 0; }

.sg-marker {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.guess-marker { background: var(--accent); }
.answer-marker { background: var(--answer); }

.guess-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
}

.coordinate {
  margin: 10px 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.reveal {
  flex: 0 0 auto;
  margin-top: 18px;
  padding: 16px;
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.reveal-kicker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.reveal-title {
  display: block;
  margin-top: 6px;
  font-size: 21px;
}

.reveal-line {
  margin: 6px 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.reveal-coords {
  margin: 0 0 10px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.reveal-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  line-height: 1.45;
}

.reveal .text-button { display: block; margin-bottom: 14px; }

/* Summary */

.summary-panel {
  max-width: 780px;
  margin: 48px auto 88px;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(22, 32, 42, 0.06);
}

.summary-panel h2 {
  margin: 0;
  font-size: 36px;
  letter-spacing: -0.035em;
}

.summary-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.summary-score {
  margin-top: 24px;
  font-size: 68px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.06em;
  line-height: 1;
}

.summary-label {
  margin: 6px 0 28px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.summary-list { border-top: 1px solid var(--line); }

.summary-row {
  display: grid;
  grid-template-columns: 28px 24px minmax(0, 1fr) 90px 80px;
  gap: 10px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.summary-num { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.summary-emoji { font-size: 15px; text-align: center; }
.summary-place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.summary-dist { color: var(--muted); font-family: var(--mono); font-size: 12px; text-align: right; }
.summary-points { font-family: var(--mono); font-weight: 600; text-align: right; }

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}
.summary-actions .button { min-width: 140px; }

@media (max-width: 820px) {
  .game-bar { top: 8px; left: 8px; right: 8px; gap: 4px; }
  .guess-card { top: 66px; right: 8px; width: 220px; }
  .guess-card:hover,
  .guess-card:focus-within,
  .guess-card.is-open { width: min(380px, calc(100vw - 16px)); }
  .guess-map { height: 140px; }
  .guess-card:hover .guess-map,
  .guess-card:focus-within .guess-map,
  .guess-card.is-open .guess-map { height: min(300px, 45vh); }
  .sat-help { display: none; }
}

@media (max-width: 600px) {
  .header { height: 54px; padding: 0 18px; }
  .menu-panel { padding: 60px 18px 80px; }
  .menu-panel h1 { font-size: 42px; }
  .intro { font-size: 15px; }
  .field { width: 100%; }
  .field select { width: 100%; }
  .game-info { padding: 4px 10px; }
  .mode-label { font-size: 12px; }
  .progress-dots { display: none; }
  .guess-card { width: 200px; padding: 12px; }
  .guess-card:hover,
  .guess-card:focus-within,
  .guess-card.is-open { width: calc(100vw - 16px); padding: 16px; }
  .summary-panel { margin: 28px 14px 60px; padding: 28px 20px; }
  .summary-row { grid-template-columns: 24px 22px minmax(0, 1fr) 68px 60px; gap: 6px; font-size: 13px; }
}
