/* style.css — Klangraum layout & components. Warm, calm, one accent per theme. */

@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/fraunces.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'Hanken Grotesk';
  src: url('../fonts/hankengrotesk.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
  font-style: normal;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* defend against display rules overriding the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color 0.8s var(--ease), color 0.8s var(--ease);
}

/* signature texture — one faint warm grain binds every section */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

#viz {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* ---- optional atmospheric background (decorative, behind the ring) ---- */
.bg-scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-layer {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  transform: scale(1.05);            /* gentle bleed so cover-crop never shows an edge */
  opacity: 0;
  transition: opacity 1.5s var(--ease);
}
.bg-layer.is-on { opacity: 1; }
/* warm, theme-tinted veil keeps every text/control ≥4.5:1 over any image */
.bg-scene::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(135% 115% at 50% 38%,
    color-mix(in oklch, var(--bg) var(--veil-c, 84%), transparent) 0%,
    color-mix(in oklch, var(--bg) var(--veil-m, 89%), transparent) 55%,
    color-mix(in oklch, var(--bg) var(--veil-e, 94%), transparent) 100%);
}
/* veil strength per theme — tuned so even a pure-white image pixel keeps the
   dim text role ≥4.5:1 at the veil's lightest point (Dawn, light bg, needs most) */
:root[data-theme="ember"] { --veil-c: 74%; --veil-m: 83%; --veil-e: 91%; }
:root[data-theme="grove"] { --veil-c: 73%; --veil-m: 83%; --veil-e: 91%; }
:root[data-theme="dusk"]  { --veil-c: 74%; --veil-m: 83%; --veil-e: 91%; }
:root[data-theme="dawn"]  { --veil-c: 86%; --veil-m: 90%; --veil-e: 94%; }
/* in image mode, promote loose secondary text to full contrast so a lighter,
   more revealing veil still keeps every text/link ≥4.5:1 over the imagery */
body.has-bg { --text-dim: var(--text); }
.atmos-select { width: 100%; }

#app {
  position: relative;
  z-index: 2;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: clamp(1rem, 0.6rem + 2vw, 2rem);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  background: var(--surface);
  color: var(--accent-text);
  padding: 0.5rem 1rem;
  border-radius: var(--r-sm);
  z-index: 50;
}
.skip:focus { left: 1rem; }

.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }

/* ---- top bar ---- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: clamp(1.5rem, 4vh, 3rem);
}
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--accent), color-mix(in oklch, var(--accent) 40%, transparent));
  box-shadow: 0 0 14px color-mix(in oklch, var(--accent) 60%, transparent);
}
.brand-name { font-family: var(--font-display); font-weight: 500; font-size: 1.15rem; letter-spacing: 0.01em; margin: 0; line-height: 1; }

.bar-actions { display: flex; align-items: center; gap: 0.8rem; }
.themes { display: flex; gap: 0.4rem; }
.theme-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--line);
  cursor: pointer; padding: 0;
  transition: transform 0.25s var(--ease), border-color 0.25s var(--ease);
}
.theme-dot[data-set-theme="ember"] { background: #e6a865; }
.theme-dot[data-set-theme="dawn"]  { background: #c66a4a; }
.theme-dot[data-set-theme="grove"] { background: #e3c581; }
.theme-dot[data-set-theme="dusk"]  { background: #e3a6bd; }
.theme-dot[aria-pressed="true"] { border-color: var(--text); transform: scale(1.18); }

.btn-ghost {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-family: var(--font-ui); font-size: 0.86rem;
  padding: 0.4rem 0.5rem; border-radius: var(--r-sm);
  transition: color 0.25s var(--ease), background-color 0.25s var(--ease);
}
.btn-ghost:hover { color: var(--text); background: var(--line-soft); }
.lang-toggle { border: 1px solid var(--line); border-radius: var(--r-pill); min-width: 2.5rem; text-align: center; font-weight: 600; letter-spacing: 0.03em; }

/* ---- gate (first gesture) ---- */
.gate {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 0.6rem;
  padding: 2rem 0 4rem;
}
.gate-title {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: clamp(3rem, 8vw, 6rem);
  margin: 0;
  letter-spacing: -0.01em;
  font-optical-sizing: auto;
}
.gate-tagline {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  color: var(--accent-text);
  letter-spacing: 0.01em;
  margin: 0;
}
.gate-intro { max-width: 38ch; color: var(--text-dim); margin: 0.4rem 0 1.6rem; }
.btn-begin {
  font-family: var(--font-ui); font-weight: 600; font-size: 1.05rem;
  color: var(--bg); background: var(--accent);
  border: none; border-radius: var(--r-pill);
  padding: 0.85rem 2.6rem; cursor: pointer;
  box-shadow: 0 8px 40px color-mix(in oklch, var(--accent) 35%, transparent);
  transition: transform 0.3s var(--ease), box-shadow 0.3s var(--ease), background-color 0.3s var(--ease);
}
.btn-begin:hover { transform: translateY(-2px); box-shadow: 0 12px 52px color-mix(in oklch, var(--accent) 50%, transparent); }
.gate-hint { color: var(--text-dim); font-size: 0.85rem; margin-top: 1rem; }

/* ---- console ---- */
.console { flex: 1; animation: rise 0.7s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.console-head { margin-bottom: 1.2rem; }
.section-label {
  font-family: var(--font-display); font-weight: 500;
  font-size: 1.4rem; margin: 0 0 0.2rem;
}
.section-hint { color: var(--text-dim); font-size: 0.88rem; margin: 0; }

.sounds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.6rem;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md);
  padding: 0.95rem 0.95rem 1.1rem;
  display: flex; flex-direction: column; gap: 0.7rem;
  cursor: pointer;
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease), transform 0.2s var(--ease), background-color 0.3s var(--ease);
}
.card:hover { border-color: var(--line); }
.card.on {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--accent) 40%, transparent),
              0 10px 34px color-mix(in oklch, var(--accent) 16%, transparent);
}
.card-top {
  display: flex; align-items: center; gap: 0.55rem;
  background: none; border: none; padding: 0; margin: 0;
  width: 100%; min-width: 0; text-align: left; cursor: pointer;
  color: inherit; font: inherit;
}
.card-icon {
  width: 30px; height: 30px; flex: none;
  color: var(--text-dim);
  transition: color 0.3s var(--ease);
}
.card.on .card-icon { color: var(--accent); }
.card-icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.4; }
.card-name { font-size: 0.92rem; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }

/* native range, styled — accessible & keyboard-operable */
.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0;
}
.range::-webkit-slider-runnable-track {
  height: 5px; border-radius: var(--r-pill);
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--line) var(--fill, 0%));
}
.range::-moz-range-track { height: 5px; border-radius: var(--r-pill); background: var(--line); }
.range::-moz-range-progress { height: 5px; border-radius: var(--r-pill); background: var(--accent); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; margin-top: -5.5px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.2s var(--ease);
}
.range::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); border: 2px solid var(--accent);
}
.range:hover::-webkit-slider-thumb { transform: scale(1.15); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px color-mix(in oklch, var(--accent) 45%, transparent); }
.range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px color-mix(in oklch, var(--accent) 45%, transparent); }

/* ---- dock ---- */
.dock {
  border-top: 1px solid var(--line-soft);
  padding-top: 1.4rem;
  display: flex; flex-direction: column; gap: 1.4rem;
}
.master { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 1rem; }
.ctl-label { font-size: 0.9rem; color: var(--text-dim); white-space: nowrap; }
.ctl-val { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--text-dim); min-width: 3ch; text-align: right; }

.modules { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.module {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-md); padding: 1rem;
}
.module-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.8rem; }
.module-title { font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; margin: 0; }
.module-hint { color: var(--text-dim); font-size: 0.78rem; }
.binaural-row { display: grid; grid-template-columns: 1fr auto; gap: 0.8rem; align-items: center; }
.select {
  font-family: var(--font-ui); font-size: 0.82rem;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 0.4rem 0.5rem; cursor: pointer;
}
.timer-row { display: flex; align-items: center; gap: 0.8rem; }
.timer-clock {
  font-family: var(--font-display); font-weight: 400;
  font-size: 1.8rem; font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em; min-width: 4.4ch;
}
.timer-row.break .timer-clock { color: var(--accent-text); }

.btn-soft {
  font-family: var(--font-ui); font-size: 0.86rem; font-weight: 500;
  color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 0.5rem 1.1rem; cursor: pointer;
  transition: border-color 0.25s var(--ease), background-color 0.25s var(--ease), color 0.25s var(--ease);
}
.btn-soft:hover { border-color: var(--accent); color: var(--accent-text); }

.scene-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

/* ---- footer ---- */
.foot {
  margin-top: 2.4rem; padding-top: 1.2rem;
  border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 0.6rem;
  color: var(--text-dim); font-size: 0.82rem;
}

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 0.6rem 1.2rem; font-size: 0.88rem;
  opacity: 0; pointer-events: none; z-index: 60;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

/* ---- nav tabs ---- */
.nav {
  display: flex; gap: 0.25rem; margin-bottom: 1.4rem;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  border-radius: var(--r-pill); padding: 0.3rem;
}
.nav-btn {
  flex: 1; min-width: 0; white-space: nowrap; border: none; background: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 0.9rem; font-weight: 500; color: var(--text-dim);
  padding: 0.55rem 0.5rem; border-radius: var(--r-pill);
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}
.nav-btn:hover { color: var(--text); }
.nav-btn.is-on { background: var(--surface); color: var(--accent-text); box-shadow: 0 2px 12px color-mix(in oklch, var(--accent) 14%, transparent); }

/* ---- chips (categories, lengths, intentions, patterns) ---- */
.cats { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.1rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.chip {
  font-family: var(--font-ui); font-size: 0.84rem; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--r-pill); padding: 0.42rem 0.9rem; cursor: pointer;
  transition: border-color 0.25s var(--ease), color 0.25s var(--ease), background-color 0.25s var(--ease);
}
.chip:hover { border-color: var(--line); color: var(--text); }
.chip.is-on { border-color: var(--accent); color: var(--accent-text); background: color-mix(in oklch, var(--accent) 12%, var(--surface)); }
.len-chip { min-width: 2.6rem; text-align: center; font-variant-numeric: tabular-nums; }

.block-label { font-family: var(--font-display); font-weight: 500; font-size: 1.05rem; margin: 1.2rem 0 0.3rem; }

/* ---- presets ---- */
.presets { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.4rem; }
.preset {
  font-family: var(--font-ui); font-size: 0.86rem; color: var(--text); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 0.55rem 1rem;
  transition: border-color 0.25s var(--ease), color 0.25s var(--ease), transform 0.2s var(--ease);
}
.preset:hover { border-color: var(--accent); color: var(--accent-text); transform: translateY(-1px); }

/* ---- scenes ---- */
.scenes-block { border-top: 1px solid var(--line-soft); padding-top: 1.2rem; }
.scenes-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.6rem; }
.scene-row { display: flex; align-items: center; gap: 0.5rem; }
.scene-load { flex: 1; text-align: left; font-family: var(--font-ui); font-size: 0.88rem; color: var(--text); background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--r-sm); padding: 0.5rem 0.8rem; cursor: pointer; transition: border-color 0.25s var(--ease); }
.scene-load:hover { border-color: var(--accent); }
.scene-del { font-size: 1.2rem; line-height: 1; padding: 0.3rem 0.6rem; }
.scenes-empty { color: var(--text-dim); font-size: 0.85rem; margin: 0.4rem 0 0; }

/* ---- meditation ---- */
.med-begin { margin-top: 1.4rem; }
.med-run { text-align: center; padding: 2rem 0; display: flex; flex-direction: column; align-items: center; gap: 0.8rem; }
.med-clock { font-family: var(--font-display); font-weight: 300; font-size: clamp(3rem, 9vw, 5rem); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.med-phase { font-family: var(--font-display); font-size: 1.2rem; color: var(--accent-text); min-height: 1.4em; }
.med-guide { color: var(--text-dim); font-size: 1.05rem; max-width: 36ch; min-height: 3em; margin: 0.4rem auto; }

/* ---- breathing ---- */
.breath-display { text-align: center; padding: 2.4rem 0 1.4rem; }
.breath-label { font-family: var(--font-display); font-weight: 300; font-size: clamp(2rem, 6vw, 3.2rem); color: var(--accent-text); }
#breathToggle { display: block; margin: 0 auto; }

/* ---- frequencies ---- */
.freq-chips { margin-bottom: 1rem; }
.freq-controls { display: flex; align-items: center; gap: 1rem; margin: 0.4rem 0 1.4rem; }
.iso-module { margin: 0 0 1.4rem; }
.tuning-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.tuning-row .chips { margin-bottom: 0; }
.freq-note { color: var(--text-dim); font-size: 0.8rem; max-width: 52ch; border-top: 1px solid var(--line-soft); padding-top: 1rem; line-height: 1.6; }

/* ---- zen mode ---- */
body.zen #app { opacity: 0; pointer-events: none; transition: opacity 0.6s var(--ease); }
.zen-exit { position: fixed; top: 1.2rem; right: 1.2rem; z-index: 60; font-family: var(--font-ui); font-size: 0.82rem; color: var(--text-dim); background: color-mix(in oklch, var(--surface) 70%, transparent); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 0.5rem 1rem; cursor: pointer; }
.zen-exit:hover { color: var(--text); border-color: var(--accent); }

/* ---- responsive ---- */
@media (max-width: 620px) {
  .modules { grid-template-columns: 1fr; }
  .master { grid-template-columns: 1fr auto; }
  .master .ctl-label { grid-column: 1 / -1; }
  .bar { gap: 0.5rem; }
  .bar-actions { gap: 0.5rem; }
  .btn-ghost { font-size: 0.78rem; }
  .brand-name { font-size: 1rem; }
  .brand { gap: 0.45rem; }
  .theme-dot { width: 18px; height: 18px; }
  .themes { gap: 0.3rem; }
  .lang-toggle { min-width: 2.2rem; padding: 0.35rem 0.4rem; }
  .nav { gap: 0.15rem; padding: 0.25rem; }
  .nav-btn { font-size: 0.76rem; padding: 0.5rem 0.2rem; }
  .sounds { gap: 0.55rem; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
  #zenBtn { display: none; }
}
@media (max-width: 380px) {
  .brand-mark { display: none; }
  .brand-name { font-size: 0.95rem; }
}

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