:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f0ebe1;
  --text: #1f2430;
  --muted: #5d6472;
  --border: #e3dccf;
  --accent: #2f6f6a;
  --accent-rgb: 47, 111, 106;
  --accent-2-rgb: 106, 94, 168;
  --on-accent: #ffffff;
  --focus: #6a5ea8;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 24, 32, .05), 0 8px 24px rgba(20, 24, 32, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #161a22;
    --surface-2: #1e2430;
    --text: #e8eaf0;
    --muted: #9aa3b2;
    --border: #283040;
    --accent: #6cc3b8;
    --accent-rgb: 108, 195, 184;
    --accent-2-rgb: 169, 156, 224;
    --on-accent: #0f1218;
    --focus: #a99ce0;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; }
h3 { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0; }

button, select, input { font: inherit; color: inherit; }

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

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -.01em;
}
.logo { width: 28px; height: 28px; color: var(--accent); align-self: center; }
.tagline { color: var(--muted); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 20px;
  align-items: start;
}
.side { display: grid; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* Player */
.player {
  position: sticky;
  top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.stage {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1;
}
#viz { position: absolute; inset: 0; width: 100%; height: 100%; }

.play {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(var(--accent-rgb), .35);
  transition: transform .15s ease, box-shadow .15s ease;
}
.play:hover { transform: translate(-50%, -50%) scale(1.05); }
.play:active { transform: translate(-50%, -50%) scale(.97); }
.play svg { width: 30px; height: 30px; fill: currentColor; }
.play .icon-pause { display: none; }
.play[aria-pressed="true"] .icon-play { display: none; }
.play[aria-pressed="true"] .icon-pause { display: block; }

.breath-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  text-align: center;
  font-size: .95rem;
  color: var(--muted);
  letter-spacing: .04em;
  min-height: 1.5em;
}

.now { text-align: center; }
.now-name { font-size: 1.3rem; font-weight: 650; }
.now-meta { color: var(--accent); font-size: .95rem; font-weight: 550; }
.now-desc {
  max-width: 360px;
  margin: 8px auto 0;
  color: var(--muted);
  font-size: .92rem;
}
.timer {
  margin-top: 6px;
  font-size: 2rem;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

.hint {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .88rem;
}
.hint[hidden] { display: none; }
.hint svg { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: .88rem;
  cursor: pointer;
  color: var(--muted);
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Preset grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.preset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  min-width: 0;
  transition: border-color .15s ease, background .15s ease;
}
.preset:hover { border-color: rgba(var(--accent-rgb), .6); }
.preset[aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb), .12);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.preset-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%; }
.preset-name { font-weight: 600; }
.preset-top svg { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.preset-tag { font-size: .84rem; color: var(--muted); }

/* Controls */
.controls { display: grid; gap: 16px; }
.controls .card-head { margin-bottom: 0; }
.field { display: grid; gap: 6px; min-width: 0; }
.field[hidden] { display: none; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.field label { font-weight: 550; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="range"] { width: 100%; accent-color: var(--accent); margin: 4px 0; }
.range-ends {
  display: flex;
  justify-content: space-between;
  margin-top: -4px;
  font-size: .82rem;
  color: var(--muted);
}

select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  flex: none;
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  transition: background .15s ease;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch-text { display: grid; }
.switch-text small { color: var(--muted); font-size: .82rem; }

/* Footer */
.foot {
  margin-top: 28px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
  max-width: 760px;
}
.stats { color: var(--text); font-weight: 550; }
.stats:empty { display: none; }

/* Responsive */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .player { position: static; }
}
@media (max-width: 420px) {
  .card { padding: 16px; }
  .field-grid { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .play, .preset, .switch-track, .switch-track::after { transition: none; }
}
