:root {
  color-scheme: light dark;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #edf3f5;
  --text: #10212d;
  --muted: #60717d;
  --line: #d7e1e5;
  --primary: #153b5b;
  --primary-strong: #0d2b44;
  --accent: #4e8a88;
  --danger: #a93636;
  --warning: #7e5b15;
  --shadow: 0 10px 28px rgba(27, 54, 69, 0.08);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(78, 138, 136, 0.12), transparent 32rem),
    var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.58; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(104px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 2px 18px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.02em; }
.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
.status-pill, .score-badge {
  border-radius: 999px;
  background: #e3f2ec;
  color: #1e674f;
  padding: 7px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}
.status-pill.offline { background: #f6ead3; color: var(--warning); }

#app:focus { outline: none; }
.page-heading { margin: 8px 2px 18px; }
.page-heading h2 { margin: 0; font-size: clamp(1.65rem, 6vw, 2.35rem); letter-spacing: -0.045em; }
.page-heading p { margin: 8px 0 0; max-width: 58ch; color: var(--muted); line-height: 1.55; }

.card, .hero-action, .protocol-card {
  border: 1px solid rgba(215, 225, 229, 0.9);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow);
}
.card { margin: 14px 0; padding: 18px; }
.card h3 { margin: 0; font-size: 1.05rem; }
.card p { line-height: 1.55; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.card-grid { display: grid; gap: 10px; }
.stats-grid { grid-template-columns: repeat(3, 1fr); margin: 14px 0; }
.stat-card { margin: 0; min-width: 0; text-align: center; }
.stat-value { display: block; font-size: 1.65rem; font-weight: 800; }
.stat-label { display: block; margin-top: 5px; color: var(--muted); font-size: 0.74rem; line-height: 1.25; }

.hero-action {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  padding: 21px;
  background: linear-gradient(135deg, var(--primary), #255b76);
  color: white;
  text-align: left;
}
.hero-action strong, .hero-action small { display: block; }
.hero-action strong { font-size: 1.08rem; }
.hero-action small { margin-top: 5px; opacity: 0.78; }
.hero-action > span:last-child { font-size: 1.6rem; }

.button {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 10px 15px;
  font-weight: 750;
}
.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-strong); }
.button-secondary { border-color: var(--line); background: var(--surface-soft); color: var(--text); }
.button-danger { background: var(--danger); color: white; }
.button-small { min-height: 36px; padding: 7px 11px; }
.text-button { border: 0; background: none; color: var(--primary); font-weight: 750; }
.button-row { display: flex; gap: 10px; }
.button-row .button { flex: 1; }
.button-row.wrap { flex-wrap: wrap; }

.stack { display: grid; gap: 17px; }
.field { display: grid; gap: 8px; }
.field > span, fieldset legend { font-weight: 750; }
.field-help, .field small, .muted { margin: 0; color: var(--muted); font-size: 0.86rem; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 13px;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}
fieldset.field { margin: 0; border: 0; padding: 0; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--surface-soft);
}
.choice input { width: auto; margin-top: 3px; accent-color: var(--primary); }
.range-row { display: flex; align-items: center; gap: 14px; }
.range-row input { padding: 0; accent-color: var(--primary); }
.range-row output { min-width: 42px; text-align: center; font-size: 1.25rem; font-weight: 800; }

.step-progress { display: flex; gap: 8px; margin: 0 2px 14px; }
.step-dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}
.step-dot.active { background: var(--primary); border-color: var(--primary); color: white; }
.protocol-card { padding: 18px; }
.breathing-card { padding: 16px; border-radius: 15px; background: var(--surface-soft); }
.breathing-card h3 { margin: 0; }
.breathing-status { min-height: 28px; margin-top: 12px; color: var(--accent); font-size: 1.08rem; font-weight: 800; }

.notice { margin: 14px 0; border-radius: 14px; padding: 14px; line-height: 1.48; }
.notice-neutral { background: #e9f1f4; color: #29495a; }
.notice-warning { background: #f6ecd7; color: #674a10; }
.notice-error { background: #f8dddd; color: #7c2424; }

.details-list { display: grid; gap: 10px; margin: 15px 0 0; }
.details-list > div { display: grid; grid-template-columns: minmax(90px, 0.38fr) 1fr; gap: 12px; }
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.session-list { display: grid; gap: 4px; }
.session-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.session-row:last-child { border-bottom: 0; }
.session-row strong, .session-row span { display: block; }
.session-row > div span { margin-top: 4px; color: var(--muted); font-size: 0.78rem; }
.empty-state { padding: 22px 4px; color: var(--muted); text-align: center; }

.file-picker {
  display: grid;
  place-items: center;
  min-height: 100px;
  border: 1px dashed var(--accent);
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--primary);
  font-weight: 750;
}
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.import-summary { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.safety-confirmation { display: grid; gap: 12px; margin-top: 12px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.safety-confirmation[hidden] { display: none; }
.version-card { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 10px; color: var(--muted); font-size: 0.76rem; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 760px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  backdrop-filter: blur(18px);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.nav-item {
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 58px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.nav-item.active { background: var(--surface-soft); color: var(--primary); }
.nav-primary .nav-icon { font-size: 1.3rem; }
.nav-icon { font-size: 1.15rem; }

.update-banner {
  position: fixed;
  z-index: 40;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 520px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-radius: 14px;
  background: var(--primary-strong);
  color: white;
  padding: 11px 12px 11px 15px;
  box-shadow: var(--shadow);
}
.toast-region { position: fixed; z-index: 50; right: 14px; bottom: 92px; display: grid; gap: 8px; }
.toast { max-width: min(360px, calc(100vw - 28px)); border-radius: 12px; background: var(--primary-strong); color: white; padding: 12px 14px; box-shadow: var(--shadow); }
.toast-success { background: #24664f; }
.toast-warning { background: #7a5713; }
.toast-error { background: #8d2f2f; }

@media (max-width: 520px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid .stat-card:first-child { grid-column: span 2; }
  .details-list > div { grid-template-columns: 1fr; gap: 3px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d171d;
    --surface: #14242d;
    --surface-soft: #1a303a;
    --text: #eef5f7;
    --muted: #a3b5be;
    --line: #2d4651;
    --primary: #407c9b;
    --primary-strong: #275d79;
    --accent: #76b6b0;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  }
  .notice-neutral { background: #19313d; color: #c6dfe9; }
  .notice-warning { background: #3e321c; color: #f5daa4; }
  .notice-error { background: #482426; color: #ffd4d4; }
  .status-pill { background: #18392f; color: #9ee0c8; }
}
