/* Layout: header, game grid, panels, modal, footer. */

/* ---------- HEADER ---------- */

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 2px solid var(--line);
  position: relative;
}
@media (max-width: 560px) {
  .header { padding: 8px 10px; margin-bottom: 12px; }
  .header-right { gap: 2px; }
  /* 44×44 minimum touch target for icon buttons on mobile */
  .icon-btn { width: 44px; height: 44px; }
  .brand-title { font-size: 16px; }
  .brand-logo { width: 22px; height: 22px; }
}
.header::before {
  /* pixel-art-ish corner notch */
  content: "";
  position: absolute;
  top: -2px; left: -2px;
  width: 10px; height: 10px;
  background: var(--primary);
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; gap: 8px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo {
  display: inline-flex;
  width: 26px; height: 26px;
  align-items: center; justify-content: center;
  background: var(--accent);
  border: 2px solid var(--accent);
}
.brand-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  letter-spacing: 0.05em;
  color: var(--text);
  text-shadow: 2px 2px 0 var(--primary);
}

.mini-track {
  display: none;
  align-items: center;
  height: 42px;
  padding: 0 8px;
}
@media (min-width: 760px) { .mini-track { display: flex; } }
.mini-track svg { width: 200px; height: 54px; }

.icon-btn {
  background: var(--bg-inset);
  color: var(--text);
  border: 2px solid var(--line);
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.icon-btn:hover { background: var(--line); border-color: var(--accent); color: var(--accent); }
.icon-btn:active { transform: translate(0, 1px); }

/* ---------- GAME GRID ---------- */

.game {
  flex: 1;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--gap);
  margin-bottom: var(--gap);
}
@media (max-width: 900px) {
  .game { grid-template-columns: 1fr; }
}

/* ---------- TRACK PANEL ---------- */

.track-panel {
  background: var(--bg-inset);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 460px;
}

.track-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-height: 360px;
  background:
    radial-gradient(ellipse at center, rgba(255, 209, 102, 0.08) 0%, transparent 70%);
}

#track-svg {
  width: 100%;
  height: auto;
  max-height: min(560px, 60vh);
  aspect-ratio: 1 / 1;
  overflow: visible;
}
@media (max-width: 900px) {
  #track-svg { max-height: min(420px, 42vh); }
  .track-panel { min-height: auto; padding: 8px; }
  .track-wrap { min-height: 220px; padding: 4px; }
}
#track-svg .track-line {
  fill: none;
  stroke: var(--track);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px var(--track-glow));
}
#track-svg .track-car {
  fill: var(--primary);
}

.track-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 2px;
  border-top: 1px dashed var(--line);
  margin-top: 6px;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}
@media (max-width: 560px) {
  .track-footer { flex-wrap: wrap; gap: 8px; }
  #btn-view-result { font-size: 10px; padding: 8px 12px; order: 3; flex-basis: 100%; white-space: normal; }
}
.label-sep { color: var(--primary); margin: 0 6px; }
.label-day { color: var(--accent); }

.guesses-left { display: flex; gap: 6px; }
.guesses-left .dot {
  width: 10px; height: 10px;
  background: var(--line);
  display: inline-block;
}
.guesses-left .dot.used { background: var(--danger); }
.guesses-left .dot.won { background: var(--success); }

/* ---------- INPUT PANEL ---------- */

.input-panel {
  background: var(--bg-surface);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.clues {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}
.clue {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 5px 8px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--accent);
  letter-spacing: 0.06em;
  animation: clue-in 0.35s ease-out backwards;
}
.clue .k { color: var(--text-dim); margin-right: 6px; }

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
@media (max-width: 400px) {
  /* On very narrow screens, stack the guess input above the GUESS button */
  .input-row { flex-wrap: wrap; }
  .input-row .autocomplete { flex: 1 1 100%; }
  .input-row .pixel-btn { flex: 1 1 100%; }
}

.autocomplete {
  position: relative;
  flex: 1;
}

.guess-input {
  width: 100%;
  background: var(--bg-inset);
  border: 2px solid var(--line);
  color: var(--text);
  padding: 12px 14px;
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.12s ease;
  outline: none;
}
.guess-input:focus {
  border-color: var(--accent);
  background: var(--bg-deep);
}
.guess-input::placeholder { color: var(--text-dim); }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  list-style: none;
  margin: 0; padding: 0;
  background: var(--bg-surface);
  border: 2px solid var(--line);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
  display: none;
}
.suggestions.open { display: block; }
.suggestions li {
  padding: 9px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.suggestions li:last-child { border-bottom: none; }
.suggestions li:hover, .suggestions li.active {
  background: var(--bg-inset);
  color: var(--accent);
}
.suggestions li.disabled {
  opacity: 0.35;
  cursor: not-allowed;
  text-decoration: line-through;
}
.suggestions li.disabled:hover { background: transparent; color: var(--text-dim); }
.suggestions .sug-country { color: var(--text-dim); font-size: 11px; }

/* ---------- GUESS LIST ---------- */

.guess-list {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.guess-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-inset);
  border: 2px solid var(--line);
  border-left-width: 4px;
  font-size: 13px;
  animation: guess-in 0.4s cubic-bezier(.22,1.6,.36,1) backwards;
  position: relative;
  overflow: hidden;
}
.guess-row.w-0 { border-left-color: #4a6cff; }  /* frozen */
.guess-row.w-1 { border-left-color: #6aa6ff; }  /* cold */
.guess-row.w-2 { border-left-color: var(--warning); }  /* warm */
.guess-row.w-3 { border-left-color: var(--primary); } /* burning */
.guess-row.w-4 { border-left-color: var(--success); } /* bullseye */
.guess-row .g-name { font-weight: 500; color: var(--text); }
.guess-row .g-dist { color: var(--text); white-space: nowrap; font-family: var(--font-pixel); font-size: 10px; }
.guess-row .g-compass {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: var(--accent);
  white-space: nowrap;
}
.guess-row.demo { border-left-color: var(--warning); }
.guess-row .proximity-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  background: var(--success);
  opacity: 0.6;
}

/* ---------- REVEAL OVERLAY ---------- */

.reveal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 16, 38, 0.82);
  backdrop-filter: blur(6px);
  z-index: 100;
  animation: fade-in 0.3s ease;
}
.reveal.open { display: flex; }

.reveal-card {
  background: var(--bg-surface);
  padding: 28px 26px 22px;
  max-width: 460px;
  width: 100%;
  max-height: 92vh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(.2,1.4,.35,1) both;
  position: relative;
  /* Reserve scrollbar space so content doesn't shift when scrolling appears */
  scrollbar-gutter: stable;
}
/* Ensure all reveal content wraps cleanly (no horizontal overflow ever) */
.reveal-card * { max-width: 100%; }
.reveal-card a, .reveal-card p, .reveal-card h3, .reveal-fact, .newsletter-title, .newsletter-body { word-wrap: break-word; overflow-wrap: anywhere; }
.reveal-offers-list { min-width: 0; }
.newsletter-form input { min-width: 0; }
@media (max-width: 560px) {
  .reveal { padding: 8px; }
  .reveal-card { padding: 20px 16px 16px; max-height: calc(100vh - 16px); }
  .reveal-emoji { font-size: 36px; margin-bottom: 4px; }
  .reveal-title { font-size: 16px; }
  .reveal-stats { gap: 6px; margin-bottom: 10px; }
  .stat { padding: 6px 2px; }
  .reveal-fact { font-size: 12px; margin: 8px 0 12px; }
  .reveal-countdown { margin-bottom: 10px; padding: 6px; }
  .countdown { font-size: 15px; }
  .reveal-buttons { flex-wrap: wrap; gap: 6px; }
  .reveal-buttons .pixel-btn { font-size: 11px; padding: 8px 10px; }
  .reveal-newsletter { padding: 10px; margin-top: 10px; }
  .newsletter-form { flex-direction: column; }
}
.reveal-close { font-size: 24px; line-height: 1; }
.reveal-emoji { font-size: 48px; margin-bottom: 6px; }
.reveal-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.reveal-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 16px;
}
.reveal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--bg-inset);
  padding: 8px 4px;
  border: 1px solid var(--line);
}
.stat-k { display: block; font-family: var(--font-pixel); font-size: 8px; color: var(--text-dim); letter-spacing: 0.1em; margin-bottom: 4px; }
.stat-v { font-family: var(--font-pixel); font-size: 13px; color: var(--text); }
.reveal-fact {
  font-size: 13px;
  color: var(--text);
  font-style: italic;
  margin: 10px 0 18px;
  line-height: 1.55;
}
.reveal-countdown {
  margin-bottom: 14px;
  padding: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
}
.countdown {
  display: block;
  font-family: var(--font-pixel);
  font-size: 18px;
  color: var(--accent);
  margin-top: 4px;
}
.reveal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 10px;
}
.reveal-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin: 0;
}

/* ---------- MODALS ---------- */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 16, 38, 0.82);
  backdrop-filter: blur(4px);
  z-index: 200;
  animation: fade-in 0.2s ease;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--bg-surface);
  padding: 28px 24px;
  max-width: 460px;
  width: 100%;
  position: relative;
  animation: pop-in 0.35s cubic-bezier(.2,1.4,.35,1) both;
}
.modal-close {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--bg-inset);
  border: 2px solid var(--line);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  padding: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.modal-close:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--bg-surface);
}
.modal-title {
  font-family: var(--font-pixel);
  font-size: 16px;
  text-align: center;
  color: var(--accent);
  margin-bottom: 16px;
  letter-spacing: 0.06em;
}
.modal-subtitle {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.08em;
  margin: 18px 0 8px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.stat-big {
  background: var(--bg-inset);
  padding: 12px 4px 10px;
  text-align: center;
  border: 1px solid var(--line);
}
.stat-big-v {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--accent);
}
.stat-big-k {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: var(--text-dim);
  margin-top: 4px;
  letter-spacing: 0.1em;
}
.distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stats-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}
.dist-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 6px;
  align-items: center;
  font-family: var(--font-pixel);
  font-size: 10px;
}
.dist-bar {
  background: var(--primary);
  color: var(--text);
  padding: 3px 6px;
  text-align: right;
  min-width: 20px;
}
.dist-row.highlight .dist-bar { background: var(--success); color: var(--bg-deep); }

.howto {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}
.howto li { margin-bottom: 6px; }
.howto strong { color: var(--accent); }
.howto-example {
  margin-top: 18px;
}
.example-label {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  text-align: center;
}

/* ---------- TOAST ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-inset);
  border: 2px solid var(--accent);
  padding: 10px 18px;
  color: var(--accent);
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 0.08em;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 300;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- FOOTER ---------- */

.footer {
  margin-top: auto;
  padding: 18px 10px 8px;
}
.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

/* ---------- REVEAL OFFERS ---------- */

.reveal-offers {
  margin: 14px 0 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.reveal-offers-title {
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
  margin: 0 0 6px;
}
.reveal-offers-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.reveal-offer a {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 0;
}
.reveal-offer a:hover { text-decoration: underline; }
.reveal-offers-disclosure { font-size: 9px; opacity: 0.5; margin: 6px 0 0; line-height: 1.4; }
.reveal-offers[data-variant="A"] .reveal-offers-title { display: none; }
.reveal-offers[data-variant="C"] .reveal-offers-title::before { content: "❤ "; }

/* ---------- SITE FOOTER (Ko-fi) ---------- */

/* Match the look of .footer-inner (the OpenStreetMap line) so both footer
   blocks read identically. Explicit colors, no opacity.
   position:relative + z-index:1 is CRITICAL: body::before in main.css paints
   a fixed gradient overlay whose bottom 20% is fully opaque var(--bg-deep).
   #app uses z-index:1 to escape it, but .site-footer lives OUTSIDE #app, so
   without its own stacking context the overlay covers the text and makes it
   look almost black on the dark background. */
.site-footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 18px 10px 24px;
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-dim, #8895B2);
}
.site-footer .footer-support { margin: 0 0 4px; }
.site-footer a { color: #FFD166; text-decoration: underline; }
.site-footer a:hover { text-decoration: none; }
.footer-links { margin-top: 4px; }

/* ---------- NEWSLETTER PROMPT ---------- */

.reveal-newsletter {
  margin-top: 16px;
  padding: 14px 12px;
  background: var(--bg-inset);
  border: 2px solid var(--line);
  position: relative;
}
.newsletter-title {
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.newsletter-body {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 10px;
  line-height: 1.4;
}
.newsletter-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.newsletter-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-deep);
  border: 2px solid var(--line);
  outline: none;
  transition: border-color 0.12s ease;
}
.newsletter-form input::placeholder { color: var(--text-dim); opacity: 0.6; }
.newsletter-form input:focus { border-color: var(--accent); }
.newsletter-form button {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--primary);
  color: var(--text);
  border: 2px solid #a01c2a;
  padding: 12px 16px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.15),
    inset -2px -2px 0 rgba(0, 0, 0, 0.35),
    0 3px 0 #5e0f19;
  transition: transform 0.06s ease, box-shadow 0.06s ease, color 0.12s ease, border-color 0.12s ease;
}
.newsletter-form button:hover { background: #ef4e5c; border-color: var(--accent); }
.newsletter-form button:active {
  transform: translateY(2px);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.1),
    inset -2px -2px 0 rgba(0, 0, 0, 0.45),
    0 1px 0 #5e0f19;
}
.newsletter-thanks {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 4px 0 0;
  text-align: center;
}

/* ---------- AD SLOTS (Phase 3 reserved containers) ---------- */

.ad-slot { min-height: 90px; width: 100%; max-width: 728px; margin: 0 auto; }
#ad-slot-below-game { min-height: 250px; max-width: 336px; }
.ad-slot-anchor { position: fixed; bottom: 0; left: 0; right: 0; min-height: 50px; }
