:root {
  color-scheme: dark;
  --ink: #fbefe0;
  --muted: #d3b99f;
  --accent: #f0a561;
  --bg-a: #3a2417;
  --bg-b: #1b1410;
  --glass: rgba(28, 18, 13, 0.74);
  --line: rgba(255, 224, 190, 0.16);
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg-b);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; min-width: 320px; overflow: hidden; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }

.stage {
  position: relative;
  height: var(--app-h, 100svh);
  min-height: 420px;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 25%, var(--bg-a) 0%, var(--bg-b) 70%);
  user-select: none;
  -webkit-user-select: none;
}

#scene { position: absolute; inset: 0; touch-action: none; cursor: grab; }
#scene.grabbing { cursor: grabbing; }
#scene.over-cloud { cursor: pointer; }
#scene canvas { display: block; width: 100%; height: 100%; outline: none; }

.title {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  right: 110px;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(20, 10, 4, 0.85), 0 1px 16px rgba(20, 10, 4, 0.7);
}
.eyebrow {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}
h1 {
  margin: 2px 0 4px;
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1;
}
.clock { margin: 0 0 6px; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#year { font-size: clamp(1.05rem, 2.6vw, 1.4rem); font-weight: 600; font-variant-numeric: tabular-nums; }
.clock small { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; }
.hint {
  margin: 0;
  max-width: 46ch;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink);
  opacity: 0.85;
  transition: opacity 0.8s ease;
}
.hint.faded { opacity: 0; }

.readout {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: right;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(20, 10, 4, 0.9), 0 1px 12px rgba(20, 10, 4, 0.8);
}
.readout b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.readout span { font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }

.toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%) translateY(6px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.panel {
  position: absolute;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + var(--browser-bar, 0px));
  transform: translateX(-50%);
  width: min(1180px, calc(100% - 24px));
  display: flex;
  flex-wrap: wrap;
  gap: 12px 22px;
  justify-content: center;
  padding: 14px 18px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 18px;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.group { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.group-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.group-label b { color: var(--ink); font-weight: 600; letter-spacing: 0.04em; margin-left: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }

button {
  cursor: pointer;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 500;
  background: rgba(255, 235, 210, 0.07);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  touch-action: manipulation;
}
button:hover { background: rgba(255, 235, 210, 0.15); }
button:active { transform: scale(0.96); }
button[aria-pressed="true"], button.active {
  background: rgba(240, 165, 97, 0.24);
  border-color: rgba(240, 165, 97, 0.8);
  color: #fff1de;
}
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sliders { flex-direction: row; gap: 18px; }
.sliders label { display: flex; flex-direction: column; gap: 8px; min-width: 130px; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

.panel-toggle {
  display: none;
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: var(--toggle-bottom, 14px);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 2;
}

@media (max-width: 720px) {
  .panel-toggle { display: block; }
  .panel {
    gap: 12px 16px;
    padding: 12px 14px;
    justify-content: flex-start;
    max-height: calc(var(--app-h, 100svh) * 0.52 - var(--browser-bar, 0px));
    overflow-y: auto;
  }
  .panel.collapsed { transform: translate(-50%, calc(100% + 24px)); opacity: 0; pointer-events: none; }
  .title { right: 120px; }
  .hint { font-size: 0.78rem; max-width: 30ch; }
  .sliders { width: 100%; }
  .group { align-items: flex-start; }
  .row { justify-content: flex-start; }
  .sliders label { flex: 1; min-width: 0; }
  .toast { top: 30%; }
  .readout b { font-size: 1rem; }
}

/* Grab handle hinting that the panel can be swiped down (touch layouts only). */
@media (max-width: 720px), (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .panel { overscroll-behavior: contain; }
  .panel::before {
    content: "";
    flex: 0 0 100%;
    height: 4px;
    margin-bottom: -4px;
    background: linear-gradient(rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.3)) center / 40px 4px no-repeat;
  }
  .panel.dragging { transition: none; }
}

@media (max-height: 520px) and (min-width: 721px) {
  .panel { padding: 8px 14px; gap: 8px 18px; }
  .hint { display: none; }
}

/* Phones in landscape: wider than 720px but very short, so use the collapsible panel. */
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .stage { min-height: 0; }
  .panel-toggle { display: block; }
  .panel {
    gap: 8px 16px;
    padding: 8px 12px;
    justify-content: flex-start;
    max-height: calc(var(--app-h, 100svh) * 0.62 - var(--browser-bar, 0px));
    overflow-y: auto;
  }
  .panel.collapsed { transform: translate(-50%, calc(100% + 24px)); opacity: 0; pointer-events: none; }
  .group { align-items: flex-start; gap: 4px; }
  .hint { display: none; }
  h1 { font-size: 1.8rem; }
  button { padding: 6px 10px; }
  .readout { flex-direction: row; gap: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .hint, .toast { transition: none; }
}
