/* Night map (dark) is the default look; light theme = a snowy day. Brand tokens from
   Main Branch/Motion/src/lotka/theme.ts, Christmas accents on top. */
:root {
  --bg: #0A0F16;
  --bg-hi: #14233A;
  --land: #123A66;
  --land-line: #76CDFF;
  --text: #F0F5FA;
  --dim: rgba(240, 245, 250, 0.7);
  --sheet: #101A27;
  --sheet-line: rgba(118, 205, 255, 0.16);
  --row-hover: rgba(118, 205, 255, 0.08);
  --red: #E24B4A;
  --red-deep: #A32D2D;
  --gold: #FAC775;
  --snow: rgba(255, 255, 255, 0.75);
  --pin-ring: #FFFFFF;
  --past: rgba(240, 245, 250, 0.35);
  --sheet-max: 40dvh;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #E9F2FB;
    --bg-hi: #FFFFFF;
    --land: #FFFFFF;
    --land-line: #0073B7;
    --text: #0B1B2E;
    --dim: rgba(11, 27, 46, 0.66);
    --sheet: #FFFFFF;
    --sheet-line: rgba(0, 115, 183, 0.16);
    --row-hover: rgba(0, 115, 183, 0.06);
    --red: #D93A39;
    --red-deep: #A32D2D;
    --gold: #BA7517;
    --snow: rgba(0, 115, 183, 0.28);
    --pin-ring: #FFFFFF;
    --past: rgba(11, 27, 46, 0.3);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-hi) 0%, var(--bg) 70%);
  background-color: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 "Barlow", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Snow: two layers of CSS-only flakes, transform/opacity only ---- */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.snow::before, .snow::after {
  content: "";
  position: absolute; left: 0; right: 0; top: -100%; height: 200%;
  background-image:
    radial-gradient(2px 2px at 10% 20%, var(--snow) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 30% 60%, var(--snow) 50%, transparent 51%),
    radial-gradient(2.5px 2.5px at 55% 35%, var(--snow) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 75% 80%, var(--snow) 50%, transparent 51%),
    radial-gradient(2px 2px at 90% 10%, var(--snow) 50%, transparent 51%);
  background-size: 260px 260px;
  animation: snowfall 22s linear infinite;
}
.snow::after { background-size: 180px 180px; opacity: 0.6; animation-duration: 34s; }
@keyframes snowfall { to { transform: translateY(50%); } }

/* ---- Header ---- */
.top {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand img { width: 34px; height: 34px; object-fit: contain; }
.brand span { font: 400 26px/1 "Bebas Neue", sans-serif; letter-spacing: 0.5px; }
.brand em { font-style: normal; color: var(--gold); }
.count-chip {
  font: 600 15px/1 "Barlow Condensed", sans-serif; letter-spacing: 0.3px;
  background: var(--red-deep); color: #fff;
  padding: 7px 12px; border-radius: 999px; white-space: nowrap;
}

/* ---- Map ---- */
.map-wrap {
  position: relative; z-index: 1;
  /* The sheet takes at most the bottom 40% (--sheet-max), the map the rest under the header. */
  height: calc(100dvh - var(--sheet-max) - 64px - env(safe-area-inset-top));
  min-height: 220px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 16px;
}
.map { width: 100%; height: 100%; max-width: 720px; overflow: visible; }
.land { fill: var(--land); stroke: var(--land-line); stroke-width: 2.4; stroke-linejoin: round; }

.pin { cursor: pointer; }
.pin .hit { fill: transparent; }
.pin .dot { fill: var(--red); stroke: var(--pin-ring); stroke-width: 3; transition: transform 0.2s ease; transform-box: fill-box; transform-origin: center; }
.pin .halo { fill: none; stroke: var(--gold); stroke-width: 3; opacity: 0; transform-box: fill-box; transform-origin: center; }
.pin.past .dot { fill: var(--past); }
.pin.selected .dot { transform: scale(1.35); }
.pin.selected .halo { opacity: 1; animation: halo 1.6s ease-out infinite; }
.pin:focus { outline: none; }
.pin:focus-visible .halo { opacity: 1; }
@keyframes halo { from { transform: scale(0.8); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }

.pin-enter .dot { animation: pin-in 0.45s cubic-bezier(.2,.9,.3,1.3) var(--enter-delay, 0ms) both; }
@keyframes pin-in { from { transform: translateY(-14px) scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Bottom sheet ---- */
.sheet {
  position: fixed; z-index: 3; left: 0; right: 0; bottom: 0;
  max-width: 720px; margin: 0 auto;
  background: var(--sheet);
  border: 1px solid var(--sheet-line); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: var(--sheet-max); display: flex; flex-direction: column;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s ease;
  touch-action: pan-x;
}
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--dim); opacity: 0.5; margin: 0 auto 10px; flex: none; }
.sheet-body { overflow-y: auto; touch-action: pan-y; }
.sheet-title { font: 600 20px/1.2 "Barlow Condensed", sans-serif; margin: 0 0 8px; }
.sheet-sub { color: var(--dim); margin: 0 0 12px; font-size: 15px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--sheet-line); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 56px; padding: 8px 4px;
  background: none; border: 0; color: inherit; text-align: left; font: inherit; cursor: pointer;
  border-radius: 10px;
}
.row:active, .row:hover { background: var(--row-hover); }
.date-badge {
  flex: none; width: 46px; text-align: center; border-radius: 10px; padding: 4px 0 5px;
  background: var(--red-deep); color: #fff; line-height: 1.05;
}
.date-badge b { display: block; font: 400 22px/1 "Bebas Neue", sans-serif; }
.date-badge small { font: 600 11px/1 "Barlow Condensed", sans-serif; text-transform: uppercase; letter-spacing: 0.5px; }
.row.past .date-badge { background: var(--past); }
.row-text { min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { color: var(--dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.close {
  flex: none; width: 44px; height: 44px; margin: -6px -8px 0 0; border-radius: 50%;
  background: none; border: 0; color: var(--dim); font-size: 26px; line-height: 1; cursor: pointer;
}
.detail-line { display: flex; gap: 10px; align-items: baseline; color: var(--dim); margin: 0 0 6px; }
.detail-line span:first-child { width: 20px; text-align: center; flex: none; }
.cta {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; margin-top: 16px; border-radius: 14px;
  background: var(--red); color: #fff; text-decoration: none;
  font: 600 18px/1 "Barlow Condensed", sans-serif; letter-spacing: 0.3px;
}
.cta:active { transform: scale(0.98); background: var(--red-deep); }
.past-note { color: var(--gold); font-size: 14px; margin: 8px 0 0; }

.empty { text-align: center; padding: 8px 0 4px; }
.empty .cta { margin-top: 12px; }

.sheet-enter { animation: sheet-in 0.35s ease both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (min-width: 900px) {
  .map-wrap { height: calc(100dvh - 90px); padding-right: 400px; min-height: 0; }
  .sheet { left: auto; right: 24px; bottom: 24px; width: 360px; border-radius: 20px; border-bottom: 1px solid var(--sheet-line); max-height: calc(100dvh - 120px); }
  .grip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .snow::before, .snow::after, .pin.selected .halo, .pin-enter .dot, .sheet-enter { animation: none; }
  .sheet { transition: none; }
}
