:root {
  --paper: #f7f0e1;
  --paper-deep: #ece1c9;
  --ink: #23323a;
  --ink-soft: #52626a;
  --berry: #9c3335;
  --berry-deep: #7f2a2c;
  --pine: #25533f;
  --gold: #f2bd52;
  --glow: #ffe3a1;

  --night: #1b3042;
  --snow: #e9f0f3;

  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Nunito", ui-rounded, system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  background: var(--paper);
  color: var(--ink);
  font: 500 16px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, .map:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.map:focus-visible { outline-offset: -3px; }

/* ---------- layout ---------- */

.app {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template: "head" auto "map" minmax(0, 1fr) "cal" auto / minmax(0, 1fr);
}
.masthead { grid-area: head; }
.map { grid-area: map; }
.calendar { grid-area: cal; }
.note { display: none; grid-area: note; }

/* ---------- masthead ---------- */

.masthead {
  position: relative;
  z-index: 2;
  padding: calc(env(safe-area-inset-top) + 24px) 16px 10px;
  background: var(--berry-deep);
  color: var(--paper);
  text-align: center;
}
.kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--glow);
}
h1 {
  margin: 0;
  font: 700 clamp(24px, 7vw, 30px)/1.1 var(--display);
  letter-spacing: -.01em;
}
.intro { display: none; }

.lights {
  position: absolute;
  top: env(safe-area-inset-top);
  left: 0;
  width: 100%;
  height: 26px;
  overflow: visible;
  pointer-events: none;
}
.lights .wire { fill: none; stroke: #2b1b1a; stroke-width: 1.4; }
.lights .cap { fill: #2b1b1a; }
.lights .bulb { animation: twinkle 4.2s ease-in-out infinite; }
.lights .bulb:nth-of-type(3n) { animation-delay: -1.4s; }
.lights .bulb:nth-of-type(3n + 1) { animation-delay: -2.8s; }
@keyframes twinkle { 50% { opacity: .55; } }

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

.map {
  position: relative;
  overflow: hidden;
  background: var(--night);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.map.dragging { cursor: grabbing; }
.base, .stems, .snow, .pins {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.base, .stems, .snow { pointer-events: none; }
.pins { pointer-events: none; }

.base path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.base .green { fill: #23464a; }
.base .wood { fill: #1e3f3f; }
.base .water { fill: #35668a; }
.base .river { stroke: #35668a; stroke-width: 80; }
.base .stream { stroke: #35668a; stroke-width: 25; }
.base .building { fill: #48627a; stroke: #a9bfcd; stroke-width: 5; }
.base .building-shadow { fill: #10202f; opacity: .55; }
.base .rail-bed { stroke: #10202f; stroke-width: 55; }
.base .rail { stroke: #7d93a5; stroke-width: 34; stroke-dasharray: 6 22; stroke-linecap: butt; }
.base .casing { stroke: #122535; }
.base .casing.major { stroke-width: 140; }
.base .casing.street { stroke-width: 92; }
.base .casing.lane { stroke-width: 50; }
.base .road.major { stroke: #8da1b1; stroke-width: 112; }
.base .road.street { stroke: #6d8396; stroke-width: 68; }
.base .road.lane { stroke: #50667a; stroke-width: 32; }
.base .foot-casing { stroke: #0e1c29; }
.base .foot { stroke: #ffc766; }
.base .tree { fill: #3d7565; }
.base .tree-snow { fill: #cfe0e4; }
.base text {
  fill: #fff;
  stroke: #203649;
  stroke-width: .26em;
  stroke-linejoin: round;
  paint-order: stroke;
  font-family: var(--body);
  font-weight: 800;
  letter-spacing: .02em;
}

.stems line { stroke: var(--glow); stroke-width: 1.5; opacity: .85; }
.stems circle { fill: var(--glow); stroke: #12253f; stroke-width: 1; }
.stems circle.selected { r: 6px; stroke: #fff; stroke-width: 2.5; fill: var(--berry); }

/* ---------- window pins ---------- */

.pin {
  position: absolute;
  top: 0;
  left: 0;
  width: 30px;
  height: 36px;
  margin: -18px 0 0 -15px;
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  will-change: transform;
}
.pin::before { /* a slightly larger touch target */
  content: "";
  position: absolute;
  inset: -4px;
}
.pane {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 3px;
  border: 2.5px solid var(--frame, var(--berry));
  border-radius: 15px 15px 4px 4px;
  background: radial-gradient(circle at 50% 62%, #fff4d2 0%, #ffd979 60%, #eeab45 100%);
  color: #3d1d14;
  font: 700 15px/1 var(--display);
  font-variant-numeric: lining-nums;
  box-shadow: 0 0 0 1px #fff6, 0 3px 6px #0007;
  transition: transform .2s ease;
}
.pane::after { /* sill with a little snow on it */
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  left: -4px;
  height: 4px;
  border-radius: 4px;
  background: #fff;
}
.pin:nth-child(even) { --frame: var(--pine); }
.pin::after { /* soft breathing glow */
  content: "";
  position: absolute;
  inset: -10px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, #ffd47a99, #ffd47a00);
  animation: breathe 5s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  pointer-events: none;
}
@keyframes breathe { 0%, 100% { opacity: .25; } 50% { opacity: .9; } }
.pin:hover .pane { transform: translateY(-2px); }
.pin.selected { z-index: 3; }
.pin.selected .pane {
  transform: scale(1.28);
  transform-origin: 50% 100%;
  box-shadow: 0 0 0 3px #fff, 0 6px 14px #0009;
}
.pin.selected::after { inset: -26px; }

.you {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  z-index: 1;
  pointer-events: none;
}
.you span {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2f8cff;
  box-shadow: 0 0 0 0 #2f8cff88;
  animation: ping 2.6s ease-out infinite;
}
@keyframes ping { 70%, 100% { box-shadow: 0 0 0 18px #2f8cff00; } }

/* ---------- controls, toast, credit ---------- */

.controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 4;
  display: grid;
  gap: 8px;
}
.controls button, .close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 2px 8px #0005;
}
.controls button[aria-pressed="true"] { background: #2f8cff; color: #fff; }
.controls svg, .close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toast {
  position: absolute;
  top: 12px;
  right: 68px;
  left: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: calc(100% - 80px);
  margin-inline: auto;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 4px 14px #0006;
  font-size: 14px;
  font-weight: 700;
  animation: rise .35s ease both;
}
.toast button {
  flex: none;
  min-height: 36px;
  padding: 4px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--pine);
  color: #fff;
  font-weight: 800;
}

.credit {
  position: absolute;
  bottom: 2px;
  left: 4px;
  margin: 0;
  padding: 0 6px;
  border-radius: 6px;
  background: #0e1d2bb0;
  color: #cfdde6;
  font-size: 10px;
}
.credit a { color: inherit; }

/* ---------- window card ---------- */

.card {
  position: absolute;
  right: 10px;
  bottom: 22px;
  left: 10px;
  z-index: 6;
  display: flex;
  gap: 16px;
  max-width: 420px;
  margin-inline: auto;
  padding: 14px;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 10px 30px #0008, inset 0 0 0 1.5px #fff, inset 0 0 0 5px var(--paper), inset 0 0 0 6px var(--paper-deep);
  cursor: auto;
  animation: rise .4s cubic-bezier(.2, .9, .3, 1.15) both;
  touch-action: auto;
}
@keyframes rise { from { opacity: 0; transform: translateY(18px); } }
.close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: transparent;
  box-shadow: none;
}

.peek {
  position: relative;
  flex: none;
  width: 108px;
  height: 136px;
  margin: 2px 0 4px 2px;
  border: 5px solid var(--frame, var(--berry));
  border-radius: 54px 54px 8px 8px;
  perspective: 420px;
}
.peek::after {
  content: "";
  position: absolute;
  right: -10px;
  bottom: -11px;
  left: -10px;
  height: 9px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 4px #0003;
}
.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 49px 49px 3px 3px;
  background: radial-gradient(circle at 50% 58%, #fff6d8 0%, #ffd674 55%, #d98a35 100%);
}
.scene svg {
  position: absolute;
  inset: 22% 8% 6%;
  width: 84%;
  height: 72%;
  animation: bob 4.5s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-3px); } }
.shutter {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  overflow: hidden;
  background: var(--frame, var(--berry));
  backface-visibility: hidden;
  animation: swing .95s .35s cubic-bezier(.45, .05, .25, 1) both;
}
.shutter span {
  position: absolute;
  inset: 8px 5px 6px;
  border: 1.5px solid #fff5;
  border-radius: 3px;
}
.shutter.left { left: 0; border-radius: 49px 0 0 3px; transform-origin: left; --turn: -112deg; }
.shutter.right { right: 0; border-radius: 0 49px 3px 0; transform-origin: right; --turn: 112deg; }
.shutter.left span { border-radius: 38px 3px 3px 3px; }
.shutter.right span { border-radius: 3px 38px 3px 3px; }
.shutter::after {
  content: "";
  position: absolute;
  top: 56%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
}
.shutter.left::after { right: 5px; }
.shutter.right::after { left: 5px; }
@keyframes swing { to { transform: rotateY(var(--turn)); opacity: 0; } }

.card-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.card h2 {
  margin: 6px 32px 2px 0;
  font: 700 26px/1.1 var(--display);
  color: var(--berry);
}
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; white-space: pre-line; }
.card .distance { margin-top: 4px; color: var(--pine); font-weight: 800; }
.step {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}
.step button {
  flex: 1;
  min-height: 42px;
  border: 1.5px solid #cdbd99;
  border-radius: 12px;
  background: #fffaf0;
  font-weight: 800;
}
.step button:last-child { border-color: var(--pine); background: var(--pine); color: #fff; }
.step button:disabled { visibility: hidden; }

/* ---------- calendar ---------- */

.calendar {
  position: relative;
  z-index: 2;
  min-width: 0;
  background: var(--paper);
  box-shadow: 0 -2px 10px #0003;
}
.calendar ol {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  overflow-x: auto;
  list-style: none;
  scrollbar-width: none;
  scroll-padding-inline: 12px;
}
.calendar ol::-webkit-scrollbar { display: none; }
.calendar li { flex: none; }
.door {
  width: 48px;
  height: 54px;
  padding: 4px 0 0;
  border: 0;
  border-radius: 22px 22px 6px 6px;
  background: var(--berry);
  color: #fff;
  font: 700 19px/1 var(--display);
  font-variant-numeric: lining-nums;
  box-shadow: inset 0 0 0 3px var(--berry), inset 0 0 0 4px #fff6;
  transition: transform .2s ease;
}
.calendar li:nth-child(even) .door { background: var(--pine); box-shadow: inset 0 0 0 3px var(--pine), inset 0 0 0 4px #fff6; }
.door:hover { transform: translateY(-2px); }
.calendar li .door[aria-current="true"] {
  background: radial-gradient(circle at 50% 62%, #fff4d2, #ffd979 60%, #eeab45);
  box-shadow: 0 0 0 2.5px var(--berry-deep);
  color: #3d1d14;
}

.noscript { position: fixed; inset: 40% 20px auto; text-align: center; }

/* ---------- desktop / landscape tablet ---------- */

@media (min-width: 820px) and (min-height: 520px) {
  .app {
    grid-template:
      "head map" auto
      "cal  map" minmax(0, 1fr)
      "note map" auto
      / 340px minmax(0, 1fr);
  }
  .masthead { padding: 44px 28px 22px; }
  .lights { top: 0; }
  .kicker { font-size: 12px; }
  h1 { margin-top: 4px; font-size: 38px; }
  .intro { display: block; margin: 10px 0 0; font-size: 15px; color: #f7f0e1e6; }
  .calendar { box-shadow: none; overflow-y: auto; }
  .calendar ol {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px 8px;
    padding: 22px 24px;
    overflow: visible;
  }
  .door { width: 100%; }
  .note {
    display: block;
    position: relative;
    z-index: 2;
    padding: 0 28px 24px;
    background: var(--paper);
    font-size: 13px;
    color: var(--ink-soft);
  }
  .note p { margin: 0; padding-top: 14px; border-top: 1.5px dashed #cdbd99; }
  .note strong { display: block; font: 700 16px var(--display); color: var(--pine); }
  .card { right: 20px; bottom: 28px; left: auto; width: 400px; margin: 0; }
}

/* Short landscape phones: keep as much map as possible. */
@media (max-height: 519px) {
  .masthead { padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; }
  .kicker, .lights { display: none; }
  h1 { font-size: 20px; }
  .door { width: 42px; height: 42px; font-size: 16px; }
  .calendar ol { padding-block: 6px calc(6px + env(safe-area-inset-bottom)); }
  .card { right: auto; bottom: 18px; width: 340px; padding: 10px; }
  .peek { width: 84px; height: 104px; }
  .controls { grid-auto-flow: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .shutter { display: none; }
  .snow { display: none; }
  .pin::after { opacity: .55; }
}
