/* tremolo — styles. Dark-first; light theme via prefers-color-scheme or data-theme on <html>. */

:root {
  color-scheme: dark;
  --bg: #0D1017;
  --surface: #141821;
  --surface-2: #1B202B;
  --line: #262C39;
  --line-strong: #363D4C;
  --text: #E9E6DF;
  --text-muted: #8B919E;
  --text-faint: #5C6270;
  --c-focus: #E5A85A;
  --c-relax: #7DBAA3;
  --c-sleep: #8FA0DE;
  --c-meditate: #B295D6;
  --on-accent: #0D1017;
  --danger: #D97A6C;
  --shadow: 0 14px 44px rgba(0, 0, 0, .45);
  --font-display: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --font-ui: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-mono: "Azeret Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-brand: "Manrope", "Inter", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --header-h: calc(60px + env(safe-area-inset-top, 0px));
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #ECEEF2; --surface: #F6F7F9; --surface-2: #FFFFFF; --line: #D8DCE3; --line-strong: #C0C6D1;
    --text: #171B23; --text-muted: #5B6270; --text-faint: #8F95A1;
    --c-focus: #A9691F; --c-relax: #25755F; --c-sleep: #4453A6; --c-meditate: #6F4EA3;
    --on-accent: #FFFFFF; --danger: #B8483A;
    --shadow: 0 14px 44px rgba(20, 30, 50, .12);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ECEEF2; --surface: #F6F7F9; --surface-2: #FFFFFF; --line: #D8DCE3; --line-strong: #C0C6D1;
  --text: #171B23; --text-muted: #5B6270; --text-faint: #8F95A1;
  --c-focus: #A9691F; --c-relax: #25755F; --c-sleep: #4453A6; --c-meditate: #6F4EA3;
  --on-accent: #FFFFFF; --danger: #B8483A;
  --shadow: 0 14px 44px rgba(20, 30, 50, .12);
}

.app[data-mode="focus"] { --accent: var(--c-focus); }
.app[data-mode="relax"] { --accent: var(--c-relax); }
.app[data-mode="sleep"] { --accent: var(--c-sleep); }
.app[data-mode="meditate"] { --accent: var(--c-meditate); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.app {
  --accent: var(--c-focus);
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  background: var(--bg);
  transition: --accent .4s;
}

/* ---------- header ---------- */
.top {
  height: var(--header-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: env(safe-area-inset-top, 0px) 22px 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark {
  display: flex; align-items: center;
  color: var(--accent);
  transition: color .4s;
}
.mark svg { width: 26px; height: 26px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.wordmark { font-family: var(--font-brand); font-weight: 600; font-size: 16px; letter-spacing: -.025em; }
.tagline { font-size: 11.5px; color: var(--text-muted); letter-spacing: .02em; white-space: nowrap; }

.modes { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.mode {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; border-radius: 999px;
  color: var(--text-muted); font-weight: 500; font-size: 13.5px;
  transition: background .2s, color .2s;
}
.mode:hover { color: var(--text); }
.mode-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot); opacity: .55; }
.mode[data-value="focus"] { --dot: var(--c-focus); }
.mode[data-value="relax"] { --dot: var(--c-relax); }
.mode[data-value="sleep"] { --dot: var(--c-sleep); }
.mode[data-value="meditate"] { --dot: var(--c-meditate); }
.mode[aria-selected="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.mode[aria-selected="true"] .mode-dot { opacity: 1; }

.tools { display: flex; justify-content: flex-end; gap: 6px; }
.tool {
  height: 32px; min-width: 32px; padding: 0 10px; border-radius: 8px;
  color: var(--text-muted); font-size: 13px; font-weight: 500; border: 1px solid transparent;
}
.tool:hover { color: var(--text); background: var(--surface); border-color: var(--line); }

/* ---------- main layout ---------- */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 420px; }

.stage {
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  height: calc(100dvh - var(--header-h));
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 42%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 60%), var(--bg);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-ui { position: absolute; inset: 0; pointer-events: none; }
.stage-ui > * { pointer-events: auto; }

.now { position: absolute; top: 26px; left: 28px; max-width: 46%; }
.now-activity { font-family: var(--font-display); font-size: 26px; font-weight: 500; line-height: 1.2; text-wrap: balance; }
.now-band { margin-top: 6px; font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); letter-spacing: .02em; }
.now-band b { color: var(--accent); font-weight: 500; }
.now-phase { margin-top: 10px; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); }
.now-phase .pill { padding: 2px 9px; border-radius: 999px; border: 1px solid var(--accent); color: var(--accent); font-weight: 500; }

.timer-wrap {
  position: absolute; left: 50%; top: var(--cy, 44%);
  transform: translate(-50%, -50%);
  text-align: center; pointer-events: none;
}
.timer {
  font-family: var(--font-mono); font-weight: 200; font-size: clamp(38px, calc(var(--R, 140px) * 0.42), 72px);
  letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums;
}
.timer-label { margin-top: 8px; font-size: 12px; color: var(--text-muted); letter-spacing: .04em; }

.breath {
  position: absolute; left: 50%; top: calc(var(--cy, 44%) + var(--R, 140px) * .62);
  transform: translateX(-50%); display: flex; align-items: baseline; gap: 10px;
  font-family: var(--font-display); font-size: 18px; color: var(--accent);
}
.breath-count { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }

.transport {
  position: absolute; left: 50%; top: calc(var(--cy, 44%) + var(--R, 140px) + 36px);
  transform: translateX(-50%); display: flex; align-items: center; gap: 14px;
}
.play {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform .15s, box-shadow .2s, background .4s;
}
.play:hover { transform: scale(1.04); }
.play:active { transform: scale(.97); }
.play svg { width: 26px; height: 26px; fill: currentColor; }
.play .ic-pause { display: none; }
.play[data-playing="true"] .ic-play { display: none; }
.play[data-playing="true"] .ic-pause { display: block; }
.stopbtn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--text-muted); display: grid; place-items: center;
}
.stopbtn:hover { color: var(--text); border-color: var(--text-muted); }
.stopbtn svg { width: 12px; height: 12px; fill: currentColor; }

.readout {
  position: absolute; right: 28px; top: 26px; text-align: right;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); line-height: 1.7;
}
.readout b { color: var(--text); font-weight: 500; }
.readout .hp { color: var(--accent); }

.volume { position: absolute; right: 28px; bottom: 74px; display: flex; align-items: center; gap: 10px; width: 150px; }
.volume-icon { color: var(--text-faint); font-size: 12px; }

/* ---------- panel ---------- */
.panel { border-left: 1px solid var(--line); background: var(--surface); min-width: 0; }
.block { padding: 22px 24px 20px; border-bottom: 1px solid var(--line); }
.block-title {
  margin: 0 0 14px; font-size: 11.5px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-muted);
}
.hint { margin: 12px 0 0; font-size: 12px; color: var(--text-muted); line-height: 1.65; max-width: 60ch; }

.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act {
  text-align: left; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px; min-height: 76px;
  transition: border-color .15s, background .15s;
}
.act:hover { border-color: var(--line-strong); }
.act[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.act-name { font-weight: 500; font-size: 14px; }
.act-hz { font-family: var(--font-mono); font-size: 11px; color: var(--accent); }
.act-desc { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.seg-btn { padding: 6px 14px; border-radius: 6px; color: var(--text-muted); font-weight: 500; font-size: 13px; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg.small .seg-btn { padding: 4px 10px; font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-muted); font-size: 12.5px; font-weight: 500; transition: border-color .15s, color .15s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.chip:disabled { opacity: .4; cursor: not-allowed; }

.mixer { display: grid; gap: 10px; }
.mix { display: grid; grid-template-columns: 96px 1fr 36px; align-items: center; gap: 12px; }
.mix-name { font-size: 13px; }
.mix-val { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); text-align: right; }

/* range inputs */
input[type="range"] {
  --pct: 50%;
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--line-strong) var(--pct));
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--line-strong); }
input[type="range"]::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; margin-top: -5.5px;
  background: var(--text); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong);
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%; background: var(--text); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--line-strong);
}

.toggles { display: grid; gap: 6px; }
.toggle {
  display: grid; grid-template-columns: 1fr 38px; align-items: center; gap: 14px; text-align: left;
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid transparent;
}
.toggle:hover { background: var(--surface-2); border-color: var(--line); }
.toggle-name { font-weight: 500; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.toggle-hint { font-size: 11.5px; color: var(--text-muted); line-height: 1.5; margin-top: 2px; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-strong); color: var(--text-muted); font-weight: 500; letter-spacing: .04em; }
.switch { width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .2s; }
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--text); transition: transform .2s;
}
.toggle[aria-pressed="true"] .switch { background: var(--accent); }
.toggle[aria-pressed="true"] .switch::after { transform: translateX(16px); background: var(--on-accent); }

/* lab */
.lab summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.lab summary::-webkit-details-marker { display: none; }
.lab summary::before { content: "▸"; font-size: 10px; transition: transform .2s; }
.lab[open] summary::before { transform: rotate(90deg); }
.lab-body { display: grid; gap: 16px; padding-top: 4px; }
.field { display: grid; gap: 6px; }
.field-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.field-label output { font-family: var(--font-mono); font-size: 12px; color: var(--accent); }
.ramp-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.ramp-fields label { display: grid; gap: 4px; font-size: 11.5px; color: var(--text-muted); }
input[type="number"], input[type="text"] {
  width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--text); font-size: 13px;
}
input[type="number"]:focus, input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }

.btn {
  padding: 8px 14px; border-radius: 8px; background: var(--text); color: var(--bg); font-weight: 500; font-size: 13px;
  border: 1px solid transparent;
}
.btn:hover { opacity: .9; }
.btn.ghost { background: transparent; color: var(--text-muted); border-color: var(--line-strong); }
.btn.ghost:hover { color: var(--text); opacity: 1; }
.btn.small { padding: 4px 10px; font-size: 12px; }

.preset-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.presets { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.preset { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.preset-name { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-meta { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); }
.preset .del { color: var(--text-faint); } .preset .del:hover { color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); }
.stat-label { font-size: 11px; color: var(--text-muted); letter-spacing: .04em; }
.stat-val { font-family: var(--font-mono); font-weight: 300; font-size: 22px; margin-top: 2px; line-height: 1.1; }
.stat-val small { font-family: var(--font-ui); font-size: 11px; color: var(--text-muted); margin-left: 3px; }
.stat-modes { grid-column: 1 / -1; display: grid; gap: 6px; margin-top: 4px; }
.stat-mode { display: grid; grid-template-columns: 80px 1fr 44px; align-items: center; gap: 10px; font-size: 12px; }
.stat-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.stat-bar i { display: block; height: 100%; background: var(--bar); border-radius: 2px; }
.stat-mode .n { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); text-align: right; }

.how-body { margin: 0 0 14px; font-size: 13px; line-height: 1.75; max-width: 62ch; color: var(--text); }
.how-now { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-size: 12px; color: var(--text-muted); }
.how-now b { font-family: var(--font-mono); font-weight: 500; color: var(--accent); }
.bands { display: grid; gap: 4px; }
.band { display: grid; grid-template-columns: 74px 84px 1fr; gap: 10px; align-items: center; font-size: 12px; padding: 5px 8px; border-radius: 6px; color: var(--text-muted); }
.band .rng { font-family: var(--font-mono); font-size: 11px; }
.band[data-active="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.band[data-active="true"] .bname { color: var(--accent); font-weight: 500; }

.foot { padding: 18px 24px 28px; font-size: 11.5px; color: var(--text-faint); line-height: 1.6; }

/* ---------- mini bar (mobile) ---------- */
.minibar { display: none; }

/* ---------- help dialog & toast ---------- */
.help { border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 14px; padding: 22px 24px; min-width: 300px; box-shadow: var(--shadow); }
.help::backdrop { background: rgba(0,0,0,.5); }
.help h2 { margin: 0 0 14px; font-family: var(--font-display); font-weight: 500; font-size: 20px; }
.keys-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 18px; font-size: 13px; }
.keys-list dt { font-family: var(--font-mono); font-size: 12px; padding: 2px 8px; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--line-strong); text-align: center; }
.keys-list dd { margin: 0; color: var(--text-muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 50; animation: toast .25s ease-out;
}
.toast-action { color: inherit; font-weight: 600; white-space: nowrap; text-decoration: underline; text-underline-offset: 3px; }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .main { grid-template-columns: minmax(0, 1fr) 380px; }
  .tagline { display: none; }
}
@media (max-width: 900px) {
  .top { grid-template-columns: auto 1fr auto; padding-left: 14px; padding-right: 14px; gap: 10px; }
  .modes { justify-self: center; }
  .mode { padding: 6px 10px; font-size: 12.5px; gap: 6px; }
  .brand-text { display: none; }
  .main { grid-template-columns: 1fr; }
  .stage { position: relative; top: 0; height: clamp(440px, 64vh, 620px); }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding-bottom: 72px; }
  .now { left: 18px; top: 18px; max-width: 60%; }
  .now-activity { font-size: 22px; }
  .readout { right: 18px; top: 18px; font-size: 10.5px; }
  .volume { right: 18px; bottom: 76px; width: 120px; }
  .block { padding: 18px 16px 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .minibar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .mini-play { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
  .mini-play svg { width: 18px; height: 18px; fill: currentColor; }
  .mini-play .ic-pause { display: none; }
  .mini-play[data-playing="true"] .ic-play { display: none; }
  .mini-play[data-playing="true"] .ic-pause { display: block; }
  .mini-info { display: flex; flex-direction: column; line-height: 1.25; }
  .mini-time { font-size: 15px; font-weight: 300; }
  .mini-hz { font-size: 11px; color: var(--text-muted); }
}
@media (max-width: 480px) {
  .mode span:last-child { display: none; }
  .mode { padding: 8px 10px; }
  .mode-dot { width: 9px; height: 9px; }
  .acts { grid-template-columns: 1fr; }
  .act { min-height: 0; }
  .ramp-fields { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
