:root {
  color-scheme: light;
  --ink: #17372f;
  --muted: #6f807b;
  --green: #356e61;
  --green-dark: #24574c;
  --green-soft: #dcebe4;
  --cream: #f8f5ed;
  --paper: rgba(255, 255, 255, .72);
  --gold: #c28a45;
  --line: rgba(41, 91, 78, .14);
  --phase-color: #356e61;
  --phase-wash: rgba(53, 110, 97, .10);
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-display: "Noto Serif TC", "PMingLiU", serif;
  font-family: var(--font-sans);
}

html[lang="zh-Hans"] {
  --font-sans: "Noto Sans SC", "Microsoft YaHei", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  --font-display: "SimSun", "Noto Sans SC", serif;
}

html[lang="en"] {
  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #edf5f0; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(255,255,255,.9), transparent 28rem),
    radial-gradient(circle at 86% 42%, rgba(194,138,69,.10), transparent 24rem),
    linear-gradient(145deg, #edf6f1 0%, #f7f5ed 54%, #edf3ee 100%);
}

body::before {
  content: "";
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 37%, var(--phase-wash), transparent 58%);
  transition: opacity .5s ease, background .7s ease;
}

body[data-running="true"]::before { opacity: 1; }
body[data-running="true"][data-phase="inhale"] { --phase-color: #27826e; --phase-wash: rgba(39, 130, 110, .20); }
body[data-running="true"][data-phase="hold"] { --phase-color: #477ca8; --phase-wash: rgba(71, 124, 168, .20); }
body[data-running="true"][data-phase="exhale"] { --phase-color: #bd7138; --phase-wash: rgba(189, 113, 56, .20); }
body[data-running="true"][data-phase="rest"] { --phase-color: #766b94; --phase-wash: rgba(118, 107, 148, .19); }

button, a, select { -webkit-tap-highlight-color: transparent; }
button, select { font: inherit; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid rgba(194, 138, 69, .55); outline-offset: 3px; }
.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; }

.app-shell { position: relative; z-index: 1; width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 40px; }
.topbar { min-width: 0; height: 94px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.brand { min-width: 0; display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid rgba(53,110,97,.25); border-radius: 50%; }
.brand-mark svg { width: 30px; fill: none; stroke: var(--green); stroke-width: 1.6; stroke-linecap: round; }
.brand strong { display: block; font-family: var(--font-display); font-size: 18px; letter-spacing: .14em; }
.topbar-tools { min-width: 0; display: flex; flex: 0 1 auto; align-items: center; gap: 22px; margin-left: auto; }
.language-picker { position: relative; min-width: 0; }
.language-picker::after { content: ""; position: absolute; top: 50%; right: 16px; width: 7px; height: 7px; border-right: 2px solid var(--green-dark); border-bottom: 2px solid var(--green-dark); pointer-events: none; transform: translateY(-70%) rotate(45deg); }
.language-picker select { appearance: none; max-width: 100%; min-height: 36px; padding: 0 36px 0 13px; border: 1px solid rgba(53,110,97,.2); border-radius: 20px; color: var(--green-dark); background-color: rgba(255,255,255,.58); cursor: pointer; font-size: 11px; }
html[lang="en"] .brand strong,
html[lang="en"] h1,
html[lang="en"] .phase-title-row h2,
html[lang="en"] .section-heading h2 { letter-spacing: .04em; }
html[lang="en"] .eyebrow,
html[lang="en"] .intro,
html[lang="en"] .footer-note { letter-spacing: .06em; }

.hero { padding: 48px 0 20px; text-align: center; }
.eyebrow { margin: 0 0 10px; color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .28em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-family: var(--font-display); font-size: clamp(32px, 4vw, 50px); font-weight: 500; letter-spacing: .12em; }
.intro { color: var(--muted); font-size: 14px; letter-spacing: .12em; }

.trainer { position: relative; margin-top: 12px; padding: 28px 0 0; }
.phase-readout { position: relative; z-index: 2; text-align: center; }
.phase-title-row { display: flex; justify-content: center; align-items: baseline; gap: 11px; margin: 7px 0 3px; }
.phase-title-row h2 { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 500; letter-spacing: .15em; }
.phase-readout p { display: flex; align-items: baseline; justify-content: center; gap: 5px; margin-bottom: 0; color: var(--muted); }
.phase-readout p strong { color: var(--ink); font-family: Georgia, serif; font-size: 24px; font-weight: 400; }
.phase-readout p span { font-size: 11px; }
body[data-running="true"] .phase-title-row h2,
body[data-running="true"] .phase-readout p strong { color: var(--phase-color); transition: color .45s ease; }

.visualizer { position: relative; margin-top: -48px; overflow: hidden; }
#breathing-svg { display: block; width: 100%; height: auto; min-height: 270px; }
.guide-line { fill: none; stroke: rgba(53,110,97,.08); stroke-width: 1; stroke-dasharray: 4 10; }
.breathing-path { fill: none; stroke: url(#line-gradient); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.breathing-path.shadow { stroke: rgba(53,110,97,.10); stroke-width: 9; filter: blur(5px); }
.center-guide { stroke: rgba(53,110,97,.10); stroke-width: 1; stroke-dasharray: 2 8; }
.ball-halo { fill: rgba(213,161,92,.18); filter: url(#ball-glow); }
.ball { fill: url(#ball-gradient); stroke: rgba(255,255,255,.9); stroke-width: 2; filter: url(#ball-glow); }
body[data-running="true"] .breathing-path { stroke: var(--phase-color); transition: stroke .45s ease; }
body[data-running="true"] .breathing-path.shadow { stroke: var(--phase-color); opacity: .22; }
body[data-running="true"] .ball { fill: var(--phase-color); transition: fill .45s ease; }
body[data-running="true"] .ball-halo { fill: var(--phase-color); opacity: .28; animation: breathing-pulse 1.6s ease-in-out infinite; }
.edge-fade { position: absolute; inset: 0 auto 0 0; width: 14%; pointer-events: none; background: linear-gradient(90deg, #f1f6f1, transparent); }
.edge-fade.right { inset: 0 0 0 auto; background: linear-gradient(-90deg, #f2f4ed, transparent); }

.phase-steps { display: grid; grid-template-columns: repeat(4, 1fr); margin: -28px auto 0; width: min(780px, 88%); border-top: 1px solid var(--line); }
.phase-steps > div { position: relative; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px; padding: 16px 10px 0; opacity: .4; transition: opacity .3s ease, transform .3s ease; }
.phase-steps > div::before { content: ""; position: absolute; top: -4px; left: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.phase-steps span { color: var(--gold); font: 13px Georgia, serif; }
.phase-steps strong { font-size: 12px; letter-spacing: .12em; }
body[data-running="true"][data-phase="inhale"] [data-step="inhale"], body[data-running="true"][data-phase="hold"] [data-step="hold"], body[data-running="true"][data-phase="exhale"] [data-step="exhale"], body[data-running="true"][data-phase="rest"] [data-step="rest"] { color: var(--phase-color); opacity: 1; transform: translateY(-2px); }
body[data-running="true"] .phase-steps > div::before { background: var(--phase-color); }

.settings { margin-top: 58px; padding: 34px 38px 28px; border: 1px solid rgba(53,110,97,.12); border-radius: 24px; background: var(--paper); box-shadow: 0 18px 55px rgba(46,78,68,.07); backdrop-filter: blur(12px); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 25px; }
.section-heading .eyebrow { margin-bottom: 7px; }
.section-heading h2 { margin: 0; font-family: var(--font-display); font-size: 25px; letter-spacing: .12em; }
.duration-grid { display: grid; grid-template-columns: repeat(4, 1fr); }
.duration-card { min-width: 0; padding: 0 24px; border-left: 1px solid var(--line); }
.duration-card:first-child { padding-left: 0; border-left: 0; }
.duration-card:last-child { padding-right: 0; }
.duration-card > div:first-child { display: flex; align-items: center; gap: 8px; }
.duration-card > div:first-child strong { font-size: 13px; letter-spacing: .12em; }
.phase-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.duration-card[data-control="hold"] .phase-dot { background: #8c9e91; }
.duration-card[data-control="exhale"] .phase-dot { background: var(--gold); }
.duration-card[data-control="rest"] .phase-dot { background: #92aaa5; }
.stepper { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px; margin-top: 16px; }
.stepper button { width: 38px; height: 38px; border: 1px solid rgba(53,110,97,.18); border-radius: 50%; color: var(--green-dark); background: rgba(255,255,255,.7); cursor: pointer; font-size: 19px; transition: background .2s ease, transform .2s ease; }
.stepper button:hover:not(:disabled) { background: var(--green-soft); transform: translateY(-1px); }
.stepper button:disabled { cursor: not-allowed; opacity: .28; }
.stepper output { display: flex; min-width: 0; align-items: baseline; justify-content: center; gap: 4px; }
.stepper output strong { font: 30px Georgia, serif; font-weight: 400; }
.stepper output span { color: var(--muted); font-size: 10px; }
.stats { display: flex; align-items: center; justify-content: center; gap: 38px; margin-top: 28px; padding-top: 23px; border-top: 1px solid var(--line); }
.stats div { display: flex; gap: 12px; align-items: baseline; }
.stats div > span { color: var(--muted); font-size: 11px; letter-spacing: .1em; }
.stats div > span:empty { display: none; }
.stats strong { font-family: var(--font-display); font-size: 18px; font-weight: 400; }
.stats-divider { width: 1px; height: 20px; background: var(--line); }

.audio-settings { margin-top: 27px; padding-top: 25px; border-top: 1px solid var(--line); }
.audio-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.audio-heading > div { display: flex; align-items: center; gap: 12px; }
.audio-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--green-dark); background: var(--green-soft); font: 19px Georgia, serif; }
.audio-heading h3 { margin: 0; font-family: var(--font-display); font-size: 16px; letter-spacing: .1em; }
.audio-heading p { margin: 4px 0 0; color: var(--muted); font-size: 10px; letter-spacing: .05em; }
.audio-status { padding: 6px 10px; border-radius: 18px; color: var(--green-dark); background: var(--green-soft); font-size: 10px; letter-spacing: .08em; }
.audio-status.is-off { color: var(--muted); background: rgba(111,128,123,.12); }
.audio-controls { display: grid; grid-template-columns: minmax(220px, .75fr) minmax(280px, 1.25fr); gap: 42px; align-items: end; margin-top: 22px; }
.sound-mode { min-width: 0; margin: 0; padding: 0; border: 0; }
.sound-mode legend, .volume-control > label { display: block; margin-bottom: 9px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .1em; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border: 1px solid rgba(53,110,97,.15); border-radius: 24px; background: rgba(235,242,237,.7); }
.segmented-control label { cursor: pointer; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { display: grid; place-items: center; min-height: 34px; border-radius: 19px; color: var(--muted); font-size: 11px; transition: color .2s ease, background .2s ease, box-shadow .2s ease; }
.segmented-control input:checked + span { color: white; background: var(--green-dark); box-shadow: 0 4px 12px rgba(36,87,76,.18); }
.segmented-control input:focus-visible + span { outline: 3px solid rgba(194,138,69,.55); outline-offset: 2px; }
.volume-control > label { display: flex; justify-content: space-between; }
.volume-control output { color: var(--green-dark); font-size: 12px; }
.volume-control > div { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; color: var(--muted); }
.volume-control input { width: 100%; accent-color: var(--green-dark); cursor: pointer; }
.volume-control input:disabled { cursor: not-allowed; opacity: .4; }

.playback { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 28px; }
.playback button { min-height: 48px; border-radius: 30px; cursor: pointer; }
.primary-control { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 180px; padding: 0 26px; border: 0; color: white; background: var(--green-dark); box-shadow: 0 10px 24px rgba(36,87,76,.22); }
.primary-control:hover { background: #194b41; }
.play-icon { width: 0; height: 0; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 9px solid currentColor; }
body[data-running="true"] .primary-control { cursor: default; background: var(--phase-color); box-shadow: 0 0 0 6px color-mix(in srgb, var(--phase-color) 12%, transparent), 0 12px 30px color-mix(in srgb, var(--phase-color) 35%, transparent); transition: background .45s ease, box-shadow .45s ease; }
body[data-running="true"] .play-icon { width: 9px; height: 9px; border: 0; border-radius: 50%; background: currentColor; animation: status-pulse 1.4s ease-in-out infinite; }
.secondary-control { display: flex; align-items: center; justify-content: center; gap: 9px; min-width: 118px; padding: 0 22px; border: 1px solid rgba(53,110,97,.25); color: var(--green-dark); background: rgba(255,255,255,.6); }
.secondary-control:disabled { cursor: not-allowed; opacity: .38; }
.pause-icon { width: 9px; height: 11px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; }
.text-control { padding: 0 14px; border: 0; color: var(--muted); background: transparent; }
.text-control:hover { color: var(--ink); }
.footer-note { margin: 28px 0 0; color: var(--muted); text-align: center; font-family: var(--font-display); font-size: 13px; font-style: italic; letter-spacing: .15em; }

@keyframes breathing-pulse {
  0%, 100% { transform: scale(.82); opacity: .18; }
  50% { transform: scale(1.18); opacity: .38; }
}

@keyframes status-pulse {
  0%, 100% { opacity: .45; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.15); }
}

@media (max-width: 900px) {
  .topbar { height: auto; min-height: 94px; padding: 12px 0; flex-wrap: wrap; row-gap: 9px; }
}

@media (max-width: 780px) {
  .app-shell { width: min(100% - 28px, 680px); }
  .topbar { min-height: 80px; }
  .topbar-tools { gap: 12px; }
  .hero { padding-top: 36px; }
  .trainer { padding-top: 20px; }
  .visualizer { margin: -30px -14px 0; }
  #breathing-svg { min-height: 250px; }
  .phase-steps { width: 100%; margin-top: -20px; }
  .phase-steps > div { padding-inline: 5px; }
  .phase-steps > div { min-width: 0; }
  .phase-steps span { display: none; }
  .phase-steps strong { grid-column: 1; }
  .settings { margin-top: 46px; padding: 28px 24px 24px; }
  .duration-grid { grid-template-columns: repeat(2, 1fr); gap: 28px 0; }
  .duration-card { padding: 0 18px; }
  .duration-card:nth-child(3) { padding-left: 0; border-left: 0; }
  .duration-card:nth-child(2) { padding-right: 0; }
  .stepper { grid-template-columns: 42px 1fr 42px; }
  .stepper button { width: 42px; height: 42px; }
}

@media (max-width: 520px) {
  .app-shell { width: min(100% - 22px, 480px); }
  .brand-mark { width: 40px; height: 40px; }
  .brand strong { font-size: 15px; }
  .topbar-tools { gap: 7px; }
  .language-picker select { min-height: 34px; max-width: 92px; padding-left: 10px; font-size: 10px; }
  html[lang="en"] .brand strong { max-width: 82px; font-size: 13px; }
  .hero { padding-bottom: 8px; }
  h1 { font-size: 31px; }
  .intro { font-size: 12px; letter-spacing: .06em; }
  .phase-title-row h2 { font-size: 26px; }
  .visualizer { margin-top: -12px; }
  #breathing-svg { min-height: 210px; }
  .phase-steps { margin-top: -5px; }
  .phase-steps > div { text-align: center; }
  .phase-steps > div::before { left: 50%; transform: translateX(-50%); }
  .section-heading { align-items: start; flex-direction: column; }
  .settings { padding: 25px 16px 22px; border-radius: 20px; }
  .duration-card { padding-inline: 10px; }
  .duration-card > div:first-child { justify-content: center; }
  .stepper { gap: 3px; grid-template-columns: 40px 1fr 40px; }
  .stepper button { width: 40px; height: 40px; }
  .stats { gap: 17px; }
  .stats div { display: grid; gap: 3px; text-align: center; }
  .playback { display: grid; grid-template-columns: 1fr 1fr; }
  .primary-control { min-width: 0; }
  .secondary-control { min-width: 0; }
  .text-control { grid-column: 1 / 3; }
  .audio-heading { align-items: flex-start; }
  .audio-heading p { max-width: 210px; }
  .audio-controls { grid-template-columns: 1fr; gap: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .ball-halo { display: none; }
  body[data-running="true"] .play-icon { animation: none; }
}

@media (prefers-contrast: more) {
  :root { --muted: #45544f; --line: rgba(20,50,42,.38); }
  .breathing-path { stroke: #174d40; stroke-width: 4; }
  .stepper button { border-color: var(--ink); }
}
