/* Streetle — mobile-first, portrait 375–430px baseline. */
:root {
  --bg: #ffffff;
  --fg: #1a1a1b;
  --line: #d3d6da;
  --green: #1a7f37;
  --yellow: #c9a227;
  --gray: #787c7e;
  --chip-bg: #f0f1f3;
  --sheet-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #f4f4f4;
    --line: #3a3a3c;
    --chip-bg: #232325;
    --sheet-bg: #1e1e1f;
  }
}
body.high-contrast {
  --green: #f5793a;
  --yellow: #85c0f9;
}
body.high-contrast .guess-line { border-width: 2px; }

* { 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;
}
#topbar h1 { font-size: 1.25rem; letter-spacing: 0.15em; font-weight: 800; }
.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;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}
.masthead {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gray);
}
#mode-badge {
  position: absolute;
  top: calc(80px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--yellow);
  color: #000;
  border: none;
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  z-index: 10;
}
#debug-badge {
  position: absolute;
  top: calc(56px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  background: var(--yellow);
  color: #000;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 10;
}
.topbar-right { display: flex; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px;
  border: none; background: none; color: var(--fg);
  font-size: 1.25rem; border-radius: 8px; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
/* Icon-only controls read as decoration, not action — pair the icon with a
   tiny caption (same two-line shape as the STREETLE/neighborhood button)
   so what a tap does is legible before tapping it. */
.stacked-btn {
  width: auto;
  min-width: 44px;
  padding: 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}
.stacked-btn .ib-icon { font-size: 1.05rem; line-height: 1; }
.stacked-btn .ib-label {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  margin-top: 2px;
  white-space: nowrap;
}

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

#silhouette-panel {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: var(--chip-bg);
}
/* touch-action:none hands pinch/pan/double-tap entirely to our own pointer
   handlers instead of the browser's page-zoom/scroll gestures; overflow
   hidden clips panned/zoomed content to the frame instead of spilling into
   the rest of the page. */
#silhouette { height: min(30dvh, 220px); display: flex; overflow: hidden; touch-action: none; }
#silhouette svg { width: 100%; height: 100%; transform-origin: 0 0; }
#silhouette path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#silhouette path.answer { stroke: var(--green); stroke-width: 2.5; }
#silhouette path.guessed { stroke: var(--yellow); stroke-width: 1.6; }
#silhouette path.ctx { stroke: var(--gray); stroke-width: 0.7; opacity: 0.45; pointer-events: none; }
body.high-contrast #silhouette path.ctx { opacity: 0.7; }
#silhouette path.ctx-hit {
  stroke: transparent;
  stroke-width: 4;
  cursor: pointer;
  pointer-events: stroke;
}
#silhouette path.ctx-hit:hover + path.ctx,
#silhouette path.ctx-hit:active + path.ctx {
  stroke: var(--fg);
  opacity: 0.9;
}
#silhouette .scalebar line { stroke: var(--fg); stroke-width: 0.5; opacity: 0.65; }
#silhouette .scalebar text { fill: var(--fg); font-size: 4px; opacity: 0.75; }
#silhouette path.anchor-cross { stroke: var(--gray); stroke-width: 1; opacity: 0.75; stroke-dasharray: 2 2; pointer-events: none; }
body.high-contrast #silhouette path.anchor-cross { opacity: 1; }
#silhouette circle.landmark { fill: var(--fg); stroke: var(--bg); stroke-width: 0.4; }
#silhouette circle.landmark.on-context { opacity: 0.45; }
#silhouette circle.landmark.on-answer { opacity: 1; }
body.high-contrast #silhouette circle.landmark.on-context { opacity: 0.7; }
/* Game over: the street's name written on the map */
#silhouette text.answer-name {
  fill: var(--green);
  font-size: 6px;
  font-weight: 800;
  letter-spacing: 0.04em;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 1.2;
}
#silhouette circle.answer-dot { fill: var(--green); stroke: var(--bg); stroke-width: 0.4; }

.sil-caption {
  font-size: 0.8rem;
  opacity: 0.85;
  padding: 4px 4px 0;
}
.cap-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.north { font-weight: 700; flex: 0 0 auto; }
#clue-line { text-align: right; }
#clue-unlocked { flex: 1 1 auto; text-align: right; font-style: italic; min-height: 1em; }
.hint-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--fg);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 30px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}
.hint-btn:disabled { opacity: 0.35; cursor: default; filter: grayscale(1); border-style: dashed; }
.hint-btn:not(:disabled):active { filter: brightness(0.9); }
.tool-row {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 4px 4px 0;
}
.lifeline-line {
  padding: 4px 4px 0;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: right;
}

/* ---- Guess rows ---- */
#guesses { display: flex; flex-direction: column; gap: 6px; }
.guess-line, .example-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 46px;
  padding: 4px 10px;
  font-size: 0.95rem;
}
.guess-line.empty { border-style: dashed; opacity: 0.45; justify-content: center; }
.guess-line .g-name, .example-row .g-name { flex: 1 1 auto; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.guess-line .g-dist, .example-row .g-dist { font-variant-numeric: tabular-nums; opacity: 0.9; }
.guess-line .g-arrow, .example-row .g-arrow {
  font-size: 1.15rem;
  min-width: 34px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center;
}
.guess-line .g-arrow small, .example-row .g-arrow small { font-size: 0.6rem; font-weight: 700; opacity: 0.8; line-height: 1; }
.guess-line .g-warm, .example-row .g-warm {
  min-width: 62px;
  text-align: center;
  font-weight: 800;
  border-radius: 6px;
  padding: 4px 6px;
  color: #fff;
  background: var(--gray);
  font-variant-numeric: tabular-nums;
}
.guess-line .g-warm small, .example-row .g-warm small { display: block; font-size: 0.55rem; font-weight: 600; opacity: 0.9; line-height: 1.1; }
.guess-line .g-warm.green, .example-row .g-warm.green { background: var(--green); }
.guess-line .g-warm.yellow, .example-row .g-warm.yellow { background: var(--yellow); }
.guess-line.hit { border-color: var(--green); background: color-mix(in srgb, var(--green) 12%, transparent); }
.guess-line.near { border-color: var(--yellow); background: color-mix(in srgb, var(--yellow) 10%, transparent); }
.guess-line.reveal { animation: pop-in 0.25s ease-out; }
.example-row { margin-bottom: 8px; }
@keyframes pop-in {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .guess-line.reveal { animation: none; } }

/* ---- Input + autocomplete ---- */
#input-area {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  position: relative;
}
.coach {
  font-size: 0.8rem;
  text-align: center;
  opacity: 0.8;
  padding-bottom: 8px;
}
#suggestions {
  position: absolute;
  bottom: 100%;
  left: 8px; right: 8px;
  background: var(--sheet-bg);
  border: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  max-height: 34dvh;
  overflow-y: auto;
  box-shadow: 0 -6px 18px rgba(0,0,0,0.15);
  z-index: 25;
}
.sugg {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  min-height: 44px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}
.sugg:last-child { border-bottom: none; }
.sugg:active { background: var(--chip-bg); }
.sugg .hl { font-weight: 800; color: var(--green); }
.sugg:disabled { opacity: 0.4; }
.sugg small { opacity: 0.6; float: right; }
/* Final-guess multiple choice chips */
#final-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-bottom: 8px;
}
.fc-label { width: 100%; font-size: 0.75rem; opacity: 0.75; }
.fc-chip {
  border: 1px solid var(--line);
  background: var(--chip-bg);
  color: var(--fg);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.fc-chip:active { filter: brightness(0.9); }

.input-row { display: flex; gap: 8px; }
#guess-input {
  flex: 1 1 auto;
  min-height: 50px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 16px; /* ≥16px prevents iOS zoom */
  background: var(--bg);
  color: var(--fg);
}
#guess-input:focus { outline: none; border-color: var(--green); }
#btn-guess {
  flex: 0 0 auto;
  min-width: 88px;
  min-height: 50px;
  border: none;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}
#btn-guess:disabled { opacity: 0.4; }
#btn-guess:active { filter: brightness(0.9); }

/* ---- Toast ---- */
#toast {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 20;
  max-width: 90%;
  text-align: center;
}
#toast.show { opacity: 1; }

/* ---- Bottom sheets ---- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
}
.sheet {
  position: fixed;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: 100%; max-width: 500px;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--sheet-bg);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  z-index: 40;
  animation: slide-up 0.25s ease-out;
}
@keyframes slide-up {
  from { transform: translate(-50%, 100%); }
  to   { transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 4px auto 14px;
}
.sheet h2 { margin-bottom: 10px; }
.sheet h3 { margin: 14px 0 8px; }
.sheet p, .sheet li { line-height: 1.45; margin-bottom: 8px; font-size: 0.95rem; }
.sheet ul { padding-left: 20px; margin-bottom: 10px; }
.sheet a { color: var(--green); }
.fine { font-size: 0.85rem; opacity: 0.8; }
.result-street { font-size: 1.3rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.result-recap { font-weight: 600; }
.result-streak { font-weight: 700; font-size: 0.95rem; }
.countdown { text-align: center; margin-top: 10px; font-variant-numeric: tabular-nums; }

/* ---- Stuck? sheet ---- */
.stuck-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chip-bg);
  color: var(--fg);
  padding: 12px 14px;
  margin-bottom: 8px;
  min-height: 56px;
  font: inherit;
  cursor: pointer;
}
.stuck-option:not(:disabled):active { filter: brightness(0.92); }
.stuck-option:disabled { opacity: 0.45; cursor: default; border-style: dashed; }
.stuck-option .so-icon { font-size: 1.4rem; flex: 0 0 auto; }
.stuck-option .so-text { display: flex; flex-direction: column; gap: 2px; }
.stuck-option .so-text strong { font-size: 0.95rem; }
.stuck-option .so-text small { font-size: 0.78rem; opacity: 0.75; line-height: 1.3; }
.reveal-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.65;
}
.reveal-divider::before, .reveal-divider::after {
  content: "";
  flex: 1 1 auto;
  border-top: 1px solid var(--line);
}
.reveal-note { margin-bottom: 4px; }
.reveal-confirm-row { display: flex; gap: 8px; }
.reveal-confirm-row .big-btn { flex: 1 1 50%; }

/* ---- Feedback sheet ---- */
.fb-error, .fb-success {
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 600;
}
.fb-error { background: color-mix(in srgb, #c41230 15%, transparent); color: #c41230; }
.fb-success { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }

/* ---- Debug sheet ---- */
.dbg-label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.dbg-label small { font-weight: 400; opacity: 0.7; }
.dbg-label input, .dbg-label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--bg);
  color: var(--fg);
}
.dbg-label input:focus, .dbg-label select:focus { outline: none; border-color: var(--green); }

.big-btn {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  border: none;
  border-radius: 10px;
  background: var(--green);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  line-height: 52px;
  padding: 0 8px;
}
a.big-btn { color: #fff; }
.big-btn.secondary { background: var(--chip-bg); color: var(--fg); }
a.big-btn.secondary { color: var(--fg); }
.big-btn:active { filter: brightness(0.9); }

/* ---- Stats ---- */
.stat-row { display: flex; justify-content: space-around; text-align: center; margin-bottom: 6px; }
.stat-box .num { font-size: 1.6rem; font-weight: 800; display: block; }
.stat-box .lbl { font-size: 0.7rem; opacity: 0.75; }
.dist-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 0.85rem; }
.dist-bar {
  background: var(--gray); color: #fff;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 3px;
  text-align: right;
  font-weight: 700;
}
.dist-bar.win { background: var(--green); }

/* ---- "Your Wyckoff" explore map ---- */
#explore-map {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  background: var(--chip-bg);
}
#explore-map svg { width: 100%; height: auto; display: block; }
#explore-map path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
#explore-map path.unseen { stroke: var(--gray); stroke-width: 0.4; opacity: 0.35; }
#explore-map path.seen { stroke: var(--green); stroke-width: 0.9; }

/* ---- Toggle rows (hard mode, contrast) ---- */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 4px 0 10px;
  font-size: 0.9rem;
  line-height: 1.35;
  cursor: pointer;
}
.toggle-row input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--green); }

/* ---- Neighborhood picker ---- */
.neighborhood-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.nb-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  min-height: 48px;
  font-size: 0.95rem;
  font-weight: 700;
  background: var(--chip-bg);
  color: var(--fg);
  cursor: pointer;
}
.nb-choice.active { border-color: var(--green); background: var(--green); color: #fff; }
.nb-choice .check { visibility: hidden; }
.nb-choice.active .check { visibility: visible; }

/* ---- Confetti ---- */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetto {
  position: absolute;
  width: 8px; height: 12px;
  top: -20px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(105vh) rotate(720deg); }
}
@media (prefers-reduced-motion: reduce) { .confetto { display: none; } }

@media (max-height: 620px) {
  #silhouette { height: 22dvh; }
  .guess-line { min-height: 40px; }
}
