:root {
  --panel-w: 360px;

  /* Palette: base (map), primary (sidebar and panels), secondary (named streets + highlights). */
  --base: #0B1020;
  --base-raised: #151C36;
  --water: #060A16;
  --park: #10192F;
  --street: #26304F;
  --boundary: #34406A;
  --primary: #141C3A;
  --primary-deep: #0F1630;
  --secondary: #7CC4FF;
  --on-secondary: #0B1020;
  --highlight: #FFE14D;

  --found: var(--secondary);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--base);
  color: var(--bp-ink);
  font-family: var(--bp-text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

#map { position: fixed; inset: 0 var(--panel-w) 0 0; }

/* ---------- panel ---------- */

#panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  background: var(--primary);
  border-left: var(--bp-hair) solid rgba(255, 255, 255, 0.08);
  font-size: 14px;

  /* Light-on-dark text and rule ramp for everything inside the sidebar. */
  --bp-ink: #FFFFFF;
  --bp-ink-2: rgba(255, 255, 255, 0.82);
  --bp-ink-3: rgba(255, 255, 255, 0.66);
  --bp-rule: rgba(255, 255, 255, 0.12);
  --bp-rule-soft: rgba(255, 255, 255, 0.08);
  --bp-rule-hard: rgba(255, 255, 255, 0.28);
  --bp-hover-1: rgba(255, 255, 255, 0.05);
  --bp-hover-2: rgba(255, 255, 255, 0.10);
  color: var(--bp-ink);
}

#panel > * { border-bottom: var(--bp-hair) solid var(--bp-rule); }
#panel > :last-child { border-bottom: 0; }

.sheet-handle { display: none; }

.panel-head { padding: var(--bp-6) var(--bp-6) var(--bp-5); }

.eyebrow {
  margin: 0;
  font-size: 11.5px;
  font-weight: var(--bp-w-label);
  letter-spacing: var(--bp-tr-label);
  text-transform: uppercase;
  color: var(--bp-ink-3);
}

h1 {
  margin: 0;
  font-family: var(--bp-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: var(--bp-tr-head);
  line-height: 1.2;
}

.score { padding: var(--bp-6); }

.score-pct {
  font-family: var(--bp-display);
  font-size: 48px;
  font-weight: 700;
  color: var(--secondary);
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score-pct .unit { margin-left: 2px; }

.score-caption { margin: var(--bp-2) 0 0; font-size: 15.5px; color: var(--bp-ink-2); }

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: var(--bp-5) 0 0;
  border-top: var(--bp-hair) solid var(--bp-rule-soft);
}
.score-row > div { padding-top: var(--bp-4); display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.score-row > div + div { border-left: var(--bp-hair) solid var(--bp-rule-soft); padding-left: var(--bp-4); }
.score-row dt { font-size: 12.5px; color: var(--bp-ink-3); }
.score-row dd { margin: 0 0 2px; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- list ---------- */

.list-section { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--bp-4) var(--bp-6);
  border-bottom: var(--bp-hair) solid var(--bp-rule-soft);
}

.segmented { display: flex; border: var(--bp-hair) solid var(--bp-rule-hard); border-radius: var(--bp-r-1); }
.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 11px;
  font-size: 13px;
  color: var(--bp-ink-2);
  transition: background var(--bp-dur-1) var(--bp-ease), color var(--bp-dur-1) var(--bp-ease);
}
.segmented button + button { border-left: var(--bp-hair) solid var(--bp-rule-hard); }
.segmented button:hover { background: var(--bp-hover-2); }
.segmented button[aria-selected="true"] { background: var(--secondary); color: var(--on-secondary); font-weight: 600; }

#list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 0 1 auto; }

#list li {
  display: flex;
  justify-content: space-between;
  gap: var(--bp-3);
  padding: 9px var(--bp-6);
  font-size: 15.5px;
  border-bottom: var(--bp-hair) solid var(--bp-rule-soft);
  cursor: pointer;
  transition: background var(--bp-dur-1) var(--bp-ease);
}
#list li:hover, #list li.hover { background: var(--bp-hover-1); }
#list li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list li .share { color: var(--bp-ink-3); font-variant-numeric: tabular-nums; flex-shrink: 0; }
#list li.latest { background: var(--primary-deep); }
#list li.latest .name { color: var(--secondary); font-weight: 600; }

.empty { margin: 0; padding: var(--bp-5) var(--bp-6); font-size: 15.5px; color: var(--bp-ink-3); }
.empty[hidden] { display: none; }

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: var(--bp-4) var(--bp-6);
  color: var(--bp-ink-2);
}

.ghost {
  border: var(--bp-hair) solid var(--bp-rule-hard);
  border-radius: var(--bp-r-1);
  background: transparent;
  padding: 6px 14px;
  color: var(--bp-ink-2);
  transition: background var(--bp-dur-1) var(--bp-ease);
}
.ghost:hover { background: var(--bp-hover-2); color: var(--bp-ink); }

.foot-actions { display: flex; gap: var(--bp-2); }

/* ---------- transfer dialog ---------- */

.transfer {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: var(--bp-hair) solid rgba(255, 255, 255, 0.12);
  border-radius: var(--bp-r-2);
  background: var(--primary);
  box-shadow: none;
  color: var(--bp-ink);

  --bp-ink: #FFFFFF;
  --bp-ink-2: rgba(255, 255, 255, 0.82);
  --bp-ink-3: rgba(255, 255, 255, 0.66);
  --bp-rule-soft: rgba(255, 255, 255, 0.16);
  --bp-rule-hard: rgba(255, 255, 255, 0.45);
  --bp-hover-2: rgba(255, 255, 255, 0.14);
}
.transfer::backdrop { background: rgba(6, 10, 22, 0.7); }

.transfer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: var(--bp-4) var(--bp-5);
  border-bottom: var(--bp-hair) solid var(--bp-rule-soft);
}
.transfer-head h2 {
  margin: 0;
  font-family: var(--bp-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: var(--bp-tr-head);
}
.transfer .close {
  border: 0;
  background: transparent;
  padding: 4px 8px;
  color: var(--bp-ink-3);
  font-size: 16px;
}
.transfer .close:hover { color: var(--bp-ink); }

.transfer-section { padding: var(--bp-4) var(--bp-5); border-bottom: var(--bp-hair) solid var(--bp-rule-soft); }
.transfer-section p { margin: var(--bp-2) 0 var(--bp-3); color: var(--bp-ink-2); }

.transfer-buttons { display: flex; gap: var(--bp-2); }

.transfer textarea {
  display: block;
  width: 100%;
  margin-bottom: var(--bp-3);
  padding: 10px 12px;
  border: var(--bp-hair) solid var(--bp-rule-hard);
  border-radius: var(--bp-r-1);
  background: var(--primary-deep);
  color: var(--bp-ink);
  font: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
}
.transfer textarea:focus { border-color: var(--secondary); }
.transfer textarea::placeholder { color: var(--bp-ink-3); }

.primary {
  border: var(--bp-hair) solid var(--secondary);
  border-radius: var(--bp-r-1);
  background: var(--secondary);
  color: var(--on-secondary);
  padding: 6px 14px;
  font-weight: 600;
  transition: opacity var(--bp-dur-1) var(--bp-ease);
}
.primary:hover { opacity: 0.88; }

.confirm { width: min(340px, calc(100vw - 32px)); }
.confirm form { margin: 0; padding: var(--bp-5); }
.confirm h2 {
  margin: 0 0 var(--bp-5);
  font-family: var(--bp-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: var(--bp-tr-head);
}
.confirm .transfer-buttons { justify-content: flex-end; }

.danger {
  border: var(--bp-hair) solid #FF6B6B;
  border-radius: var(--bp-r-1);
  background: #FF6B6B;
  color: var(--on-secondary);
  padding: 6px 14px;
  font-weight: 600;
  transition: opacity var(--bp-dur-1) var(--bp-ease);
}
.danger:hover { opacity: 0.88; }

.transfer-status { margin: 0; padding: var(--bp-3) var(--bp-5); min-height: 1.45em; color: var(--bp-ink-2); }
.transfer-status:empty { display: none; }

/* ---------- guess input ---------- */

.guess {
  position: fixed;
  left: calc((100vw - var(--panel-w)) / 2);
  bottom: 48px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - var(--panel-w) - 32px));
  margin: 0;
  border: var(--bp-hair) solid rgba(255, 255, 255, 0.22);
  border-radius: var(--bp-r-2);
  background: var(--primary);
}

.guess input {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 16px 20px;
  font: inherit;
  font-family: var(--bp-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  text-align: center;
  color: #FFFFFF;
  caret-color: var(--secondary);
  outline: none;
}
.guess input::placeholder { color: rgba(255, 255, 255, 0.55); font-family: var(--bp-text); font-size: 19px; font-weight: 500; letter-spacing: 0.06em; }
.guess:focus-within { border-color: var(--secondary); }

.feedback {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(100% + 12px);
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  text-align: center;
  color: #FFFFFF;
  text-shadow: 0 1px 0 var(--base), 0 0 12px var(--base);
  opacity: 0;
  transition: opacity var(--bp-dur-2) var(--bp-ease);
  pointer-events: none;
}
.feedback.show { opacity: 1; }

.guess.shake { animation: shake 320ms var(--bp-ease-io); }
@keyframes shake {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translateX(calc(-50% - 6px)); }
  75% { transform: translateX(calc(-50% + 6px)); }
}

/* ---------- map overlays ---------- */

.tooltip {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
  padding: 6px 10px;
  font-size: 15px;
  font-weight: 600;
  background: var(--secondary);
  color: var(--on-secondary);
  border-radius: var(--bp-r-1);
  white-space: nowrap;
}
.tooltip .share { color: rgba(11, 16, 32, 0.68); font-weight: 500; margin-left: 6px; font-variant-numeric: tabular-nums; }

.loading {
  position: fixed;
  inset: 0 var(--panel-w) 0 0;
  display: grid;
  place-items: center;
  font-size: 19px;
  color: var(--bp-ink-3);
  pointer-events: none;
}
.loading[hidden] { display: none; }

.maplibregl-ctrl-attrib.maplibregl-compact,
.maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--base-raised) 85%, transparent); color: var(--bp-ink-3); }
.maplibregl-ctrl-attrib a { color: var(--bp-ink-2); }
.maplibregl-ctrl-group { background: var(--base-raised); border: var(--bp-hair) solid var(--boundary); border-radius: var(--bp-r-2); box-shadow: none; overflow: hidden; }
.maplibregl-ctrl-group button { width: 44px; height: 44px; }
.maplibregl-ctrl-group button + button { border-top: var(--bp-hair) solid var(--boundary); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-scale { background: transparent; border-color: var(--bp-ink-3); color: var(--bp-ink-3); }

/* ---------- small screens: bottom sheet ---------- */

@media (max-width: 720px) {
  /* Phones: the score is a strip at the top that drops down to show stats and the list; the guess input is
     a bar at the bottom that rides above the on-screen keyboard (--kb, set from the visual viewport). */
  :root { --sheet-peek: 80px; --bottombar: 66px; --kb: 0px; --vv-top: 0px; --vv-height: 100vh; }

  body::before {
    content: "";
    position: fixed;
    left: 0; right: 0;
    bottom: var(--kb);
    height: var(--bottombar);
    z-index: 1;
    background: var(--primary);
    border-top: var(--bp-hair) solid rgba(255, 255, 255, 0.08);
  }

  #map, .loading { inset: var(--sheet-peek) 0 var(--bottombar) 0; }

  .guess {
    top: auto; left: 12px; right: 12px;
    bottom: calc(var(--kb) + 10px);
    z-index: 3;
    width: auto;
    transform: none;
    background: var(--base);
  }
  .guess input { font-size: 18px; padding: 11px 14px; }
  .guess input::placeholder { font-size: 15px; }
  .guess.shake { animation-name: shake-docked; }
  .feedback { font-size: 16px; }

  #panel {
    top: var(--vv-top); bottom: auto;
    width: 100%;
    height: var(--sheet-peek);
    overflow: hidden;
    border-left: 0;
    border-bottom: var(--bp-hair) solid rgba(255, 255, 255, 0.08);
    z-index: 2;
    transition: height var(--bp-dur-3) var(--bp-ease);
  }
  #panel.open { height: min(70vh, calc(var(--vv-height) - var(--bottombar) - 16px)); }

  /* The score strip is the toggle; the grabber sits on the panel's lower edge. */
  .sheet-handle {
    display: block;
    position: absolute;
    top: 0; left: 0; right: 0;
    height: var(--sheet-peek);
    z-index: 1;
    border: 0 !important;
    background: transparent;
  }
  #panel::after {
    content: "";
    position: absolute;
    bottom: 6px; left: 50%;
    width: 36px; height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--bp-rule-hard);
  }

  .panel-head { display: none; }
  .score {
    flex-shrink: 0;
    padding: 20px 16px 16px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: baseline;
    column-gap: 12px;
  }
  .score-pct { font-size: 36px; }
  .score-caption { margin: 0; }
  .score-row { grid-column: 1 / -1; }
  #panel:not(.open) .score-row { visibility: hidden; }
  .panel-foot { padding-bottom: 20px; }
  .list-head, #list li, .empty, .panel-foot { padding-left: 16px; padding-right: 16px; }

  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-scale { display: none; }
  .maplibregl-ctrl-bottom-left { top: 0; bottom: auto; }
}

@keyframes shake-docked {
  0%, 100% { transform: none; }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  .guess.shake { animation: none; }
  #panel { transition: none; }
}
