*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f2e8cf;
  --surface: #ede0bd;
  --border: #3a3226;
  --accent: #c0392b;
  --text: #2b2620;
  --text-muted: #6b6152;
  --state-fill: #e7d9ae;
  --state-stroke: #3a3226;
  --panel-width: 380px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Patrick Hand', cursive;
  font-size: 1.05rem;
  overflow: hidden;
}

/* Paper-fiber grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.09;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

/* Vignette overlay — soft aged-paper edges, much lighter than the dark theme */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 48%, transparent 55%, rgba(110, 90, 50, 0.22) 100%);
}

/* Header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 16px 24px 8px;
  pointer-events: none;
}

header::before {
  content: '';
  position: absolute;
  inset: 0;
  height: 110px;
  background: linear-gradient(to bottom, rgba(242,232,207,0.96) 0%, transparent 100%);
  z-index: -1;
}

.header-inner {
  text-align: center;
}

.header-inner h1 {
  font-family: 'Caveat', cursive;
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  transform: rotate(-1.5deg);
  display: inline-block;
}

.header-inner .subtagline {
  font-size: 1rem;
  color: var(--text-muted);
  margin-top: 0;
  letter-spacing: 0.01em;
}

.header-inner .subtagline-italic {
  font-style: normal;
  color: var(--accent);
  margin-top: 2px;
}

/* Theme picker — tapping "Map" in the title reveals a style switcher.
   header has pointer-events:none, so the trigger opts itself back in. */
#theme-trigger {
  pointer-events: auto;
  cursor: pointer;
  border-bottom: 1px dotted transparent;
  transition: border-color 0.2s;
}

#theme-trigger:hover,
#theme-trigger:focus-visible {
  border-bottom-color: currentColor;
}

.theme-picker {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px 8px 14px 6px;
  padding: 6px;
  min-width: 160px;
  box-shadow: 4px 4px 0 rgba(43, 38, 32, 0.15);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-picker.hidden {
  display: none;
}

.theme-option {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: 'Patrick Hand', cursive;
  font-size: 0.95rem;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.theme-option:hover {
  background: var(--border);
  color: var(--bg);
}

.theme-option.active {
  color: var(--accent);
  font-weight: 700;
}

/* Main layout */
main {
  height: 100vh;
}

/* Map */
#map-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* The runtime "water" rect (app.js sets fill via .attr(), which CSS
   presentation-attribute rules always lose to) — retint it pale paper-blue.
   Direct-child selector only, so this doesn't also catch the .city-label-bg
   rects nested inside .city-marker groups elsewhere in #map. */
#map > rect {
  fill: #cfd8bf;
}

.state {
  fill: var(--state-fill);
  stroke: var(--state-stroke);
  stroke-width: 1.2px;
  stroke-linejoin: round;
  filter: url(#sketch-wobble);
}

.state-border {
  fill: none;
  stroke: var(--border);
  stroke-width: 1.6px;
  stroke-linecap: round;
  filter: url(#sketch-wobble);
  vector-effect: non-scaling-stroke;
}

.nation-border {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.5px;
  stroke-linecap: round;
  filter: url(#sketch-wobble);
  vector-effect: non-scaling-stroke;
}

/* City markers */
.city-marker {
  cursor: pointer;
}

.city-hitarea {
  fill: transparent;
  stroke: none;
}

.city-dot {
  fill: var(--accent);
  stroke: var(--text);
  stroke-width: 2px;
  filter: url(#sketch-wobble);
  transition: r 0.15s ease;
}

.city-pulse {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5px;
  opacity: 0;
  animation: pulse 2.5s ease-out infinite;
}

@keyframes pulse {
  0% { r: 6px; opacity: 0.8; }
  100% { r: 22px; opacity: 0; }
}

.city-marker:hover .city-dot {
  r: 8px;
  fill: #e0704f;
}

.city-marker.active .city-dot {
  fill: #1db954;
  stroke: var(--text);
  stroke-width: 3px;
}

.city-marker.active .city-pulse {
  stroke: #1db954;
}

.city-label-bg {
  fill: var(--surface);
  opacity: 0.4;
  pointer-events: none;
}

.city-label {
  fill: var(--text);
  font-family: 'Kalam', cursive;
  font-size: 16px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  opacity: 0.9;
  letter-spacing: 0.01em;
}

/* Map hint — now a real button that opens a random city. Lives inside
   .header-inner, centered under the subtagline; header has pointer-events:
   none so this opts itself back in, same pattern as #theme-trigger. */
#map-hint {
  display: inline-block;
  margin-top: 14px;
  pointer-events: auto;
  background: none;
  border: none;
  padding: 0;
  font-family: 'Caveat', cursive;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 1.5px 1.5px 0 rgba(43, 38, 32, 0.3);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: opacity 0.4s, transform 0.15s;
  transform: rotate(-2deg);
}

#map-hint:hover,
#map-hint:focus-visible {
  transform: rotate(-2deg) scale(1.08);
}

#map-hint:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 4px;
  border-radius: 4px;
}

#map-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Player panel */
#player-panel {
  position: fixed;
  right: 0;
  top: 0;
  width: var(--panel-width);
  height: 100vh;
  background: var(--surface);
  border-left: 3px dashed var(--border);
  box-shadow: -6px 0 0 rgba(43, 38, 32, 0.06);
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 5;
}

#player-panel.hidden {
  transform: translateX(100%);
}

/* Player header */
#player-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 90px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 42vh;
  overflow-y: auto;
}

#city-name {
  font-family: 'Caveat', cursive;
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--accent);
}

#city-state {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#city-tagline-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 10px;
}

#city-tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}

/* Venues section */
#venues-section {
  display: none;
  margin-top: 10px;
}

#venues-section.visible {
  display: block;
}

#venues-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

#venues-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#venues-list a {
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.15s;
}

#venues-list a:hover {
  opacity: 0.75;
}

#close-player {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-left: 8px;
  transition: color 0.15s;
}

#close-player:hover {
  color: var(--text);
}

/* Spotify embed */
#spotify-embed {
  flex: 1;
  width: 100%;
  border: none;
  display: block;
}

/* ── Mobile ─────────────────────────────────────────────────────────────────*/
@media (max-width: 768px) {
  /* Header content wraps taller here (bigger Caveat/Patrick Hand fonts,
     subtagline wraps to 2 lines, plus the #map-hint button below it) than
     the base 110px scrim was sized for — extend it so nothing sits
     unscrimmed directly over the map. */
  header::before {
    height: 170px;
  }

  /* Labels stay hidden by default (too crowded at the base zoom level) but
     reveal once zoomed in enough that they won't overlap — see the
     'label-visible' class toggled in app.js's zoom handler. */
  .city-label,
  .city-label-bg {
    display: none;
  }

  .city-marker.label-visible .city-label,
  .city-marker.label-visible .city-label-bg {
    display: block;
  }

  /* Smaller dots and tighter hit areas on mobile */
  .city-dot {
    r: 3.5px;
  }

  .city-pulse {
    r: 3.5px;
  }

  .city-hitarea {
    r: 10px;
  }

  /* Hint text — smaller and less prominent */
  #map-hint {
    font-size: 0.65rem;
    margin-top: 10px;
  }

  /* Player panel becomes a bottom sheet instead of a side drawer */
  #player-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 78vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    transform: translateY(0);
  }

  #player-panel.hidden {
    transform: translateY(100%);
  }

  #player-header {
    padding: 20px 16px 16px;
  }

  /* Request button — move up so it clears the bottom sheet */
  #request-btn {
    bottom: 16px;
    left: 16px;
  }
}

/* Icon links (newsletter) */
#icon-links {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: opacity 0.2s ease;
}

#icon-links button,
#icon-links a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  opacity: 1;
  cursor: pointer;
  transition: opacity 0.3s ease, color 0.15s;
}

#icon-links svg {
  display: block;
}

.icon-link-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: inherit;
}

#icon-links button:hover,
#icon-links a:hover {
  color: var(--text);
}

#icon-links .hidden {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 768px) {
  #icon-links {
    bottom: 16px;
    right: 16px;
    gap: 10px;
  }
}

/* Request button */
#request-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 20;
  background: var(--surface);
  color: var(--accent);
  border: 2px solid var(--accent);
  border-radius: 14px 8px 16px 6px;
  padding: 10px 16px;
  font-family: 'Caveat', cursive;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transform: rotate(-1deg);
  box-shadow: 3px 3px 0 rgba(43, 38, 32, 0.15);
  transition: background 0.15s, color 0.15s, opacity 0.2s ease;
}

/* Hide the floating action buttons whenever the player panel is open —
   both sit at fixed viewport corners and otherwise collide with the
   Spotify embed's own content (track rows, its login/upsell overlay, etc.) */
body.panel-open #request-btn,
body.panel-open #icon-links {
  opacity: 0;
  pointer-events: none;
}

#request-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.modal-card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px 10px 18px 8px;
  padding: 28px;
  width: 480px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  transform: rotate(-0.4deg);
  box-shadow: 5px 5px 0 rgba(43, 38, 32, 0.12);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.modal-title {
  font-family: 'Caveat', cursive;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--text);
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 22px;
}

/* Form */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.required {
  color: var(--accent);
}

input, select {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Patrick Hand', cursive;
  font-size: 1rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

input:focus, select:focus {
  border-color: var(--accent);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
  cursor: pointer;
}

.form-error {
  font-size: 0.78rem;
  color: #e05a5a;
  margin-bottom: 12px;
}

.form-error.hidden {
  display: none;
}

.btn-submit {
  width: 100%;
  background: var(--accent);
  color: #fdf6e3;
  border: 2px solid var(--text);
  border-radius: 10px 6px 12px 6px;
  padding: 11px;
  font-family: 'Caveat', cursive;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.btn-submit:hover {
  opacity: 0.88;
}

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

.form-success {
  text-align: center;
  padding: 28px 0 8px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.form-success.hidden {
  display: none;
}

.modal-footer-note {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 16px;
}

.modal-footer-note a {
  color: var(--accent);
}
