/* ---------- tokens ---------- */
:root {
  --bg:            #0b1020;
  --bg-far:        #131a33;
  --sky-glow:      rgba(120, 140, 255, 0.28);
  --ink:           #e8ecff;
  --ink-dim:       #98a2c8;
  --ink-faint:     #5b648c;

  --brick:         #1b2242;
  --brick-edge:    #2a3260;
  --roofline:      #10162e;

  --win-off:       #222a52;
  --win-off-edge:  #2d376a;
  --win-on:        #ffd479;
  --win-on-warm:   #ffb44d;
  --win-glow:      rgba(255, 196, 92, 0.55);

  --beam:          rgba(190, 205, 255, 0.10);
  --beam-edge:     rgba(190, 205, 255, 0.30);

  --accent:        #ffc95c;
  --accent-ink:    #2a1c00;

  --surface:       rgba(255, 255, 255, 0.045);
  --surface-edge:  rgba(255, 255, 255, 0.10);

  --star-opacity:  1;
  --orb-bg:        radial-gradient(circle at 34% 34%, #fdf6d8, #e8dfae 58%, #cfc596);
  --orb-glow:      rgba(250, 244, 210, 0.22);

  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="day"] {
  --bg:            #8fc0e8;
  --bg-far:        #e2eefb;
  --sky-glow:      rgba(255, 214, 140, 0.65);
  --ink:           #16203c;
  --ink-dim:       #4a577a;
  --ink-faint:     #7b87a8;

  --brick:         #d9cdb6;
  --brick-edge:    #bfb094;
  --roofline:      #a3927a;

  --win-off:       #7c8ba4;
  --win-off-edge:  #68778f;
  --win-on:        #fff0b4;
  --win-on-warm:   #ffb02e;
  --win-glow:      rgba(255, 160, 40, 0.55);

  --beam:          rgba(40, 70, 130, 0.07);
  --beam-edge:     rgba(40, 70, 130, 0.22);

  --accent:        #ff8a3d;
  --accent-ink:    #2a1000;

  --surface:       rgba(20, 35, 70, 0.045);
  --surface-edge:  rgba(20, 35, 70, 0.10);

  --star-opacity:  0;
  --orb-bg:        radial-gradient(circle at 36% 32%, #fff6cf, #ffd978 55%, #ffb64d);
  --orb-glow:      rgba(255, 200, 90, 0.35);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background 600ms ease, color 600ms ease;
}

/* ---------- sky ---------- */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(120% 80% at 50% 108%, var(--sky-glow), transparent 62%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-far) 100%);
  transition: background 600ms ease;
}

.stars {
  position: absolute;
  inset: 0;
  opacity: var(--star-opacity);
  transition: opacity 600ms ease;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 26% 9%,  #dfe6ff, transparent),
    radial-gradient(1.6px 1.6px at 41% 24%, #fff, transparent),
    radial-gradient(1.1px 1.1px at 58% 12%, #cdd8ff, transparent),
    radial-gradient(1.5px 1.5px at 71% 27%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 84% 15%, #e6ecff, transparent),
    radial-gradient(1.3px 1.3px at 93% 31%, #fff, transparent),
    radial-gradient(1.1px 1.1px at 7%  38%, #d7e0ff, transparent),
    radial-gradient(1.4px 1.4px at 34% 41%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 64% 38%, #e9eeff, transparent);
}

.orb {
  position: absolute;
  top: 8vh;
  right: 12vw;
  width: clamp(44px, 7vw, 86px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--orb-bg);
  box-shadow: 0 0 60px 24px var(--orb-glow);
  transition: background 600ms ease, box-shadow 600ms ease;
}

/* ---------- header ---------- */
.top {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 56px) 16px 0;
  text-align: center;
}

.wordmark {
  margin: 0;
  font-size: clamp(2.1rem, 7vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1;
}
.wordmark span { color: var(--accent); }

.tagline {
  margin: 10px 0 0;
  color: var(--ink-dim);
  font-size: clamp(0.94rem, 2.4vw, 1.06rem);
}

.theme-toggle {
  position: absolute;
  top: clamp(20px, 4vw, 34px);
  right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 10px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 999px;
  cursor: pointer;
  transition: color 180ms, border-color 180ms, background 180ms;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.theme-icon {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: inset -4px -2px 0 0 var(--bg);
  transition: box-shadow 300ms ease, background 300ms ease;
}
:root[data-theme="day"] .theme-icon { box-shadow: inset 0 0 0 0 var(--bg); }

/* ---------- stage ---------- */
main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

.stage { margin-top: clamp(28px, 5vw, 48px); }

.town {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(3px, 0.7vw, 8px);
  touch-action: manipulation;
}

.building {
  position: relative;
  flex: var(--w) 1 0;
  min-width: 0;
  padding-top: var(--roof);
  background: var(--brick);
  border: 1px solid var(--brick-edge);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  transition: background 600ms ease, border-color 600ms ease;
}

.building::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  top: calc(var(--roof) * 0.34);
  height: 1px;
  background: var(--roofline);
  opacity: 0.85;
}

.building[data-antenna="1"]::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 2px;
  height: 16px;
  background: var(--brick-edge);
  transform: translateX(-50%);
}

.beam {
  position: absolute;
  top: -28px;
  right: -2px;
  bottom: 0;
  left: -2px;
  border-radius: 6px;
  background: linear-gradient(180deg, transparent, var(--beam));
  border-left: 1px solid var(--beam-edge);
  border-right: 1px solid var(--beam-edge);
  opacity: 0;
  pointer-events: none;
  transition: opacity 90ms ease-out;
}
.building.is-active .beam { opacity: 1; }

.windows {
  display: grid;
  grid-template-rows: repeat(8, clamp(13px, 2.9vw, 26px));
  gap: clamp(2px, 0.5vw, 5px);
  padding: clamp(3px, 0.7vw, 7px);
}

.window {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  font: inherit;
  cursor: pointer;
  background: var(--win-off);
  border: 1px solid var(--win-off-edge);
  border-radius: 2px;
  transition: background 220ms ease, box-shadow 220ms ease, border-color 220ms ease, transform 120ms ease;
}

.window:hover { border-color: var(--accent); }

.window:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  z-index: 2;
}

.window[aria-checked="true"] {
  background: linear-gradient(160deg, var(--win-on), var(--win-on-warm));
  border-color: var(--win-on);
  box-shadow: 0 0 10px 1px var(--win-glow);
}

.window.is-ringing { animation: ring 620ms ease-out; }

@keyframes ring {
  0%   { transform: scale(1);    box-shadow: 0 0 10px 1px var(--win-glow); }
  18%  { transform: scale(1.22); box-shadow: 0 0 22px 7px var(--win-glow); }
  100% { transform: scale(1);    box-shadow: 0 0 10px 1px var(--win-glow); }
}

.street {
  height: clamp(18px, 3.4vw, 30px);
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, var(--roofline), transparent);
  opacity: 0.9;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px 22px;
  margin-top: clamp(24px, 4vw, 38px);
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
}

.btn {
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: transform 120ms ease, background 180ms, color 180ms, border-color 180ms;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.btn-play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 22px 11px 18px;
  font-size: 0.98rem;
  color: var(--accent-ink);
  background: var(--accent);
}
.btn-play:hover { filter: brightness(1.07); }

.icon-play {
  width: 0;
  height: 0;
  border-left: 11px solid currentColor;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}
.btn-play[aria-pressed="true"] .icon-play {
  width: 12px;
  height: 13px;
  border: none;
  background:
    linear-gradient(currentColor, currentColor) left / 4px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right / 4px 100% no-repeat;
}

.btn-ghost {
  padding: 9px 16px;
  font-size: 0.86rem;
  color: var(--ink-dim);
  background: transparent;
  border-color: var(--surface-edge);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--accent); }

.dials {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: center;
}

.dial { display: grid; gap: 5px; }

.dial-name {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: clamp(92px, 16vw, 132px);
  height: 4px;
  border-radius: 999px;
  background: var(--surface-edge);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

select {
  font: inherit;
  font-size: 0.86rem;
  padding: 6px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 8px;
  cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.hint {
  margin: 16px auto 0;
  max-width: 46ch;
  text-align: center;
  font-size: 0.84rem;
  color: var(--ink-faint);
  line-height: 1.6;
}

kbd {
  font: inherit;
  font-size: 0.78em;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
}

/* ---------- footer ---------- */
.bottom {
  max-width: 1080px;
  margin: clamp(40px, 8vw, 76px) auto 0;
  padding: 22px 16px clamp(28px, 6vw, 46px);
  text-align: center;
  font-size: 0.82rem;
  color: var(--ink-faint);
  line-height: 1.7;
}
.bottom p { margin: 0; }
.colophon { margin-top: 4px; opacity: 0.75; }
.bottom a { color: inherit; text-decoration-color: var(--surface-edge); }
.bottom a:hover { color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 16px);
  padding: 9px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.is-up { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .controls { gap: 12px; }
  .theme-toggle { padding: 8px; }
  .theme-toggle .theme-label { display: none; }

  /* Claw back every pixel of width so the windows stay tappable,
     and buy height where the screen is happy to give it. */
  .stage { margin-inline: -8px; }
  .town { gap: 2px; }
  .windows {
    grid-template-rows: repeat(8, 22px);
    gap: 2px;
    padding: 2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Touch painting: opt-in, because it has to take the drag away from scrolling. */
.town.paint-mode { touch-action: none; }
.btn-ghost[aria-pressed="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

/* "Sound on" cue — sits directly above the play button so it is read at the
   moment of clicking, then retires once the town has actually been heard. */
.sound-cue {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: fit-content;
  margin: clamp(20px, 3.5vw, 30px) auto 0;
  padding: 7px 16px 7px 13px;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: 999px;
  animation: cue-breathe 2.8s ease-in-out infinite;
  transition: opacity 500ms ease, transform 500ms ease;
}

.sound-cue svg { flex: none; }

@keyframes cue-breathe {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50%      { box-shadow: 0 0 14px 1px var(--win-glow); }
}

.sound-cue.is-retired {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}
