/* ══════════════════════════════════════════════════════════
   HUSH — design system
   Day is the default: a pale sage ground with the spectrum drawn
   across it like ink on paper. Night is the sleep state, and it
   swaps the whole palette rather than just dimming.
   ══════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(fonts/inter-var.woff2) format('woff2');
}
@font-face {
  font-family: 'JB Mono';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url(fonts/JetBrainsMono.woff2) format('woff2');
}

:root {
  /* ── day (default) ─────────────────────────────────────
     Card bases are tinted glass, never plain white or grey. */
  --page:     #e9f1ee;
  --page-2:   #dde9e4;
  --panel:    rgba(203, 230, 218, .60);
  --panel-hi: rgba(178, 216, 200, .78);
  --panel-on: rgba(242, 213, 175, .62);
  --hair:     rgba(21, 48, 42, .16);
  --hair-2:   rgba(21, 48, 42, .24);
  --ink:      #15302a;
  --dim:      rgba(21, 48, 42, .70);
  --dim-2:    rgba(21, 48, 42, .50);
  --accent:   #ad5f26;
  --accent-d: rgba(173, 95, 38, .12);
  --accent-t: rgba(173, 95, 38, .38);
  --cool:     #2c6f7d;
  --shadow:   0 1px 2px rgba(21,48,42,.06), 0 12px 32px rgba(21,48,42,.09);
  --gate-bg:  radial-gradient(120% 90% at 50% 40%, #f4f8f5 0%, var(--page) 62%);
}

/* ── night: the sleep state ─────────────────────────── */
html.night {
  --page:     #0a1014;
  --page-2:   #060a0d;
  --panel:    rgba(18, 30, 38, .55);
  --panel-hi: rgba(26, 42, 52, .68);
  --panel-on: rgba(232, 181, 122, .14);
  --hair:     rgba(190, 214, 236, .12);
  --hair-2:   rgba(190, 214, 236, .22);
  --ink:      #e6ecf3;
  --dim:      rgba(230, 236, 243, .55);
  --dim-2:    rgba(230, 236, 243, .32);
  --accent:   #e8b57a;
  --accent-d: rgba(232, 181, 122, .14);
  --accent-t: rgba(232, 181, 122, .42);
  --cool:     #7fb0cf;
  --shadow:   none;
}

* { box-sizing: border-box; }

html { background: var(--page); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 350;
  overflow-x: hidden;
  transition: background .6s ease, color .6s ease;
}

.mono { font-family: 'JB Mono', ui-monospace, 'SF Mono', Menlo, monospace; font-weight: 400; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
::selection { background: var(--accent); color: #fff; }

/* ══════════════ GATE ══════════════ */
.gate[hidden] { display: none !important; }

.gate {
  position: relative;              /* normal flow; iOS samples body bg for chrome */
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(30px, env(safe-area-inset-top)) 24px max(30px, env(safe-area-inset-bottom));
  background: var(--gate-bg);
}
.gate-inner { position: relative; z-index: 1; text-align: center; max-width: 560px; }

.gate-ring { color: var(--accent); margin-bottom: 26px; }
.gate-ring svg { display: block; margin: 0 auto; }
.pulse-ring { transform-origin: 70px 70px; animation: spin 34s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.gate-title {
  font-weight: 200;
  font-size: clamp(52px, 15vw, 108px);
  letter-spacing: .30em;
  margin: 0 0 0 .30em;
  line-height: 1;
  color: var(--ink);
}
.gate-sub {
  margin: 24px 0 0;
  font-size: clamp(13px, 2.4vw, 15px);
  color: var(--dim);
  letter-spacing: .04em;
  line-height: 1.7;
}
.gate-sub.en {
  margin-top: 8px;
  font-size: clamp(11px, 2vw, 12.5px);
  color: var(--dim-2);
  font-family: 'JB Mono', monospace;
  letter-spacing: .06em;
}

.gate-btn {
  margin-top: 38px;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 16px 38px;
  border: 1px solid var(--hair-2);
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: .16em;
  color: var(--ink);
  background: rgba(255,255,255,.42);
  box-shadow: var(--shadow);
  transition: border-color .45s, color .45s, background .45s, letter-spacing .45s, box-shadow .45s;
}
.gate-btn:hover, .gate-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--panel-on);
  letter-spacing: .22em;
  outline: none;
}
.gate-btn .arw { transition: transform .45s; }
.gate-btn:hover .arw { transform: translateX(5px); }
.gate-foot { margin: 42px 0 0; font-size: 9.5px; letter-spacing: .3em; color: var(--dim-2); }

/* ══════════════ APP ══════════════ */
.app[hidden] { display: none !important; }
.app {
  position: relative;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 0 clamp(14px, 3.6vw, 46px);
  background: var(--page);
  transition: background .6s ease;
}

#viz { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }

/* the scrim keeps type readable over the densest part of the drawing */
.scrim {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(233,241,238,.80) 0%, rgba(233,241,238,0) 18%,
                    rgba(233,241,238,0) 46%, rgba(233,241,238,.86) 100%);
  transition: background .6s ease;
}
html.night .scrim {
  background:
    radial-gradient(96% 70% at 50% 42%, rgba(10,16,20,0) 32%, rgba(10,16,20,.60) 100%),
    linear-gradient(180deg, rgba(10,16,20,.70) 0%, rgba(10,16,20,0) 20%,
                    rgba(10,16,20,0) 50%, rgba(10,16,20,.90) 100%);
}

.bar, .presets, .library, .deck, .credit, .wake, .nope { position: relative; z-index: 2; }

/* ── top bar ── */
.bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 0 10px;
}
.brand { font-weight: 300; font-size: 14px; letter-spacing: .42em; }
.now {
  font-size: 10px; letter-spacing: .16em; color: var(--dim);
  text-align: center; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar-right { display: flex; align-items: center; gap: 10px; }
.timer-line, .timer {
  font-size: 10px; letter-spacing: .14em; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.icon-btn {
  font-family: 'JB Mono', monospace;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--dim);
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 6px 11px;
  transition: color .3s, border-color .3s, background .3s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--hair-2); background: var(--panel); }
#langBtn { display: inline-flex; align-items: center; gap: 4px; }
#langBtn .on { color: var(--accent); font-weight: 600; }
#langBtn .sep { color: var(--dim-2); }

/* ── presets ── */
.presets {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 6px 0 14px;
}
.pre {
  font-size: 11.5px;
  letter-spacing: .08em;
  color: var(--dim);
  padding: 7px 15px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--panel);
  transition: color .3s, border-color .3s, background .3s;
}
.pre:hover { color: var(--ink); border-color: var(--hair-2); background: var(--panel-hi); }
.pre.on { color: var(--accent); border-color: var(--accent-t); background: var(--panel-on); }

/* ── library ── */
.library {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 4px 0 18px;
  max-width: 1060px;
  margin: 0 auto;
  width: 100%;
}
.group-label {
  font-family: 'JB Mono', monospace;
  font-size: 9.5px;
  letter-spacing: .34em;
  color: var(--dim);
  margin: 0 0 10px;
}
.tiles { display: grid; gap: 10px; }
.tiles-rhythm { display: flex; }
.tiles-noise   { grid-template-columns: repeat(4, 1fr); }
.tiles-ambient { grid-template-columns: repeat(4, 1fr); }
.tiles-rhythm  { justify-content: center; gap: 10px; }
.tiles-rhythm .tile { width: calc((100% - 30px) / 4); }

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 14px 15px 12px;
  border: 1px solid var(--hair);
  border-radius: 13px;
  background: var(--panel);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.55);
  text-align: left;
  transition: border-color .38s, background .38s, box-shadow .38s;
  overflow: hidden;
}
.tile::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: radial-gradient(120% 96% at 50% 116%, rgba(173,95,38,.20), transparent 64%);
  opacity: 0;
  transition: opacity .5s;
  pointer-events: none;
}
.tile:hover { border-color: var(--hair-2); background: var(--panel-hi); }
.tile.on { border-color: var(--accent-t); background: var(--panel-on); }
.tile.on::before { opacity: 1; }

.tile-main {
  display: flex; flex-direction: column; gap: 4px;
  padding: 0; text-align: left; width: 100%;
}
.tile-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; border-radius: 6px; }
.tile-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tile-zh { font-size: 15.5px; letter-spacing: .05em; color: var(--ink); font-weight: 450; }
.tile-en { font-family: 'JB Mono', monospace; font-size: 9.5px; letter-spacing: .16em; color: rgba(21,48,42,.60); }
.tile-en.cjk { font-family: 'Inter', sans-serif; font-size: 11.5px; letter-spacing: .1em; font-weight: 400; color: var(--dim-2); }
.tile-desc { font-size: 12px; line-height: 1.6; color: var(--dim); margin: 3px 0 0; }
.tile.on .tile-zh { color: var(--accent); }
.tile.on .tile-en { color: var(--accent); opacity: .66; }
.tile.on .tile-desc { color: rgba(21,48,42,.78); }

html.night .tile-en { color: var(--dim-2); }

.dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--dim-2);
  flex: 0 0 auto;
  transition: background .35s, box-shadow .35s;
}
.tile.on .dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-d); }

.tile-vol {
  display: flex; align-items: center; gap: 9px;
  max-height: 0; opacity: 0; overflow: hidden;
  transition: max-height .4s ease, opacity .32s, margin .4s;
}
.tile.on .tile-vol { max-height: 30px; opacity: 1; margin-top: 9px; }
.tile-vol input[type=range] { flex: 1; min-width: 0; width: auto; }
.vol-val {
  font-size: 9.5px; letter-spacing: .1em; color: var(--dim);
  min-width: 22px; text-align: right; font-variant-numeric: tabular-nums;
}

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; background: none; cursor: pointer; margin: 0;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 60%), var(--hair) var(--fill, 60%));
}
input[type=range]::-moz-range-track { height: 2px; border-radius: 2px; background: var(--hair); }
input[type=range]::-moz-range-progress { height: 2px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent);
  margin-top: -5.5px;
  box-shadow: 0 1px 4px rgba(21,48,42,.28);
}
input[type=range]::-moz-range-thumb {
  width: 13px; height: 13px; border: 0; border-radius: 50%;
  background: var(--accent);
}
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

/* ── deck ── */
.deck {
  padding: 14px 0 max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--hair);
  display: flex; flex-direction: column; gap: 10px;
}
.deck-row { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }

.play {
  display: inline-flex; align-items: center; gap: 11px;
  padding: 11px 22px;
  border: 1px solid var(--hair-2);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel);
  transition: border-color .3s, color .3s, background .3s;
}
.play:hover { border-color: var(--accent); color: var(--accent); }
.play[aria-pressed="true"] { border-color: var(--accent-t); color: var(--accent); background: var(--panel-on); }
.play-ico {
  width: 0; height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent currentColor;
  transition: all .3s;
}
.play[aria-pressed="true"] .play-ico {
  width: 9px; height: 10px; border: 0;
  background: linear-gradient(90deg, currentColor 0 34%, transparent 34% 66%, currentColor 66% 100%);
}

.master { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 220px; }
.master input { flex: 1; }
.master .mono { font-size: 10.5px; letter-spacing: .18em; color: var(--dim); }
.master .val { color: var(--dim); min-width: 24px; text-align: right; font-variant-numeric: tabular-nums; }

.timer-wrap { display: flex; align-items: center; gap: 10px; }
.timer-wrap > .mono { font-size: 11px; letter-spacing: .18em; color: var(--dim); }
.timer-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tc {
  font-family: 'JB Mono', monospace;
  font-size: 11px;
  letter-spacing: .06em;
  color: var(--dim);
  padding: 6px 11px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--panel);
  transition: color .3s, border-color .3s, background .3s;
}
.tc:hover { color: var(--ink); border-color: var(--hair-2); }
.tc.on { color: var(--accent); border-color: var(--accent-t); background: var(--panel-on); }

.hint { font-size: 10.5px; letter-spacing: .1em; color: var(--dim); margin: 0; }
.credit {
  text-align: center;
  font-family: 'JB Mono', monospace;
  font-size: 9.5px; letter-spacing: .24em;
  color: var(--dim);
  padding: 0 0 16px; margin: 0;
}

/* ══════════════ NIGHT: strip the chrome, then fade it ══════════════ */
html.night .presets,
html.night .library,
html.night .bar-top .now,
html.night .deck .hint,
html.night .credit,
html.night .master,
html.night .timer-wrap { display: none; }
html.night .deck { border-top: 0; }
html.night .bar-top { justify-content: space-between; }

html.night .bar-top,
html.night .wake { transition: opacity 1.4s ease; }
html.night.chrome-dim .bar-top,
html.night.chrome-dim .wake { opacity: .12; }
html.night #viz { transition: opacity 2.4s ease; }
html.night.chrome-dim #viz { opacity: .16; }

.wake {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 22px));
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 22px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--panel-hi);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 10px; letter-spacing: .3em;
  color: var(--dim);
}
.wake[hidden] { display: none; }
.wake-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

/* ══════════════ FALLBACK ══════════════ */
.nope {
  position: fixed; z-index: 50; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: var(--page); text-align: center; padding: 30px;
}
.nope[hidden] { display: none; }
.nope p.mono { font-size: 11px; letter-spacing: .3em; color: var(--accent); margin: 0; }
.nope p { font-size: 13px; color: var(--dim); margin: 0; max-width: 40ch; line-height: 1.7; }

/* ══════════════ RESPONSIVE ══════════════ */
@media (max-width: 860px) {
  .tiles-noise, .tiles-ambient { grid-template-columns: repeat(2, 1fr); }
  .tiles-rhythm .tile { width: calc((100% - 10px) / 2); }

  /* fourteen tiles never fit a phone screen: pin the transport and let the
     library scroll inside its own box */
  .app { height: 100svh; overflow: hidden; }
  .library {
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 10px;
  }
  .deck {
    flex: 0 0 auto;
    background: linear-gradient(180deg, transparent 0%, var(--page) 34%, var(--page) 100%);
  }
  .credit { display: none; }
  .presets, .bar-top { flex: 0 0 auto; }
}
@media (max-width: 720px) {
  .library { gap: 20px; }
  .tiles { gap: 8px; }
  .tile { padding: 12px 13px 10px; border-radius: 11px; }
  .tile-zh { font-size: 14.5px; }
  .tile-desc { font-size: 11px; }
  .deck-row { gap: 14px; }
  .master { min-width: 100%; order: 3; }
  .timer-wrap { order: 4; min-width: 100%; }
  .hint { display: none; }
  .bar-top .now { font-size: 9px; }
}
@media (max-width: 560px) {
  .presets {
    flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .presets::-webkit-scrollbar { display: none; }
  .pre { flex: 0 0 auto; }
  .library { padding-bottom: 26px; }
  .tile { padding: 11px 12px 9px; }
  .tile-desc {
    font-size: 10.5px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .timer-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .timer-chips::-webkit-scrollbar { display: none; }
  .tc { flex: 0 0 auto; }
}
@media (max-width: 400px) {
  .presets { gap: 6px; }
  .deck-row { gap: 10px; }
  .pre { padding: 7px 12px; font-size: 11px; }
  .tc { padding: 8px 13px; }
  .play { padding: 12px 22px; }
  .tile { padding: 12px 12px 11px; }
}
@media (max-height: 560px) {
  .gate-ring { margin-bottom: 14px; }
  .gate-ring svg { width: 84px; height: 84px; }
  .gate-sub.en, .gate-foot { display: none; }
  .gate-btn { margin-top: 22px; }
  .tile-desc { display: none; }
}
/* 1366x768 is still the most common laptop, and it is short rather than
   narrow — tighten the vertical rhythm so the deck stays on screen */
@media (min-width: 861px) and (max-height: 830px) {
  .bar-top { padding-top: 10px; padding-bottom: 6px; }
  .presets { padding: 2px 0 10px; }
  .library { gap: 15px; padding: 2px 0 10px; }
  .group-label { margin-bottom: 7px; }
  .tile { padding: 11px 13px 9px; }
  .tile-desc { font-size: 10.5px; line-height: 1.45; }
  .deck { padding-top: 10px; padding-bottom: 10px; }
  .hint { display: none; }
  .credit { padding-bottom: 8px; }
}
