:root {
  --sky-top: #161a3b;
  --sky-middle: #723c69;
  --sky-bottom: #f58b5c;
  --glow: #ffbd6e;
  --water-top: #433d62;
  --water-bottom: #172439;
  --hill: #332e4f;
  --cloud: #252846;
  --cloud-front: #4b3b58;
  --far-building: #172036;
  --mid-building: #20283a;
  --mid-building-2: #283147;
  --bridge: #1b2436;
  --bridge-light: #ffbd6e;
  --window-on: #ffd36a;
  --window-off: #253148;
  --window-opacity: .9;
  --lamp-opacity: .92;
  --star-opacity: .72;
  --sun-opacity: .12;
  --moon-opacity: .95;
  --scene-brightness: .92;
  --scene-saturation: 1.05;
  --ui-bg: rgba(11, 14, 22, .72);
  --ui-border: rgba(255, 255, 255, .12);
  --ui-text: #f8f6f0;
  --ui-muted: rgba(255, 255, 255, .58);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b0f1c;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ui-text);
}

button, input { font: inherit; }

.city-app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  background: var(--sky-bottom);
}

.sky,
.sky-glow,
.stars,
.celestial,
.city-scene,
.grain {
  position: absolute;
  inset: 0;
}

.sky {
  z-index: -5;
  background:
    radial-gradient(circle at 50% 78%, color-mix(in srgb, var(--glow) 52%, transparent), transparent 30%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-middle) 54%, var(--sky-bottom) 100%);
  transition: background 240ms linear;
}

.sky-glow {
  z-index: -4;
  background: radial-gradient(circle at 48% 54%, color-mix(in srgb, var(--glow) 45%, transparent), transparent 34%);
  opacity: .78;
  transition: opacity 240ms linear;
}

.stars {
  z-index: -3;
  opacity: var(--star-opacity);
  transition: opacity 240ms linear;
}

.star {
  position: absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: rgba(255, 255, 255, var(--alpha));
  box-shadow: 0 0 8px rgba(255,255,255,.5);
  animation: twinkle var(--duration) ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { transform: scale(.72); opacity: .42; }
  to { transform: scale(1.18); opacity: 1; }
}

.celestial {
  z-index: -2;
  pointer-events: none;
}

.sun,
.moon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(54px, 6vw, 92px);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 220ms linear;
  will-change: transform, opacity;
}

.sun {
  background: #ffd36b;
  box-shadow: 0 0 45px rgba(255, 197, 94, .95), 0 0 120px rgba(255, 167, 72, .7);
  opacity: var(--sun-opacity);
}

.moon {
  background: #f1f3f7;
  box-shadow: 0 0 30px rgba(221, 231, 255, .66);
  opacity: var(--moon-opacity);
}

.moon::after {
  content: "";
  position: absolute;
  width: 84%;
  height: 84%;
  left: 28%;
  top: -6%;
  border-radius: 50%;
  background: var(--sky-top);
}

.city-scene {
  width: 100%;
  height: 100%;
  z-index: 1;
  filter: brightness(var(--scene-brightness)) saturate(var(--scene-saturation));
  transition: filter 240ms linear;
}

.clouds { fill: var(--cloud); transition: fill 240ms linear; }
.cloud-front { fill: var(--cloud-front); }
.distant-hills path { fill: var(--hill); transition: fill 240ms linear; }
.water-reflections path { fill: var(--glow); opacity: .17; filter: blur(4px); }
.skyline-far path:not(.spire) { fill: var(--far-building); transition: fill 240ms linear; }
.skyline-far .spire { fill: var(--far-building); stroke: var(--bridge-light); stroke-width: 3; }
.city-mid .block path { fill: var(--mid-building); transition: fill 240ms linear; }
.city-mid .block:nth-child(2n) path { fill: var(--mid-building-2); }
.city-mid .block > path:first-child { stroke: rgba(255,255,255,.035); stroke-width: 2; }
.bridge-lights circle { fill: var(--bridge-light); filter: url(#softGlow); opacity: var(--lamp-opacity); }
.window { fill: var(--window-on); opacity: var(--window-opacity); filter: url(#softGlow); transition: opacity 240ms linear, fill 240ms linear; }
.window.dim { opacity: calc(var(--window-opacity) * .35); }
.window.large { stroke: rgba(255,255,255,.08); stroke-width: 2; }
.window.vehicle { filter: none; }
.arcade-sign { fill: #49265f; stroke: #bc73ff; stroke-width: 4; filter: url(#softGlow); opacity: var(--lamp-opacity); }
.sign-text { fill: #d7b4ff; font-size: 18px; font-weight: 800; letter-spacing: 2px; filter: url(#softGlow); }
.neon-sign { fill: #ff80cf; font-size: 24px; font-weight: 900; letter-spacing: 4px; filter: url(#softGlow); opacity: var(--lamp-opacity); }
.mural { fill: rgba(189, 205, 231, .48); font-size: 27px; font-weight: 800; letter-spacing: 2px; }
.street-lights path { fill: none; stroke: #1a1d25; stroke-width: 8; stroke-linecap: round; }
.street-lights circle { fill: #ffd36a; opacity: var(--lamp-opacity); filter: url(#lampGlow); }
.trees rect { fill: #4b3529; }
.trees circle { fill: #1e5637; }

.topbar {
  position: absolute;
  z-index: 5;
  top: max(22px, env(safe-area-inset-top));
  left: max(26px, env(safe-area-inset-left));
  right: max(26px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-size: clamp(14px, 1.25vw, 18px);
  font-weight: 800;
  letter-spacing: .24em;
  text-decoration: none;
  text-shadow: 0 2px 18px rgba(0,0,0,.35);
  pointer-events: auto;
}

.brand-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 24px;
}

.brand-mark i {
  display: block;
  width: 4px;
  border-radius: 1px 1px 0 0;
  background: currentColor;
  box-shadow: 0 0 12px rgba(255,255,255,.35);
}

.brand-mark i:nth-child(1) { height: 9px; }
.brand-mark i:nth-child(2) { height: 17px; }
.brand-mark i:nth-child(3) { height: 13px; }
.brand-mark i:nth-child(4) { height: 23px; }

.clock {
  padding: 9px 14px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(7, 10, 16, .28);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: rgba(255,255,255,.9);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: .08em;
  box-shadow: 0 12px 30px rgba(0,0,0,.15);
}

.time-panel {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: max(26px, env(safe-area-inset-bottom));
  width: min(680px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 18px 22px 14px;
  border: 1px solid var(--ui-border);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(17, 20, 29, .78), rgba(8, 11, 18, .72));
  box-shadow: 0 22px 60px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.periods {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 8px;
  color: var(--ui-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .13em;
}
.periods span:nth-child(2), .periods span:nth-child(3) { text-align: center; }
.periods span:last-child { text-align: right; }

.time-range {
  width: 100%;
  height: 30px;
  margin: 0;
  cursor: ew-resize;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
}

.time-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background:
    linear-gradient(90deg,
      #92b8df 0%,
      #ffd57f 25%,
      #f79367 52%,
      #7560b5 73%,
      #273050 100%);
  box-shadow: 0 0 0 1px rgba(255,255,255,.07);
}

.time-range::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(90deg, #92b8df 0%, #ffd57f 25%, #f79367 52%, #7560b5 73%, #273050 100%);
}

.time-range::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border: 3px solid rgba(255,255,255,.9);
  border-radius: 50%;
  appearance: none;
  -webkit-appearance: none;
  background: #fff;
  box-shadow: 0 0 0 5px rgba(255,255,255,.12), 0 5px 18px rgba(0,0,0,.35);
}

.time-range::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255,255,255,.9);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 5px rgba(255,255,255,.12), 0 5px 18px rgba(0,0,0,.35);
}

.panel-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 4px;
  color: rgba(255,255,255,.82);
  font-size: 13px;
}

#periodLabel { font-weight: 700; letter-spacing: .04em; }

.auto-button {
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.76);
  cursor: pointer;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}

.auto-button:hover { transform: translateY(-1px); background: rgba(255,255,255,.1); }
.auto-button[aria-pressed="true"] { background: rgba(255,255,255,.92); color: #171a22; }

.grain {
  z-index: 4;
  pointer-events: none;
  opacity: .12;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
}

@media (max-width: 700px) {
  .city-app { min-height: 520px; }
  .topbar { top: 16px; left: 16px; right: 16px; }
  .brand { letter-spacing: .16em; }
  .clock { padding: 8px 11px; font-size: 13px; }
  .time-panel { bottom: 16px; padding: 15px 16px 12px; border-radius: 18px; }
  .periods { font-size: 9px; }
}

@media (max-height: 650px) {
  .time-panel { bottom: 12px; transform: translateX(-50%) scale(.92); transform-origin: bottom center; }
  .topbar { top: 12px; }
}

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