/* ember — warm ember in a dark room. No blue light, no pure white. */

@font-face {
  font-family: 'Hanken Grotesk';
  src: url('fonts/hanken-grotesk.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ember: #ff8a3d;
  --fade: 1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #070503;
}

body {
  font-family: 'Hanken Grotesk', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

/* ── range sliders ─────────────────────────────────────────── */
input[type=range].vv {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 44px;
  width: 100%;
  cursor: pointer;
  margin: 0;
}
input[type=range].vv::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: rgba(255,150,90,0.14);
}
input[type=range].vv::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ember);
  margin-top: -7px;
  box-shadow: 0 0 8px rgba(255,138,61,.45);
}
input[type=range].vv::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: rgba(255,150,90,0.14);
}
input[type=range].vv::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 8px rgba(255,138,61,.45);
}

/* ── app shell ─────────────────────────────────────────────── */
.app {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  color: #8b7865;
  transition: filter .8s ease;
  -webkit-user-select: none;
  user-select: none;
}
.app.dim { filter: brightness(0.6); }

/* ── header ────────────────────────────────────────────────── */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,138,61,.45);
  display: inline-block;
  transition: background .6s ease, box-shadow .6s ease;
}
.dot.live {
  background: rgba(255,138,61,.85);
  box-shadow: 0 0 10px rgba(255,138,61,.7);
}
.wordmark { font-size: 14px; letter-spacing: .34em; color: rgba(200,160,120,0.5); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.offline-chip { font-size: 11px; letter-spacing: .06em; color: rgba(185,145,112,0.6); padding: 5px 4px; }
.icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 11px;
  border: 1px solid rgba(255,180,120,0.08);
  background: rgba(14,10,6,0.6);
  color: rgba(195,155,118,0.62);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
#depthBtn { font-size: 19px; }
#depthBtn[aria-pressed="true"] {
  color: var(--ember);
  border-color: rgba(255,138,61,.35);
}
#lockBtn[aria-pressed="true"] {
  color: var(--ember);
  border-color: rgba(255,138,61,.35);
}
/* padlock shackle: open when idle, closed while the wake lock is held */
#lockBtn .lock-closed { display: none; }
#lockBtn[aria-pressed="true"] .lock-closed { display: block; }
#lockBtn[aria-pressed="true"] .lock-open { display: none; }

/* ── storage notice ────────────────────────────────────────── */
.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,180,120,0.10);
  background: rgba(22,15,9,0.7);
  flex: 0 0 auto;
}
.notice-text { flex: 1; font-size: 13px; line-height: 1.45; color: rgba(205,170,134,0.72); }
.notice-keep {
  flex: 0 0 auto;
  padding: 8px 12px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255,138,61,.28);
  background: rgba(255,138,61,.10);
  color: #f0c091;
  font-size: 13px;
  cursor: pointer;
}
.notice-x {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  color: rgba(180,145,115,0.6);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── labelled rows (master, timer) ─────────────────────────── */
.block { display: flex; flex-direction: column; gap: 3px; flex: 0 0 auto; }
.row { display: flex; justify-content: space-between; align-items: center; }
.row-label { font-size: 12px; letter-spacing: .12em; color: rgba(165,135,110,0.62); }
.row-val { font-size: 12px; color: rgba(145,118,96,0.5); font-variant-numeric: tabular-nums; }

/* ── sound tiles ───────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex: 1 1 auto;
  align-content: start;
}

.tile {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  padding: 14px 14px 13px;
  min-height: 120px;
  border-radius: 18px;
  border: 1px solid rgba(255,180,120,0.07);
  background: rgba(14,10,6,0.65);
  color: #8b7865;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .9s ease, transform .9s ease, border-color .7s ease, color .7s ease;
}
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,138,61,.11), rgba(20,13,7,0.55));
  opacity: 0;
  transition: opacity .7s ease;
  pointer-events: none;
}
.tile.appeared { opacity: 1; transform: none; }
.tile.appeared.unavailable { opacity: 0.4; }
.tile.on {
  border-color: rgba(255,138,61,.30);
  color: #eccfa9;
}
/* --fade dims active tiles in step with the audio during the 6s stop fade */
.tile.on::before { opacity: var(--fade, 1); }

.tile-toggle {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  cursor: pointer;
}
.tile-toggle:disabled { cursor: default; }

.tile-head {
  position: relative;
  z-index: 2;
  pointer-events: none;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.tile-icon { color: rgba(200,150,110,0.34); transition: color .7s ease; line-height: 0; }
.tile-icon svg { display: block; }
.tile.uncached .tile-icon, .tile.caching .tile-icon { color: rgba(128,124,118,0.32); }
.tile.on .tile-icon { color: var(--ember); }
.tile-label {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .01em;
  text-align: right;
  color: rgba(139,120,101,0.85);
  transition: color .7s ease;
}
.tile.on .tile-label { color: #eccfa9; }

.tile-body {
  position: relative;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}
.tile-caption { font-size: 11px; letter-spacing: .02em; margin-top: 2px; color: rgba(180,150,120,0.5); }
.tile-caption.wifi { color: rgba(255,138,61,.55); }
.tile-vol { margin-top: 8px; pointer-events: auto; }

/* per-sound pitch-down slider, revealed by the ≈ header button */
.tile-depth {
  margin-top: -2px;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tile-depth-label {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: .1em;
  color: rgba(140,116,94,0.55);
}
.tile-depth input { flex: 1 1 auto; min-width: 0; }
input[type=range].vv.dd { height: 36px; }
input[type=range].vv.dd::-webkit-slider-thumb { width: 16px; height: 16px; margin-top: -6px; }
input[type=range].vv.dd::-moz-range-thumb { width: 16px; height: 16px; }

.tile-progress {
  position: absolute;
  z-index: 2;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2px;
  background: rgba(255,180,120,0.08);
}
.tile-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--ember);
  box-shadow: 0 0 6px rgba(255,138,61,.6);
  transition: width .12s linear;
}

/* ── mix ───────────────────────────────────────────────────── */
.mix { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.mix-row { display: flex; gap: 10px; }
.btn-mymix {
  position: relative;
  overflow: hidden;
  z-index: 0;
  flex: 2 1 0;
  padding: 13px 0;
  min-height: 48px;
  border-radius: 12px;
  text-align: center;
  font-size: 15px;
  letter-spacing: .02em;
  cursor: pointer;
  border: 1px solid rgba(255,138,61,.30);
  background: rgba(14,10,6,0.5);
  color: #eccfa9;
  transition: border-color .5s ease, color .5s ease;
}
.btn-mymix::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(255,138,61,.12), rgba(20,13,7,0.4));
  opacity: 1;
  transition: opacity .5s ease;
}
.btn-mymix:disabled {
  cursor: default;
  border-color: rgba(255,180,120,0.07);
  color: rgba(125,108,91,0.55);
}
.btn-mymix:disabled::before { opacity: 0; }
.btn-savemix {
  flex: 1 1 0;
  padding: 13px 0;
  min-height: 48px;
  border-radius: 12px;
  text-align: center;
  font-size: 14px;
  letter-spacing: .02em;
  cursor: pointer;
  border: 1px solid rgba(255,180,120,0.08);
  background: rgba(14,10,6,0.5);
  color: #7d6c5b;
  transition: all .5s ease;
}
.mix-hint { font-size: 11px; letter-spacing: .02em; color: rgba(180,150,120,0.45); }

/* ── sleep timer ───────────────────────────────────────────── */
.timer { display: flex; flex-direction: column; gap: 9px; flex: 0 0 auto; }
.timer-val { font-size: 13px; letter-spacing: .04em; color: rgba(150,122,98,0.62); }
.timer-val.armed {
  font-size: 18px;
  letter-spacing: .05em;
  color: var(--ember);
  text-shadow: 0 0 14px rgba(255,138,61,.5);
  font-variant-numeric: tabular-nums;
}
.timer-scale {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: .1em;
  color: rgba(140,116,94,0.42);
}

/* ── transport ─────────────────────────────────────────────── */
.transport { display: flex; gap: 10px; flex: 0 0 auto; margin-top: 2px; }
.btn-play {
  position: relative;
  overflow: hidden;
  z-index: 0;
  flex: 2 1 0;
  min-height: 64px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .06em;
  color: rgba(228,188,148,0.45);
  background: rgba(30,20,12,0.7);
  cursor: default;
  transition: color .6s ease, box-shadow .6s ease;
}
.btn-play::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, var(--ember), rgba(255,138,61,.82));
  opacity: 0;
  transition: opacity .6s ease;
}
.btn-play.any { color: #1a0f07; cursor: pointer; }
.btn-play.any::before { opacity: 1; }
.btn-play-inner {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  justify-content: center;
}
.btn-play-inner svg { display: block; }
/* small waveform shown while sound is flowing; with reduced motion the
   bars keep their varied static heights */
.wave { display: inline-flex; align-items: center; gap: 3px; height: 16px; }
.wave i {
  display: block;
  width: 2px;
  border-radius: 1px;
  background: currentColor;
  animation: wavebar 1.6s ease-in-out infinite;
}
.wave i:nth-child(1) { height: 6px;  animation-duration: 1.5s; animation-delay: -0.2s; }
.wave i:nth-child(2) { height: 12px; animation-duration: 1.9s; animation-delay: -0.9s; }
.wave i:nth-child(3) { height: 8px;  animation-duration: 1.7s; animation-delay: -0.5s; }
.wave i:nth-child(4) { height: 13px; animation-duration: 2.1s; animation-delay: -1.4s; }
@keyframes wavebar {
  0%, 100% { transform: scaleY(0.35); }
  50% { transform: scaleY(1); }
}
.btn-stop {
  flex: 1 1 0;
  min-height: 64px;
  border-radius: 18px;
  border: 1px solid rgba(255,180,120,0.16);
  background: rgba(22,15,9,0.7);
  color: rgba(150,122,98,0.5);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .18em;
  cursor: pointer;
  transition: all .6s ease;
}
.btn-stop.any { color: rgba(214,172,136,0.85); }
.btn-stop-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn-stop-inner svg { display: block; }

/* ── preview states panel ──────────────────────────────────── */
.prefs {
  position: absolute;
  right: 16px;
  top: 60px;
  width: 230px;
  background: rgba(18,12,7,0.98);
  border: 1px solid rgba(255,180,120,0.12);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 12px 44px rgba(0,0,0,0.65);
  z-index: 20;
}
.prefs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}
.prefs-title { font-size: 11px; letter-spacing: .16em; color: rgba(185,150,118,0.6); }
.prefs-btn {
  text-align: left;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255,180,120,0.08);
  background: rgba(30,20,12,0.5);
  color: rgba(200,168,132,0.82);
  font-size: 13px;
  cursor: pointer;
}

/* ── short viewports: compress gently, never reorder ───────── */
@media (max-height: 1020px) {
  .app { gap: 12px; }
  .tile { min-height: 106px; }
}
@media (max-height: 920px) {
  .app { gap: 10px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .grid { gap: 10px; }
  .tile { min-height: 96px; }
  .timer { gap: 6px; }
  .btn-play, .btn-stop { min-height: 58px; }
}

/* ── reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.rm *, .rm *::before, .rm *::after { animation: none !important; transition: none !important; }
