:root {
  --bg-top: #fff6ed;
  --bg-bottom: #f7efe2;
  --panel: rgba(255, 250, 244, 0.82);
  --panel-border: rgba(126, 87, 58, 0.15);
  --text: #342319;
  --muted: #826c5c;
  --accent: #d9342b;
  --line: #efc6b8;
  --field-bg: rgba(255, 255, 255, 0.72);
  --card-bg: rgba(255, 255, 255, 0.62);
  --canvas-bg-inner: rgba(255, 255, 255, 0.98);
  --canvas-bg-mid: rgba(255, 249, 244, 0.86);
  --canvas-bg-outer: rgba(238, 214, 197, 0.55);
  --inhale: #e48a68;
  --hold-in: #d5a86a;
  --exhale: #c46a5b;
  --hold-out: #b98662;
  --shadow: 0 24px 60px rgba(109, 67, 39, 0.12);
}

[data-theme="dark"] {
  --bg-top: #231d1a;
  --bg-bottom: #14110f;
  --panel: rgba(34, 28, 24, 0.84);
  --panel-border: rgba(212, 176, 145, 0.12);
  --text: #f2e6d8;
  --muted: #c7b3a1;
  --accent: #ef9a7d;
  --line: rgba(210, 168, 138, 0.25);
  --field-bg: rgba(53, 45, 39, 0.86);
  --card-bg: rgba(42, 35, 31, 0.86);
  --canvas-bg-inner: rgba(38, 32, 29, 0.98);
  --canvas-bg-mid: rgba(29, 24, 21, 0.92);
  --canvas-bg-outer: rgba(56, 43, 35, 0.72);
  --inhale: #f0a17d;
  --hold-in: #d8b073;
  --exhale: #db8b7c;
  --hold-out: #c79b7a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 179, 142, 0.45), transparent 30%),
    radial-gradient(circle at bottom right, rgba(223, 81, 60, 0.14), transparent 28%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  transition: background 220ms ease, color 220ms ease;
}

.page-shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.hero-main {
  flex: 1;
}

.hero-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 10px;
  font-family: "Avenir Next", "DIN Alternate", sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #b05e46;
  font-size: 0.78rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 4.1rem);
  line-height: 1.02;
}

.hero-copy {
  max-width: 720px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 11px 16px;
  min-height: 46px;
  background: rgba(255, 250, 244, 0.55);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

[data-theme="dark"] .theme-toggle {
  background: rgba(40, 33, 29, 0.8);
}

.hero-badge {
  min-width: 180px;
  padding: 18px 20px;
  border-radius: 22px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.hero-badge span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.hero-badge strong {
  font-size: 1.6rem;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.controls-panel,
.status-panel {
  padding: 26px;
}

.controls-panel {
  grid-row: span 2;
}

.visual-panel {
  padding: 24px;
  min-height: 580px;
}

h2 {
  margin: 0 0 20px;
  font-size: 1.2rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field span {
  color: var(--muted);
  font-size: 0.92rem;
}

.field input {
  width: 100%;
  border: 1px solid rgba(150, 110, 82, 0.18);
  border-radius: 18px;
  padding: 14px 16px;
  min-height: 52px;
  background: var(--field-bg);
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.field input:focus {
  border-color: rgba(217, 52, 43, 0.48);
  box-shadow: 0 0 0 4px rgba(217, 52, 43, 0.1);
  transform: translateY(-1px);
}

.field-wide {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
}

.button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  min-height: 50px;
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-primary {
  background: linear-gradient(135deg, #f45541 0%, #d82d31 100%);
  color: #fff;
  box-shadow: 0 14px 28px rgba(217, 52, 43, 0.24);
}

.button-secondary {
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid rgba(150, 110, 82, 0.18);
}

.button-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed rgba(150, 110, 82, 0.24);
}

.hint {
  margin: 18px 0 0;
  color: #8f5542;
  line-height: 1.7;
  font-size: 0.92rem;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.phase-chip {
  border-radius: 999px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--inhale) 18%, transparent);
  color: var(--inhale);
  font-weight: 700;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  padding: 18px;
  border-radius: 22px;
  background: var(--card-bg);
  border: 1px solid rgba(150, 110, 82, 0.12);
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.stat-card strong {
  font-family: "Avenir Next", "DIN Alternate", sans-serif;
  font-size: clamp(1.4rem, 2vw, 1.9rem);
}

.visual-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.visual-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 0.92rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.inhale {
  background: var(--inhale);
}

.dot.hold-in {
  background: var(--hold-in);
}

.dot.exhale {
  background: var(--exhale);
}

.dot.hold-out {
  background: var(--hold-out);
}

.canvas-wrap {
  margin-top: 22px;
  min-height: 470px;
  display: grid;
  place-items: center;
  border-radius: 26px;
  background:
    radial-gradient(circle at center, var(--canvas-bg-inner) 0%, var(--canvas-bg-mid) 54%, var(--canvas-bg-outer) 100%);
  border: 1px solid rgba(168, 121, 92, 0.14);
  overflow: hidden;
}

#breathSvg {
  width: min(100%, 700px);
  aspect-ratio: 1;
}

.base-path {
  fill: rgba(255, 255, 255, 0.05);
  stroke: rgba(183, 143, 113, 0.18);
  stroke-width: 1.25;
}

.segment-path {
  fill: none;
  stroke-width: 2.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

.segment-inhale {
  stroke: var(--inhale);
}

.segment-hold-in {
  stroke: var(--hold-in);
}

.segment-exhale {
  stroke: var(--exhale);
}

.segment-hold-out {
  stroke: var(--hold-out);
}

.phase-path {
  fill: none;
  stroke: var(--inhale);
  stroke-width: 3.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 10px rgba(214, 120, 89, 0.3));
}

.progress-dot {
  fill: var(--accent);
  filter: drop-shadow(0 0 8px rgba(213, 120, 89, 0.38));
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls-panel {
    grid-row: auto;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .visual-head {
    flex-direction: column;
  }

  .legend {
    justify-content: flex-start;
  }

  .hero-tools {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
  }

  .hero {
    flex-direction: column;
  }

  .hero-tools {
    flex-direction: column;
    align-items: stretch;
  }

  .theme-toggle {
    width: 100%;
  }

  .hero-badge {
    min-width: 0;
    width: 100%;
  }

  .field-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .visual-panel {
    min-height: auto;
  }

  .canvas-wrap {
    min-height: 340px;
  }
}
