/* Breathing Box — visual design tokens live here.
   Tweak colors, box size, glow, and gradient speed below. */

:root {
  --bg: #eef3f6;
  --bg-glow-1: #cfe4e2;
  --bg-glow-2: #dfd9ec;
  --ink: #243342;
  --ink-soft: #5b6b7a;
  --accent: #35847d;
  --accent-ink: #ffffff;
  --track: rgba(36, 51, 66, 0.16);
  --tick: rgba(36, 51, 66, 0.32);
  --chip-bg: rgba(36, 51, 66, 0.06);
  --chip-border: rgba(36, 51, 66, 0.14);
  --halo: rgba(70, 150, 142, 0.35);
  --focus: #2c6f69;

  --box-size: min(62vw, 260px);
  --gradient-period: 80s;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1721;
    --bg-glow-1: #14313a;
    --bg-glow-2: #1d2340;
    --ink: #dde7ee;
    --ink-soft: #8fa1b0;
    --accent: #63bcb2;
    --accent-ink: #08201d;
    --track: rgba(221, 231, 238, 0.18);
    --tick: rgba(221, 231, 238, 0.4);
    --chip-bg: rgba(221, 231, 238, 0.07);
    --chip-border: rgba(221, 231, 238, 0.16);
    --halo: rgba(80, 180, 168, 0.28);
    --focus: #7fd2c8;
  }
}

[data-theme="dark"] {
  --bg: #0d1721;
  --bg-glow-1: #14313a;
  --bg-glow-2: #1d2340;
  --ink: #dde7ee;
  --ink-soft: #8fa1b0;
  --accent: #63bcb2;
  --accent-ink: #08201d;
  --track: rgba(221, 231, 238, 0.18);
  --tick: rgba(221, 231, 238, 0.4);
  --chip-bg: rgba(221, 231, 238, 0.07);
  --chip-border: rgba(221, 231, 238, 0.16);
  --halo: rgba(80, 180, 168, 0.28);
  --focus: #7fd2c8;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over display:flex/grid rules */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Slow-drifting background glow */
body::before {
  content: "";
  position: fixed;
  inset: -30%;
  z-index: -1;
  background:
    radial-gradient(40% 40% at 30% 30%, var(--bg-glow-1) 0%, transparent 70%),
    radial-gradient(45% 45% at 70% 65%, var(--bg-glow-2) 0%, transparent 70%);
  animation: drift var(--gradient-period) ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes drift {
  from { transform: translate(-4%, -3%) scale(1); }
  to   { transform: translate(4%, 3%) scale(1.12); }
}

[data-motion="min"] body::before,
:root[data-motion="min"] body::before { animation: none; }

/* Layout */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

.brand {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
}

.brand-mark {
  width: 14px;
  height: 14px;
  border: 2.5px solid var(--accent);
  border-radius: 4px;
  display: inline-block;
}

main {
  flex: 1;
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 0 18px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* Stage & breathing box */
.stage {
  position: relative;
  width: 100%;
  height: max(32dvh, 240px);
  display: grid;
  place-items: center;
}

.halo {
  position: absolute;
  width: calc(var(--box-size) * 1.3);
  height: calc(var(--box-size) * 1.3);
  border-radius: 30%;
  background: radial-gradient(closest-side, var(--halo), transparent);
  filter: blur(18px);
  opacity: 0.3;
}

/* Visualizations (chosen per pattern in js/patterns.js):
   - square / triangle / perimeter: a dot traces the outline, one equal leg
     per phase — the dot's speed follows the timing; ticks mark the corners.
   - circle: expands as you breathe in, contracts as you breathe out;
     the faint ring shows "full lungs". */
.boxviz {
  position: relative;
  width: var(--box-size);
  height: var(--box-size);
}

.boxviz svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.track {
  fill: var(--accent);
  fill-opacity: 0.05;
  stroke: var(--track);
  stroke-width: 4;
  stroke-linejoin: miter;
  transition: fill-opacity 0.2s linear;
}

.guide {
  fill: none;
  stroke: var(--track);
  stroke-width: 3;
}

/* Marks how far the FIRST inhale of the sigh goes (before the top-up) */
.guide-mid {
  stroke-width: 2;
  stroke-dasharray: 4 7;
  stroke-linecap: round;
}

.bcirc {
  fill: var(--accent);
  fill-opacity: 0.1;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-opacity: 0.75;
}

.tick { fill: var(--tick); }

/* Quiet round counter under the box. Its line height is always reserved,
   so text appearing/disappearing never shifts the layout. */
.sessions {
  margin: -6px 0 0;
  min-height: 1.3em;
  font-size: 12.5px;
  color: var(--ink-soft);
  text-align: center;
  opacity: 0.85;
}

.dot {
  fill: var(--accent);
  filter: drop-shadow(0 0 7px var(--halo));
}

[data-motion="min"] .dot,
[data-motion="min"] #ticks { display: none; }

/* Phase text and countdown are centered TOGETHER as one block in the
   middle of the shape; empty elements take no space, so a lone number
   (pre-start countdown) or a lone label is also dead-center. */
.boxlabel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.phase {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-align: center;
  padding: 0 30px;
  color: var(--ink);
}

.count {
  font-size: 34px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  color: var(--ink-soft);
}

.phase:empty, .count:empty { display: none; }

/* Triangle viz: its visual center (centroid) is at h/6 below the box
   center — shift the text block down so it sits inside the triangle. */
.boxlabel.tri { transform: translateY(10.8%); }

/* Pre-start countdown: one big fading number */
.boxlabel.counting .count {
  font-size: 56px;
  color: var(--ink);
}

@keyframes bb-fade {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* Pattern list: options stacked, description beside each */
.plist {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 430px;
}

.prow {
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  border-radius: 14px;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.prow input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.prow-main {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  cursor: pointer;
}

.prow-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  min-width: 98px;
}

.prow-head b {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.prow-head small {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.prow-desc {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-soft);
}

.prow:has(input[type="radio"]:checked) {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.prow:has(input[type="radio"]:checked) .prow-head b { color: var(--accent); }

.prow:has(input[type="radio"]:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Chips (duration selector) */
.chips {
  border: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip { cursor: pointer; }

.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip span {
  display: inline-block;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  font-size: 14px;
  color: var(--ink);
  transition: background 0.25s, border-color 0.25s, color 0.25s;
}


.chips.small .chip span { padding: 6px 12px; font-size: 13px; }

.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Custom pattern editor — lives inside the Custom card */
.custom {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--chip-border);
}

.custom label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}

.custom input {
  width: 100%;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid var(--chip-border);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  text-align: center;
}

.custom input:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.start {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 14px 58px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform 0.15s, filter 0.2s;
}

.start:hover { filter: brightness(1.06); }
.start:active { transform: scale(0.97); }
.start:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Settings disclosure + toggles */
.settings-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.settings-row {
  display: flex;
  gap: 8px;
}

.settings-wrap .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#settingsBtn[aria-expanded="true"] {
  color: var(--ink);
  border-color: var(--tick);
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 340px;
}

/* Volume sliders inside the settings panel */
.vol {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.vol span { flex-shrink: 0; min-width: 92px; text-align: right; }

.vol input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle, .pill {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.25s, color 0.25s, border-color 0.25s;
}

.toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.toggle:focus-visible, .pill:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

footer {
  text-align: center;
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  opacity: 0.8;
}

footer p { margin: 0 0 8px; }

footer .about {
  max-width: 44ch;
  margin: 0 auto 10px;
  line-height: 1.5;
}

.support {
  margin: 0;
  font-size: 13px;
  text-align: center;
}

.kofi {
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 500;
  padding: 10px 20px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  transition: background 0.25s;
}

.kofi svg { width: 18px; height: 18px; }

.kofi:hover,
.kofi:focus-visible { background: var(--chip-bg); }

/* Legal pages (Impressum / Datenschutz) */
.legal {
  display: block;
  max-width: 560px;
  font-size: 14.5px;
  line-height: 1.6;
}

.legal h2 { font-size: 22px; font-weight: 600; }

.legal h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 22px 0 6px;
}

.legal p { margin: 0 0 12px; color: var(--ink); }

.legal a { color: var(--accent); }

a.brand { text-decoration: none; }

footer a {
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

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

@media (max-width: 380px) {
  :root { --box-size: min(64vw, 230px); }
  .phase { font-size: 18px; }
  .count { font-size: 30px; }
  .start { padding: 13px 46px; }
}
