/* Visual language borrowed from neuralnoise.com: Raleway + Roboto Slab, grey text on white,
   a dark photographic cover panel, hairline rules and #e25440 as the single accent. */
:root {
  --paper: #ffffff;
  --ink: #333333;
  --text: #666666;
  --muted: #999999;
  --rule: #dddddd;
  --rule-soft: #eeeeee;
  --accent: #e25440;
  --accent-dark: #b9301c;
  --accent-tint: #fae3df;
  --you: #5ba4e5;
  --you-dark: #217fd2;
  --slate: #2f3942;
  --sans: "Raleway", "Helvetica Neue", Arial, sans-serif;
  --slab: "Roboto Slab", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: lining-nums;  /* Raleway defaults to old-style figures */
  overflow: hidden;
}
[hidden] { display: none !important; }
h1, h2 { font-weight: 300; margin: 0; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--you-dark); outline-offset: 2px; }

.screen { position: fixed; inset: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 9px 22px;
  border: 1px solid var(--accent);
  border-radius: 20px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: .03em;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn:disabled { background: var(--rule-soft); border-color: var(--rule); color: var(--muted); cursor: default; }
.btn-large { padding: 11px 28px; font-size: 1rem; }

.text-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: .88rem;
  font-weight: 500;
}
.text-btn:hover { color: var(--accent-dark); text-decoration: underline; }

.wordmark {
  font-family: var(--sans);
  font-weight: 300;
  letter-spacing: 4px;
}

/* ---------- Start screen ---------- */
#start-screen { display: flex; }

.cover {
  position: relative;
  flex: 0 0 40%;
  max-width: 530px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 30px;
  color: #fff;
  text-align: center;
  background: var(--slate) url("https://neuralnoise.com/images/foto/M.S.ANGELO_FERRO_BATTUTO_011.jpg") center / cover no-repeat;
}
.cover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(140deg, rgba(68, 68, 68, .6) 20%, rgba(0, 0, 0, .6));
}
.cover-inner { position: relative; max-width: 380px; }
.cover .wordmark { font-size: 2.5rem; color: #fff; }
.cover-rule { width: 50%; margin: 20px auto; border: 0; border-top: 1px solid rgba(255, 255, 255, .14); }
.cover-rule--short { width: 15%; }
.cover-text { font-size: 1rem; line-height: 1.7; color: #fff; }
.cover-link { color: rgba(255, 255, 255, .85); font-size: .95rem; letter-spacing: 1px; }
.cover-link:hover { color: #fff; }

.start-main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  padding: 48px 60px;
  overflow-y: auto;
}
.start-content { max-width: 620px; }
.start-content h2 { font-family: var(--slab); font-size: 2.5rem; line-height: 1.2; color: var(--ink); margin-bottom: 16px; }
.lead { font-size: 1.05rem; line-height: 1.75; }

.settings { margin: 32px 0 30px; padding-top: 24px; border-top: 1px solid var(--rule); }
.setting + .setting { margin-top: 22px; }
.setting-name { display: block; margin-bottom: 8px; font-weight: 600; font-size: .95rem; color: var(--ink); }
.setting-hint { margin-top: 8px; font-size: .85rem; color: var(--muted); max-width: 52ch; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  min-width: 56px;
  padding: 6px 16px;
  border: 1px solid #cccccc;
  border-radius: 20px;
  background: var(--paper);
  color: var(--text);
  font-weight: 500;
  font-size: .92rem;
}
.seg button:hover { border-color: var(--muted); color: var(--ink); }
.seg button.active { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-dark); }

.fineprint { margin-top: 28px; font-size: .82rem; line-height: 1.7; color: var(--muted); }
#model-name { color: var(--text); }

/* ---------- Game screen ---------- */
#game-screen { display: flex; flex-direction: column; }

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 28px;
  min-height: 56px;
  padding: 8px 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  z-index: 10;
}
.wordmark--small { padding: 0; border: 0; background: none; font-size: 1.25rem; letter-spacing: 3px; color: var(--ink); }
.wordmark--small:hover { color: var(--accent); }
.topbar-stats { display: flex; align-items: baseline; gap: 24px; }
.stat { white-space: nowrap; font-size: .9rem; }
.stat-name { color: var(--muted); }
.stat-value { font-family: var(--slab); font-size: 1.1rem; color: var(--ink); font-variant-numeric: lining-nums tabular-nums; }
.stat--you .stat-value { color: var(--you-dark); }
.stat--ai .stat-value { color: var(--accent); }
#hud-timer.low { color: var(--accent-dark); font-weight: 400; }

.ai-status { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); }
.ai-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #cccccc; flex: none; }
.ai-status.thinking .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.ai-status.done .dot { background: var(--accent); }
.ai-status.error .dot { background: var(--muted); }
@keyframes pulse { 50% { opacity: .25; } }

#viewer-wrap { position: relative; flex: 1 1 auto; min-height: 0; background: #1e1e1e; }
#viewer { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#viewer.flat { cursor: grab; }
#viewer.flat.dragging { cursor: grabbing; }
#viewer .flat-img {
  position: absolute; left: 0; top: 0; max-width: none;
  transform-origin: 0 0; user-select: none; -webkit-user-drag: none; will-change: transform;
}
#viewer .pnlm-controls-container { top: auto; bottom: 16px; left: 16px; }

.viewer-controls { position: absolute; left: 16px; bottom: 16px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.viewer-controls button {
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--paper); color: var(--ink);
  font-family: "Helvetica Neue", Arial, sans-serif; font-size: 1.25rem; line-height: 1;
}
.viewer-controls button:hover { color: var(--accent); }

.loading {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: 16px; background: var(--paper); color: var(--text); text-align: center;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--rule); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.guess-panel {
  position: absolute; right: 16px; bottom: 16px; z-index: 10;
  width: 320px;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
  transition: width .2s ease;
}
.guess-panel-bar { display: flex; align-items: baseline; gap: 14px; }
.guess-panel-title { margin-right: auto; font-weight: 600; font-size: .92rem; color: var(--ink); }
#map-pin-btn[aria-pressed="true"] { color: var(--accent-dark); font-weight: 600; }
#guess-map { height: 190px; border: 1px solid var(--rule-soft); border-radius: 2px; transition: height .2s ease; }
.guess-panel:hover, .guess-panel.pinned { width: min(560px, calc(100vw - 32px)); }
.guess-panel:hover #guess-map, .guess-panel.pinned #guess-map { height: min(380px, 52vh); }
.guess-panel.large, .guess-panel.large:hover { width: min(900px, calc(100vw - 32px)); }
.guess-panel.large #guess-map, .guess-panel.large:hover #guess-map { height: min(620px, 66vh); }
#guess-btn { width: 100%; }
.mobile-only { display: none; }

/* ---------- Results & final ---------- */
#result-screen, #final-screen { display: flex; flex-direction: column; }
#result-map, #final-map { flex: 1 1 auto; min-height: 200px; }
.sheet {
  flex: none;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  box-shadow: 0 -2px 14px rgba(0, 0, 0, .12);
}
.sheet-inner { max-width: 860px; margin: 0 auto; padding: 22px 24px 28px; }
.sheet h2 { font-family: var(--slab); font-size: 1.9rem; line-height: 1.25; color: var(--ink); margin-bottom: 18px; }

.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 36px; }
.player-card { padding-top: 12px; border-top: 2px solid var(--rule); }
.player-card.you { border-top-color: var(--you); }
.player-card.ai { border-top-color: var(--accent); }
.who { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.swatch { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.swatch--answer { width: 8px; height: 8px; margin: 0 7px 0 2px; vertical-align: 1px; background: var(--ink); box-shadow: 0 0 0 1.5px #fff, 0 0 0 3px var(--ink); }
.you .swatch { background: var(--you); }
.ai .swatch { background: var(--accent); }
.player-card.winner .who::after {
  content: "Winner";
  margin-left: 4px; padding: 0 9px;
  border: 1px solid var(--ink); border-radius: 20px;
  font-size: .72rem; font-weight: 600; line-height: 1.6; color: var(--ink);
}
.pts { margin-top: 2px; font-family: var(--slab); font-weight: 300; font-size: 2.3rem; line-height: 1.2; color: var(--ink); font-variant-numeric: lining-nums tabular-nums; }
.pts-unit { font-family: var(--sans); font-size: .9rem; color: var(--muted); }
.bar { height: 4px; margin: 8px 0; background: var(--rule-soft); border-radius: 2px; overflow: hidden; }
.bar div { width: 0; height: 100%; transition: width .8s ease; }
.you .bar div { background: var(--you); }
.ai .bar div { background: var(--accent); }
.dist { font-size: .92rem; line-height: 1.55; }

#ai-reasoning { margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--rule); }
#ai-reasoning summary { cursor: pointer; font-weight: 600; font-size: .95rem; color: var(--accent); }
#ai-reasoning summary:hover { color: var(--accent-dark); }
#ai-reasoning-text { margin-top: 10px; max-width: 72ch; white-space: pre-wrap; font-size: .93rem; line-height: 1.7; }

.answer-meta { margin-top: 16px; font-size: .88rem; line-height: 1.7; color: var(--text); }
.result-actions { margin-top: 22px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }

.table-wrap { margin-top: 24px; overflow-x: auto; }
.rounds-table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.rounds-table th {
  padding: 6px 10px; text-align: left; white-space: nowrap;
  font-weight: 600; font-size: .85rem; color: var(--muted); border-bottom: 1px solid var(--rule);
}
.rounds-table td { padding: 9px 10px; border-bottom: 1px solid var(--rule-soft); vertical-align: baseline; }
.rounds-table .num { text-align: right; white-space: nowrap; font-variant-numeric: lining-nums tabular-nums; }
.rounds-table td.win { color: var(--ink); font-weight: 600; }
.rounds-table .km { display: block; color: var(--muted); font-weight: 400; font-size: .82rem; }

/* ---------- Map markers ---------- */
.pin {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.pin.you { background: var(--you-dark); }
.pin.ai { background: var(--accent); }
.pin.answer { background: var(--ink); box-shadow: 0 0 0 3px var(--ink), 0 1px 6px rgba(0, 0, 0, .5); }
.leaflet-container { font-family: var(--sans); background: #aad3df; }
.leaflet-tooltip.map-label {
  padding: 2px 8px; border: 1px solid var(--rule); border-radius: 3px;
  box-shadow: none; font-family: var(--sans); font-size: .82rem; font-weight: 500; color: var(--ink);
}

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 1000;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 3px;
  background: var(--ink); color: #fff; font-size: .92rem;
}

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  #start-screen { display: block; overflow-y: auto; }
  .cover { max-width: none; padding: 30px 24px 28px; }
  .cover .wordmark { font-size: 2rem; }
  .cover-rule { margin: 14px auto; }
  .cover-text { font-size: .95rem; }
  .cover-text br { display: none; }
  .start-main { display: block; padding: 32px 20px 44px; overflow: visible; }
  .start-content h2 { font-size: 2rem; }

  .topbar { flex-wrap: wrap; gap: 6px 18px; padding: 8px 14px; }
  .topbar-stats { gap: 16px; }
  .ai-status { margin-left: 0; flex-basis: 100%; font-size: .85rem; }

  .guess-panel, .guess-panel:hover, .guess-panel.pinned, .guess-panel.large, .guess-panel.large:hover {
    left: 12px; right: 12px; bottom: 12px; width: auto;
  }
  .guess-panel { display: none; }
  .guess-panel.mobile-open { display: flex; }
  #guess-map, .guess-panel:hover #guess-map, .guess-panel.pinned #guess-map, .guess-panel.large #guess-map { height: 52vh; }
  #map-size-btn, #map-pin-btn { display: none; }
  .mobile-only { display: inline-block; }
  #mobile-map-btn { position: absolute; right: 16px; bottom: 16px; z-index: 9; }
  .guess-panel.mobile-open ~ #mobile-map-btn { display: none; }

  .sheet { max-height: 64vh; }
  .sheet-inner { padding: 18px 16px 24px; }
  .sheet h2 { font-size: 1.6rem; margin-bottom: 14px; }
  .versus { grid-template-columns: 1fr 1fr; gap: 18px; }
  .pts { font-size: 1.7rem; }
  .rounds-table { font-size: .88rem; }
  .rounds-table th, .rounds-table td { padding-left: 6px; padding-right: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
