:root {
  --bg: #f2f6fb;
  --panel-bg: #ffffff;
  --ink: #182735;
  --muted: #5a6979;
  --line: #d4deea;
  --line-strong: #aebfd1;
  --surface: #eef4fb;
  --good: #1e8d4a;
  --bad: #c93136;
  --label-stroke: #f5f8fc;
  --focus: #0e64b3;
  --accent: #0e64b3;
  --accent-strong: #0b4f8d;
  --accent-soft: #dcecff;
  --hint: #0d7d63;
  --hint-soft: #d9f2ea;
  --reveal: #975c00;
  --reveal-soft: #fff0d3;
  --sunset-amber: #ffb347;
  --sunset-peach: #ffd08a;
  --sunset-rose: #ff6b4a;
  --sunset-mauve: #ff4e1a;
  --sunset-indigo: #7a2a00;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'IBM Plex Sans', 'Avenir Next', 'Segoe UI', sans-serif;
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 410px) 1fr;
  min-height: 0;
}

.topbar {
  background: linear-gradient(180deg, #fbfdff 0%, #f6f9fd 100%);
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.title-block {
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent-strong);
}

.subtitle {
  margin: 7px 0 0;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--muted);
}

.panel-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-bg);
  padding: 11px;
  margin: 0 0 10px;
  box-shadow: 0 1px 0 rgba(10, 40, 74, 0.03);
}

.card-label {
  margin: 0 0 7px;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: #4d6178;
}

.scope-panel {
  background: var(--surface);
  border-color: #c8daee;
}

.scope-top {
  display: block;
}

.scope-label {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-strong);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.btn:focus-visible,
.mobile-menu-btn:focus-visible,
#guess-input:focus-visible,
.scope-chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.btn {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #f8fbff;
  color: var(--ink);
  padding: 9px 10px;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: #7f98b4;
  background: #eef5fd;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.mini {
  padding: 6px 8px;
  font-size: 0.78rem;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn.primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn.reveal {
  background: var(--reveal-soft);
  border-color: #e3c48b;
  color: #6f4300;
}

.btn.reveal:hover {
  border-color: #c4954b;
  background: #ffe8ba;
}

#guess-form button[type='submit'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

#guess-form button[type='submit']:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

#new-round-btn {
  background: var(--accent-soft);
  border-color: #aac6e8;
  color: var(--accent-strong);
}

#new-round-btn:hover {
  background: #cce1fb;
  border-color: #85acd8;
}

#daily-round-btn {
  background: #e6edff;
  border-color: #b0bde8;
  color: #293f82;
}

#daily-round-btn:hover {
  background: #d5e0ff;
  border-color: #8e9fdb;
}

#hint-btn {
  background: var(--hint-soft);
  border-color: #9fceb9;
  color: #0a5e4b;
}

#hint-btn:hover {
  background: #c7eadf;
  border-color: #71b49a;
}

.scope-groups {
  margin-top: 8px;
  display: grid;
  gap: 8px;
}

.scope-group {
  display: grid;
  gap: 5px;
}

.scope-group-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #50657e;
}

.scope-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#scope-town-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

#scope-postcode-chips {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
}

.scope-chip {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  border: 1px solid #b2c2d3;
  background: #f8fbff;
  color: #243446;
  border-radius: 999px;
  min-height: 28px;
  padding: 4px 10px;
  font-size: 0.78rem;
  line-height: 1.1;
  cursor: pointer;
}

.scope-chip-label {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateY(-0.5px);
}

.scope-chip-icon {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: 0 0 auto;
}

.scope-chip.town-chip {
  width: 100%;
  min-height: 36px;
  padding: 6px 13px;
  font-size: 0.86rem;
  font-weight: 600;
  gap: 8px;
  justify-content: flex-start;
}

.scope-chip.scope-all-chip {
  width: 100%;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.86rem;
  font-weight: 600;
  justify-content: center;
}

.scope-chip.town-chip .scope-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-chip.town-chip .scope-chip-icon {
  width: 20px;
  height: 20px;
}

#scope-postcode-chips .scope-chip {
  width: 100%;
  min-height: 28px;
  padding: 3px 6px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.scope-chip:hover {
  border-color: #7a9cbc;
  background: #edf4fc;
}

.scope-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.scope-chip.town-chip.active {
  background: #f8fbff;
  color: #243446;
  border-color: var(--accent);
  border-width: 2px;
  box-shadow: inset 0 0 0 1px rgba(14, 100, 179, 0.18);
}

.scope-chip.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.scope-help {
  margin: 7px 0 0;
  min-height: 0;
  font-size: 0.79rem;
  line-height: 1.28;
  color: var(--muted);
}

.target-card {
  padding-top: 10px;
  padding-bottom: 10px;
  border-color: #c5d8ed;
  min-height: 84px;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: start;
}

.targets {
  margin: 0;
  font-size: 0.99rem;
  line-height: 1.34;
  font-weight: 650;
  min-height: 2.68em;
  max-height: 2.68em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
}

.target-card.menu-only {
  display: none;
}

.targets-inline {
  margin-bottom: 6px;
  min-height: 1.4em;
  max-height: none;
  overflow: visible;
  -webkit-line-clamp: unset;
}

#guess-form {
  display: grid;
  gap: 8px;
}

.input-wrap {
  position: relative;
}

#guess-input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 0.98rem;
  color: var(--ink);
  background: #ffffff;
}

#guess-input::placeholder {
  color: #8393a5;
}

.action-row {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.action-row .btn {
  flex: 1 1 0;
}

.action-row-bottom .btn {
  flex: 1 1 calc(50% - 4px);
}

.action-row-daily .btn {
  flex: 1 1 0;
}

.action-row-daily .btn:only-child {
  flex: 1 1 100%;
}

.meta-card {
  background: #f8fbff;
  border-color: #cbdaea;
}

.feedback,
.status {
  margin: 0;
  min-height: 1.15em;
  font-size: 0.88rem;
  line-height: 1.35;
}

.feedback.is-empty {
  display: none;
  min-height: 0;
}

.status {
  margin-top: 6px;
  color: var(--muted);
}

.status.is-empty {
  display: none;
  min-height: 0;
  margin-top: 0;
}

.feedback.is-empty + .status {
  margin-top: 0;
}

.feedback.good {
  color: var(--good);
  font-weight: 620;
}

.feedback.bad {
  color: var(--bad);
  font-weight: 620;
}

.feedback.info {
  color: var(--accent-strong);
}

.site-footer {
  margin-top: 2px;
  padding: 2px 2px 0;
  display: flex;
  justify-content: center;
}

.site-footer-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #3d5875;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.site-footer-link:hover {
  color: #1f4d7a;
  text-decoration: underline;
}

.site-footer-icon {
  width: 17px;
  height: 17px;
  object-fit: contain;
  flex: 0 0 auto;
}

.map-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #fcfdff;
}

/* Confetti celebration */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10010;
  opacity: 0;
}

.confetti-layer.is-active {
  opacity: 1;
}

.confetti-piece {
  display: block;
  position: absolute;
  top: -8vh;
  left: 0;
  width: var(--size, 8px);
  height: calc(var(--size, 8px) * 0.62);
  border-radius: 2px;
  opacity: 0.95;
  transform: translate3d(var(--x, 50vw), -12vh, 0) rotate(0deg);
  will-change: transform, opacity;
  animation: confetti-fall var(--dur, 2.8s) linear var(--delay, 0s) forwards;
}

@keyframes confetti-fall {
  from {
    transform: translate3d(var(--x, 50vw), -12vh, 0) rotate(0deg);
  }
  to {
    transform: translate3d(calc(var(--x, 50vw) + var(--drift, 0px)), 112vh, 0) rotate(var(--rot, 720deg));
    opacity: 0.98;
  }
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(13, 31, 51, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 120;
}

.dialog-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.dialog-card {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 14px 28px rgba(15, 42, 73, 0.22);
}

.dialog-text {
  margin: 0;
  font-size: 0.97rem;
  line-height: 1.4;
  color: var(--ink);
}

.dialog-actions {
  margin-top: 12px;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dialog-actions .btn {
  width: 100%;
}

@media (max-width: 520px) {
  .dialog-actions {
    grid-template-columns: 1fr;
  }
}

.mobile-menu-btn {
  display: none;
}

#map-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
  cursor: grab;
  touch-action: none;
}

#map-canvas.dragging {
  cursor: grabbing;
}

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid #c0d2e5;
  border-radius: 10px;
  background: #fff;
  max-height: 260px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 10px 20px rgba(21, 49, 81, 0.12);
}

.suggestions.hidden {
  display: none;
}

.suggestion-item {
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.93rem;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: #e8f2fd;
}

.suggestion-town {
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 1080px) {
  .app {
    grid-template-columns: 355px 1fr;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .topbar {
    position: fixed;
    inset: 0;
    height: 100dvh;
    border: 0;
    padding: 0;
    max-height: none;
    background: transparent;
    overflow: hidden;
    pointer-events: none;
    z-index: 12;
  }

  .panel-card {
    padding: 10px;
  }

  .topbar .menu-only {
    display: none !important;
  }

  #guess-form {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    margin: 0;
    pointer-events: auto;
    z-index: 15;
    background: rgba(255, 255, 255, 0.96);
    border-color: #c5d8ed;
    box-shadow: 0 10px 22px rgba(18, 44, 73, 0.18);
  }

  #guess-form .targets-inline {
    display: none;
  }

  .action-row {
    flex-wrap: nowrap;
  }

  .action-row .btn {
    flex: 1 1 0;
    min-width: 0;
  }

  #reveal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-menu-btn {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    z-index: 30;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #aac3dc;
    border-radius: 10px;
    background: rgba(250, 253, 255, 0.94);
    color: #193754;
    min-height: 42px;
    padding: 8px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    box-shadow: 0 6px 16px rgba(15, 42, 73, 0.16);
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
  }

  .map-shell {
    min-height: 100dvh;
  }

  body.mobile-menu-open .topbar {
    background: rgba(246, 250, 254, 0.985);
    padding: calc(env(safe-area-inset-top, 0px) + 54px) 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    overscroll-behavior: contain;
  }

  body.mobile-menu-open .topbar .menu-only {
    display: block !important;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
  }

  body.mobile-menu-open .topbar .target-card.menu-only {
    display: grid !important;
  }

  body.mobile-menu-open .title-block .subtitle {
    display: none;
  }

  body.mobile-menu-open #guess-form {
    display: none;
  }

  body.mobile-menu-open .mobile-menu-btn {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }

  body.mobile-menu-open {
    overflow: hidden;
  }
}
