:root {
  /* Layout: full-bleed weather scene, a quiet title up top, one glass mixing dock at the bottom.
     Evening is the base palette; data-mood="day" swaps every token for overcast daylight. */
  --bg: #06090f;
  --glass: rgba(12, 19, 29, 0.62);
  --raised: rgba(255, 255, 255, 0.04);
  --line: rgba(168, 196, 214, 0.14);
  --track: rgba(220, 232, 240, 0.13);
  --fg: #e3eaef;
  --muted: #8b9ba8;
  --accent: #b4d3df;
  --accent-ink: #08121a;
  --accent-soft: rgba(180, 211, 223, 0.12);
  --warm: #ffc27a;
  --live: #7fd3a6;
  --shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.6);
  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --font-ui: "Hanken Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --theme-t: background-color .9s var(--ease), color .9s var(--ease), border-color .9s var(--ease), box-shadow .9s var(--ease);
  color-scheme: dark;
}
:root[data-mood="day"] {
  --bg: #b9c2c9;
  --glass: rgba(244, 247, 249, 0.66);
  --raised: rgba(255, 255, 255, 0.5);
  --line: rgba(28, 48, 62, 0.13);
  --track: rgba(20, 40, 55, 0.14);
  --fg: #14212b;
  --muted: #55646f;
  --accent: #2c5a6d;
  --accent-ink: #f2f7f9;
  --accent-soft: rgba(44, 90, 109, 0.1);
  --warm: #c46a12;
  --live: #2f8a5a;
  --shadow: 0 30px 80px -40px rgba(20, 35, 45, 0.45);
  color-scheme: light;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: var(--theme-t);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
svg { flex: none; }

#scene, #bolt, #glass { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#bolt, #glass { pointer-events: none; }
#bolt { mix-blend-mode: screen; }

.shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.shell > * { pointer-events: auto; }

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; transition: opacity 1.2s var(--ease); }
.brand { font-family: var(--font-display); font-size: 1.5rem; letter-spacing: 0.01em; transition: var(--theme-t); }
.strike { display: grid; justify-items: end; gap: 2px; opacity: 0; transform: translateY(-6px); transition: opacity .6s var(--ease), transform .6s var(--ease); text-align: right; }
.strike.show { opacity: 1; transform: none; }
.strike-km { font-family: var(--font-mono); font-size: .95rem; font-variant-numeric: tabular-nums; }
.strike-note { font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- hero ---------- */
.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  transition: opacity .9s var(--ease), transform .9s var(--ease);
}
.hero h1 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(2.6rem, 11vw, 4.4rem); line-height: .98; letter-spacing: -.01em; text-wrap: balance; }
.hero h1 em { color: var(--accent); transition: var(--theme-t); }
.hero p { margin: 0; max-width: 34ch; color: var(--muted); line-height: 1.5; }
.hero-link { color: var(--accent); text-underline-offset: 3px; white-space: nowrap; }
.start {
  margin-top: 6px;
  padding: 14px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  letter-spacing: .01em;
  animation: breathe 3.6s ease-in-out infinite;
  transition: transform .3s var(--ease), var(--theme-t);
}
.start:active { transform: scale(.97); }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 14px transparent; } }
body.started .hero { opacity: 0; transform: translateY(-12px); pointer-events: none; }

/* ---------- panel ---------- */
.panel {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  box-sizing: border-box;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--glass);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  transition: opacity 1.2s var(--ease), var(--theme-t);
}
body.desk-on .panel { box-shadow: var(--shadow), 0 0 90px -30px rgba(255, 170, 90, .45); }
.panel-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 10px; }
.play { width: 48px; height: 48px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); transition: transform .3s var(--ease), var(--theme-t); }
.play:active { transform: scale(.94); }
.play svg { width: 22px; height: 22px; fill: currentColor; }
.play .i-pause, body.playing .play .i-play { display: none; }
body.playing .play .i-pause { display: block; }
.now { min-width: 0; }
.now-label { font-family: var(--font-display); font-size: 1.35rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-meta { display: flex; gap: 10px; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.focus-left { font-family: var(--font-mono); color: var(--accent); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: transparent; transition: background-color .3s, var(--theme-t); }
.icon-btn:hover { background: var(--raised); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
#collapseBtn svg { transition: transform .5s var(--ease); }
.panel.collapsed #collapseBtn svg { transform: rotate(180deg); }

.panel-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .55s var(--ease), opacity .45s var(--ease); }
.panel.collapsed .panel-body { grid-template-rows: 0fr; opacity: 0; }
.inner { min-height: 0; overflow: hidden; overflow: clip; display: grid; gap: 12px; }
.inner > :first-child { margin-top: 12px; }

/* ---------- tabs ---------- */
.tabs { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); transition: var(--theme-t); }
.tab { position: relative; z-index: 1; padding: 7px 0; border: 0; background: none; font-size: .84rem; font-weight: 500; color: var(--muted); transition: color .35s var(--ease); }
.tab[aria-selected="true"] { color: var(--fg); }
.tab-ink { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc((100% - 6px) / 3); border-radius: 9px; background: var(--glass); box-shadow: 0 1px 6px rgba(0, 0, 0, .18); border: 1px solid var(--line); box-sizing: border-box; transition: transform .45s var(--ease), var(--theme-t); }

.panes { display: grid; overflow: hidden; overflow: clip; transition: height .45s var(--ease); }
.pane { grid-area: 1 / 1; align-self: start; display: grid; gap: 12px; align-content: start; transition: opacity .35s var(--ease), transform .35s var(--ease), visibility 0s; }
.pane:not(.active) { opacity: 0; visibility: hidden; transform: translateY(6px); pointer-events: none; transition: opacity .25s var(--ease), transform .25s var(--ease), visibility 0s linear .25s; }

/* ---------- chips + sliders ---------- */
.presets { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 85%, transparent); mask-image: linear-gradient(to right, #000 85%, transparent); }
.presets::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: transparent; font-size: .86rem; white-space: nowrap; transition: var(--theme-t); }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.small { padding: 6px 11px; font-size: .8rem; }

.mixer { display: grid; gap: 2px; }
.row { display: grid; grid-template-columns: 68px minmax(0, 1fr) 76px; align-items: center; gap: 12px; }
.lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); white-space: nowrap; }
.row output { font-family: var(--font-mono); font-size: .78rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

input[type="range"] { --fill: 50%; -webkit-appearance: none; appearance: none; width: 100%; min-width: 0; height: 30px; margin: 0; background: transparent; transition: opacity .4s var(--ease); }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--accent) var(--fill), var(--track) var(--fill)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--fg); box-shadow: 0 0 0 4px var(--accent-soft); transition: transform .25s var(--ease); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.18); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--fg); }

/* ---------- sound tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tile { display: grid; gap: 2px; padding: 8px 10px 2px; border: 1px solid var(--line); border-radius: 14px; background: transparent; transition: var(--theme-t); }
.tile.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.tile-btn { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 2px 0; border: 0; background: none; text-align: left; }
.tile-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); transition: color .4s var(--ease); }
.tile.on .tile-btn svg { color: var(--accent); }
.tile-name { flex: 1; min-width: 0; font-size: .88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-state { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tile.on .tile-state { color: var(--accent); }
.tile:not(.on) input[type="range"] { opacity: .35; }
/* An odd tile out spans the row instead of sitting alone in half of it */
.tiles .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* ---------- room ---------- */
.opt { display: grid; grid-template-columns: 68px minmax(0, 1fr); align-items: center; gap: 12px; min-height: 40px; }
.seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 12px; background: var(--raised); border: 1px solid var(--line); transition: var(--theme-t); }
.seg button { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 0; border: 0; background: none; font-size: .84rem; color: var(--muted); transition: color .35s var(--ease); }
.seg button[aria-checked="true"] { color: var(--fg); }
.seg svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.seg-ink { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 9px; background: var(--glass); border: 1px solid var(--line); box-sizing: border-box; box-shadow: 0 1px 6px rgba(0, 0, 0, .18); transition: transform .45s var(--ease), var(--theme-t); }
:root[data-mood="evening"] .seg-ink { transform: translateX(100%); }

.lamps { display: flex; flex-wrap: wrap; gap: 8px; }
.lamp { display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: transparent; font-size: .84rem; transition: var(--theme-t); }
.bulb { width: 10px; height: 10px; border-radius: 50%; background: var(--track); box-shadow: 0 0 0 0 transparent; transition: background-color .5s var(--ease), box-shadow .5s var(--ease); }
.lamp[aria-pressed="true"] { border-color: color-mix(in srgb, var(--warm) 55%, transparent); }
.lamp[aria-pressed="true"] .bulb { background: var(--warm); box-shadow: 0 0 10px 2px color-mix(in srgb, var(--warm) 60%, transparent); }
.timer-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- online counter ---------- */
.panel-foot { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 8px; font-size: .74rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--live); box-shadow: 0 0 6px var(--live); animation: live 2.8s ease-in-out infinite; }
@keyframes live { 50% { opacity: .35; } }
#onlineCount { color: var(--fg); }
#onlineCount.bump { animation: bump .6s var(--ease); }
@keyframes bump { from { opacity: 0; } }

/* ---------- account ---------- */
[hidden] { display: none !important; }
.top-right { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.account-btn {
  flex: none;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: .82rem;
  font-weight: 500;
  transition: var(--theme-t);
}
.account-btn:hover { border-color: var(--accent); }
.update-btn { border-color: var(--accent); }
.account-btn.avatar { width: 34px; padding: 0; display: grid; place-items: center; overflow: hidden; font-family: var(--font-display); font-size: 1.05rem; }
.account-btn.avatar img { width: 100%; height: 100%; object-fit: cover; }

.sheet-wrap { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(3, 6, 10, .45); opacity: 0; transition: opacity .35s var(--ease); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: min(86vh, 720px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom, 0px));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.2);
  backdrop-filter: blur(24px) saturate(1.2);
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  transition: transform .45s var(--ease), opacity .35s var(--ease), var(--theme-t);
}
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; opacity: 1; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; }
.sheet-body { display: grid; gap: 16px; min-height: 0; overflow-y: auto; margin-top: 14px; overscroll-behavior: contain; }
.sheet-lede { margin: 0; line-height: 1.5; max-width: 40ch; }
.sheet-note { margin: 0; font-size: .82rem; color: var(--muted); line-height: 1.5; }
.google-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 18px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: #1f1f1f; font-weight: 500;
}
.google-btn svg { width: 18px; height: 18px; }

.total { display: grid; gap: 2px; }
.total-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.total-value { font-family: var(--font-display); font-size: clamp(2.4rem, 11vw, 3.2rem); line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.stats div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.stats dt { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.stats dd { margin: 4px 0 0; font-family: var(--font-mono); font-size: .9rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

.history { display: grid; gap: 14px; }
.day h3 { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 4px; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.day-total { font-family: var(--font-mono); font-weight: 400; letter-spacing: 0; }
.day ul { list-style: none; margin: 0; padding: 0; }
.day li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line); }
.when, .dur { font-family: var(--font-mono); font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.what { color: var(--muted); font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 4px; font-size: .8rem; color: var(--muted); }
.sheet-foot span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { flex: none; padding: 6px 0; border: 0; background: none; color: var(--accent); font-size: .84rem; font-weight: 500; }

@media (min-width: 720px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-bottom: 1px solid var(--line); border-radius: 22px; padding-bottom: 18px; }
}

/* ---------- idle + toast ---------- */
body.idle .top, body.idle .panel { opacity: .14; }
body.idle .account-btn { opacity: .5; }
body.idle .strike.show { opacity: .7; }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: calc(max(16px, env(safe-area-inset-top, 0px)) + 52px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  font-size: .88rem;
  text-align: center;
  animation: drop-in .5s var(--ease);
}
@keyframes drop-in { from { opacity: 0; transform: translate(-50%, -8px); } }

@media (min-width: 720px) {
  .shell { padding: 28px 32px; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Short landscape screens (phones on their side): title left, controls docked right */
@media (max-height: 560px) and (min-aspect-ratio: 4/3) {
  .shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); grid-template-rows: auto minmax(0, 1fr); column-gap: 24px; padding-block: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-bottom, 0px)); }
  .top { grid-column: 1; grid-row: 1; }
  .hero { grid-column: 1; grid-row: 2; gap: 12px; margin: 0; }
  .hero h1 { font-size: clamp(2rem, 13vh, 3.4rem); }
  .panel { grid-column: 2; grid-row: 1 / 3; align-self: end; margin: 0; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
  .panel::-webkit-scrollbar { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toast { top: auto; bottom: 16px; left: 16px; transform: none; max-width: calc(100% - 460px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .2s !important; }
}
