/* Time Machine — mobile-first, portrait 375–430px baseline.
   Shares Streetle's visual language (same tokens) with purple as its accent. */
:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --line: #d3d6da;
  --accent: #6d4c9f;
  --green: #1a7f37;
  --yellow: #c9a227;
  --gray: #787c7e;
  --chip-bg: #f0f1f3;
  --sheet-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #f4f4f4;
    --line: #3a3a3c;
    --accent: #a98ad4;
    --chip-bg: #232325;
    --sheet-bg: #1e1e1f;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---- Top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  position: relative;
}
#topbar h1 { font-size: 1.05rem; letter-spacing: 0.12em; font-weight: 800; white-space: nowrap; }
.beta-tag {
  display: inline-block;
  vertical-align: middle;
  font-size: 0.55rem;
  letter-spacing: 0.02em;
  font-weight: 800;
  background: var(--yellow);
  color: #000;
  padding: 1px 5px;
  border-radius: 4px;
  transform: translateY(-4px);
}
.header-title { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.masthead {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray);
}
.topbar-right { display: flex; gap: 4px; }
.icon-btn {
  border: none;
  background: none;
  color: inherit;
  font-size: 1.1rem;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  border-radius: 8px;
}
.icon-btn:active { background: var(--chip-bg); }
.stacked-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; }
.ib-icon { font-size: 1.05rem; line-height: 1.1; }
.ib-label { font-size: 0.5rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--gray); }
#mode-badge {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  z-index: 5;
  white-space: nowrap;
  border: 1px solid var(--yellow);
  background: var(--yellow);
  color: #000;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 0 0 8px 8px;
  cursor: pointer;
}

/* ---- Play area ---- */
#play-area {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 4px;
  gap: 8px;
  position: relative;
}

#toast {
  position: fixed;
  top: 14vh;
  left: 50%;
  transform: translateX(-50%) scale(0.95);
  z-index: 60;
  background: var(--fg);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: 88vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) scale(1); }

#photo-panel { flex: 0 0 auto; }
#scene-photo {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: block;
  background: var(--chip-bg);
  transition: max-height 0.25s ease;
}
#photo-panel.mini #scene-photo {
  aspect-ratio: auto;
  height: 96px;
  object-fit: cover;
  cursor: pointer;
}
.photo-caption {
  font-size: 0.82rem;
  color: var(--gray);
  font-weight: 600;
  padding: 6px 2px 0;
  text-align: center;
}

#map-panel { flex: 0 0 auto; }
#townmap {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  overflow: hidden;
}
#townmap svg { width: 100%; height: 100%; display: block; }
.map-streets {
  fill: none;
  stroke: var(--gray);
  stroke-opacity: 0.55;
  stroke-width: 0.45;
  stroke-linecap: round;
}
.pin-win-radius { fill: var(--accent); fill-opacity: 0.12; stroke: var(--accent); stroke-opacity: 0.5; stroke-width: 0.3; }
.pin-pending { fill: var(--accent); fill-opacity: 0.55; stroke: var(--accent); stroke-width: 0.5; }
.pin-locked { fill: var(--accent); }
.pin-num { fill: #fff; font-size: 3px; font-weight: 700; }
.pin-star { font-size: 5px; }
.map-caption {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 0.8rem;
  color: var(--gray);
  font-weight: 600;
  padding: 5px 2px 0;
}
.north { font-size: 0.68rem; letter-spacing: 0.04em; flex: 0 0 auto; }

#guesses { display: flex; flex-direction: column; gap: 5px; padding-bottom: 4px; }
.guess-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.9rem;
}
.g-main { font-weight: 700; }
.g-fb { color: var(--gray); font-weight: 600; font-size: 0.85rem; }
.g-fb.win { color: var(--green); }

/* ---- Input area ---- */
#input-area {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.year-row { display: flex; align-items: center; gap: 10px; }
#year-slider { flex: 1 1 auto; accent-color: var(--accent); height: 34px; }
.nudge-btn {
  min-width: 40px;
  min-height: 40px;
  font-size: 1.25rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: inherit;
  border-radius: 10px;
  cursor: pointer;
}
.commit-row { display: flex; align-items: center; gap: 10px; }
#year-readout {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 4ch;
  text-align: center;
}
.pin-readout { flex: 1 1 auto; font-size: 0.85rem; font-weight: 600; color: var(--gray); }
#btn-guess-year, #btn-guess-place {
  flex: 1 1 auto;
  min-height: 46px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#btn-guess-place { flex: 0 0 auto; padding: 0 18px; }
#btn-guess-year:disabled, #btn-guess-place:disabled { opacity: 0.4; cursor: default; }
.assist-row { display: flex; justify-content: center; }
.reveal-link {
  border: none;
  background: none;
  color: var(--gray);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 10px;
}

/* ---- Sheets ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 500px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--sheet-bg);
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet h2 { font-size: 1.1rem; }
.sheet p, .sheet li { font-size: 0.9rem; line-height: 1.45; }
.sheet ol { padding-left: 1.3em; display: flex; flex-direction: column; gap: 6px; }
.fine-print { font-size: 0.75rem !important; color: var(--gray); }
.sheet-close {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
}
.reveal-confirm-row { display: flex; gap: 10px; }
.reveal-confirm-row > * { flex: 1 1 0; }
.danger {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

/* ---- Result crossfade ---- */
#crossfade {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#crossfade img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#xf-now { opacity: 0; }
.xf-labels {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}
#xf-slider { width: 100%; accent-color: var(--accent); height: 34px; }
.learned { color: var(--gray); font-weight: 600; }
.result-actions { display: flex; gap: 10px; }
#btn-share {
  flex: 1 1 0;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
}
.secondary {
  flex: 1 1 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--chip-bg);
  color: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

/* ---- Feedback ---- */
#tm-feedback-form { display: flex; flex-direction: column; gap: 8px; }
#tm-feedback-form textarea, #tm-feedback-form input {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  padding: 9px 10px;
  user-select: text;
  -webkit-user-select: text;
}
#fb-submit {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.fb-error { color: #c0392b; font-size: 0.85rem !important; }
.fb-success { color: var(--green); font-weight: 700; }
