:root {
  color-scheme: dark;
  --bg: #12161c;
  --surface: #1c2430;
  --text: #e8eef4;
  --muted: #9fb0c2;
  --line: #2d3a4a;
  --accent: #134b5a;
  --accent-text: #f4fbfd;
  --focus: #f2d48a;
  --emergency: #f6e6d4;
  --shadow: 0 0 0 1px #2d3a4a;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Segoe UI", sans-serif;
  line-height: 1.45;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #e7edf2;
    --surface: #f4f7f9;
    --text: #14202b;
    --muted: #3e4c5c;
    --line: #c5d0da;
    --accent: #0f4c5c;
    --accent-text: #f4fbfd;
    --focus: #0f4c5c;
    --emergency: #6a3b12;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e7edf2;
  --surface: #f4f7f9;
  --text: #14202b;
  --muted: #3e4c5c;
  --line: #c5d0da;
  --accent: #0f4c5c;
  --accent-text: #f4fbfd;
  --focus: #0f4c5c;
  --emergency: #6a3b12;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161c;
  --surface: #1c2430;
  --text: #e8eef4;
  --muted: #9fb0c2;
  --line: #2d3a4a;
  --accent: #134b5a;
  --accent-text: #f4fbfd;
  --focus: #f2d48a;
  --emergency: #f6e6d4;
}

html[data-font="lg"] { font-size: 112.5%; }
html[data-font="xl"] { font-size: 125%; }

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

.shell {
  width: min(100%, 34rem);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.skip {
  position: absolute;
  left: 8px;
  top: -4rem;
  background: var(--bg);
  color: var(--text);
  padding: 8px 12px;
}

.skip:focus { top: 8px; z-index: 3; }

.top {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
}

.top h1 {
  flex: 1;
  margin: 0;
  min-width: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn, #back {
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 10px;
}

main {
  flex: 1;
  padding: 8px 16px 20px;
  outline: none;
}

.helpbar {
  text-align: center;
  padding: 4px 16px calc(8px + env(safe-area-inset-bottom));
}

.helpbar a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0 12px;
  color: var(--text);
}

button, .btn, .hero, .item, .tel, .text-link {
  font: inherit;
  color: var(--text);
}

button, .btn, .hero, .item, .tel {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
}

button, .btn {
  min-height: 2.75rem;
  padding: 10px 14px;
  cursor: pointer;
}

.hero, .btn.primary, button[aria-pressed="true"], button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 5.5rem;
  margin: 8px 0 18px;
  font-size: 1.45rem;
  text-decoration: none;
  font-weight: 650;
}

.group-title {
  margin: 16px 0 8px;
  font-size: 0.95rem;
  font-weight: 650;
}

.items { display: grid; gap: 8px; }

.item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 2.75rem;
  padding: 10px 12px;
  text-decoration: none;
}

.item-title { font-weight: 650; }

.item-desc, .hint, .disclaimer { color: var(--muted); }

.hint, .disclaimer, .lead-sm, .remain, .result { margin: 8px 0; }

.text-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  margin-top: 12px;
}

.practice { display: flex; flex-direction: column; gap: 8px; }

.moods {
  border: 0;
  margin: 0;
  padding: 0;
}

.moods legend { padding: 0; font-weight: 650; }

.mood-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.score { width: 100%; padding: 0; }

.breath {
  position: relative;
  width: min(72vw, 280px);
  aspect-ratio: 1;
  margin: 8px auto;
}

.ring { width: 100%; height: 100%; }

.ring-bg { fill: none; stroke: var(--line); stroke-width: 3; }

.ring-fg {
  fill: none;
  stroke: #7eb8c9;
  stroke-width: 3;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.orb {
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #3d8494, #17343d 72%);
  transform: scale(0.78);
  transition: transform linear;
}

.orb[data-key="inhale"], .orb[data-key="hold"] { transform: scale(1); }
.orb[data-key="topup"] { transform: scale(1.06); }
.orb[data-key="exhale"] { transform: scale(0.78); }

.phase, .lead {
  margin: 8px 0;
  text-align: center;
  font-size: 1.6rem;
  font-weight: 650;
}

.lead { text-align: start; font-size: 1.45rem; }

.count, .remain { text-align: center; font-variant-numeric: tabular-nums; }

.count { font-size: 2rem; margin: 0; }

.controls, .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.controls .btn, .chips .btn { flex: 1 1 8rem; }

.volume {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 2.75rem;
}

input[type="range"] { width: 100%; min-height: 2.75rem; }

textarea {
  width: 100%;
  min-height: 8rem;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 2.75rem;
}

.choice input { width: 1.3rem; height: 1.3rem; }

.paper { transform-origin: 50% 80%; }

.paper.is-away { animation: fold 700ms ease forwards; }

@keyframes fold {
  to { transform: translateY(1.5rem) scale(0.2); opacity: 0; }
}

.big-count {
  width: min(100%, 12rem);
  min-height: 7rem;
  margin: 8px auto;
  font-size: 3rem;
  display: block;
}

.tel {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 2.75rem;
  margin: 8px 0;
  padding: 12px;
  text-decoration: none;
  font-weight: 650;
}

.emergency { color: var(--emergency); font-weight: 650; }

.log-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 8px; }

.log-list li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: var(--surface);
  border-radius: 14px;
  overflow-wrap: anywhere;
}

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

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

:focus { outline: none; }

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

button:disabled { opacity: 0.45; }

@media (max-width: 359px) {
  .mood-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .orb { transition: none !important; transform: none !important; }
  .orb[data-key="inhale"], .orb[data-key="topup"] { opacity: 1; filter: brightness(1.35); }
  .orb[data-key="hold"] { opacity: 0.8; filter: brightness(1.1); }
  .orb[data-key="exhale"] { opacity: 0.5; filter: brightness(0.8); }
  .paper.is-away { animation: none; opacity: 0; }
}
