:root {
  color-scheme: light;
  --bg: #f6f8f5;
  --surface: #ffffff;
  --surface-2: #edf4f1;
  --text: #15211f;
  --muted: #60716d;
  --line: #d9e3df;
  --primary: #2f6f68;
  --primary-strong: #1f5853;
  --primary-soft: #dceee9;
  --accent: #916a35;
  --warn: #9f5b23;
  --danger: #a33d3d;
  --danger-soft: #f7dfdf;
  --shadow: 0 18px 50px rgba(26, 45, 42, 0.12);
  --radius: 8px;
  --tap: 46px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111715;
  --surface: #18211f;
  --surface-2: #202d2a;
  --text: #eef6f3;
  --muted: #a9bbb6;
  --line: #31423e;
  --primary: #79c8bb;
  --primary-strong: #a1ddd3;
  --primary-soft: #203b37;
  --accent: #e0b56f;
  --warn: #e2a260;
  --danger: #ff9a9a;
  --danger-soft: #472625;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(47, 111, 104, 0.13), transparent 34rem),
    linear-gradient(180deg, var(--bg), var(--surface-2));
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

button:hover,
.file-button:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-button:focus-within {
  outline: 3px solid color-mix(in srgb, var(--primary) 38%, transparent);
  outline-offset: 2px;
}

button.primary,
.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

[data-theme="dark"] button.primary,
[data-theme="dark"] .primary {
  color: #08221e;
}

button.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0.78rem 0.85rem;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
}

label > span,
label input,
label textarea,
label select {
  font-weight: 500;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.65rem;
  font-size: clamp(2rem, 10vw, 3.6rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 1.18rem;
  line-height: 1.18;
  margin-bottom: 0.7rem;
}

h3 {
  font-size: 1rem;
  margin-bottom: 0.35rem;
}

p {
  color: var(--muted);
}

ul {
  padding-left: 1.25rem;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 20;
  background: var(--surface);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 1rem;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 70px;
  padding: 0.7rem max(1rem, env(safe-area-inset-left)) 0.7rem max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.72rem;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.brand:hover {
  transform: none;
}

.brand small,
.brand strong {
  display: block;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 900;
}

[data-theme="dark"] .brand-mark {
  color: #08221e;
}

.menu-toggle {
  display: grid;
  gap: 4px;
  width: 46px;
  padding: 0.65rem;
}

.menu-toggle span {
  display: block;
  height: 2px;
  background: currentColor;
}

.icon-button {
  place-items: center;
}

.safety-chip {
  margin-left: auto;
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
  color: var(--danger);
  font-weight: 800;
}

.sidebar {
  position: fixed;
  inset: 70px auto 0 0;
  z-index: 9;
  width: min(86vw, 300px);
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  transition: transform 180ms ease;
}

.sidebar.open {
  transform: translateX(0);
}

.nav-list {
  display: grid;
  gap: 0.35rem;
}

.nav-list button {
  justify-content: flex-start;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.nav-list button.active,
.bottom-nav button.active {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 6.25rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 180ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-panel {
  min-height: min(58vh, 620px);
  display: grid;
  align-content: end;
  padding: clamp(1.25rem, 6vw, 3rem);
  margin: 0 -1rem 1rem;
  background:
    linear-gradient(145deg, rgba(18, 36, 34, 0.9), rgba(31, 88, 83, 0.7)),
    linear-gradient(135deg, #2f6f68, #d2e5de 68%, #f6f8f5);
  color: #fff;
}

.hero-panel p,
.hero-panel .eyebrow {
  color: rgba(255, 255, 255, 0.86);
  max-width: 720px;
}

.hero-panel h1 {
  max-width: 830px;
}

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--primary-strong);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin: 1rem 0;
}

.section-head p {
  max-width: 720px;
}

.card,
.notice,
.result-panel,
.tool-workspace {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.card,
.notice,
.result-panel {
  padding: 1rem;
}

.notice {
  margin-bottom: 1rem;
}

.safety-notice {
  border-color: color-mix(in srgb, var(--warn) 32%, var(--line));
  background: color-mix(in srgb, var(--surface) 78%, #f6e8cf);
}

.danger-notice {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  background: var(--danger-soft);
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.form-grid {
  display: grid;
  gap: 1rem;
}

.two-column {
  display: grid;
  gap: 1rem;
}

.choice-grid,
.metric-grid,
.insight-grid,
.tool-grid,
.heat-grid {
  display: grid;
  gap: 0.75rem;
}

.choice-card {
  text-align: left;
  font-weight: 900;
  min-height: 76px;
}

.choice-card.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-strong);
}

.tool-card.active,
.exercise-tabs button.active,
.insight-card[aria-expanded="true"] {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-strong);
}

.button-row,
.button-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button-row > *,
.button-stack > * {
  flex: 1 1 auto;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.check-row input {
  width: 22px;
  min-width: 22px;
  height: 22px;
  margin-top: 0.1rem;
}

.metric-card {
  min-height: 118px;
  display: grid;
  align-content: space-between;
}

.metric-card strong {
  font-size: 1.8rem;
  line-height: 1;
}

.metric-card span {
  color: var(--muted);
  font-weight: 800;
}

.trend-bars {
  display: grid;
  grid-template-columns: repeat(7, minmax(28px, 1fr));
  gap: 0.45rem;
  align-items: end;
  min-height: 150px;
}

.trend-bar {
  display: grid;
  align-items: end;
  gap: 0.35rem;
  height: 150px;
}

.trend-bar div {
  min-height: 6px;
  border-radius: 6px 6px 0 0;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}

.trend-bar span {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.stack,
.insight-list,
.lesson-list {
  display: grid;
  gap: 0.75rem;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0.3rem 0.62rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-weight: 800;
  font-size: 0.86rem;
}

.assessment-form {
  display: grid;
  gap: 1rem;
}

.question-card {
  display: grid;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.question-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.scale-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.scale-row label {
  min-height: 56px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
}

.scale-row input {
  width: auto;
}

.scale-row label:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.result-panel {
  margin-top: 1rem;
}

.pattern-badge {
  display: inline-flex;
  margin-bottom: 0.75rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-weight: 900;
}

[data-theme="dark"] .pattern-badge {
  color: #08221e;
}

.pattern-badge.high {
  background: var(--danger);
  color: #fff;
}

.insight-card,
.tool-card,
.lesson-card {
  display: grid;
  gap: 0.45rem;
  text-align: left;
  min-height: 132px;
  align-content: start;
}

.insight-card p,
.tool-card p,
.lesson-card p {
  margin-bottom: 0;
}

.exercise-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
}

.exercise-tabs button {
  white-space: nowrap;
}

.exercise-panel {
  display: grid;
  gap: 0.85rem;
}

.heat-grid {
  grid-template-columns: 1fr;
}

.heat-button {
  min-height: 74px;
  text-align: left;
  font-weight: 900;
}

.heat-button[data-level="4"],
.heat-button[data-level="5"] {
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
}

.tool-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.tool-card {
  min-height: 118px;
}

.timer-face {
  display: grid;
  place-items: center;
  width: min(68vw, 260px);
  aspect-ratio: 1;
  margin: 1rem auto;
  border-radius: 50%;
  border: 10px solid var(--primary-soft);
  background: radial-gradient(circle, var(--surface), var(--surface-2));
  color: var(--primary-strong);
  font-size: 3rem;
  font-weight: 900;
}

.breath-orb {
  width: min(46vw, 180px);
  aspect-ratio: 1;
  margin: 1rem auto;
  border-radius: 50%;
  background: var(--primary);
  transform: scale(0.78);
  transition: transform 1s ease;
}

.breath-orb.expand {
  transform: scale(1.08);
}

.lesson-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
}

.lesson-card details {
  display: grid;
  gap: 0.75rem;
}

.lesson-card summary {
  cursor: pointer;
  font-weight: 900;
  min-height: 34px;
}

.lesson-card .lesson-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.prose {
  max-width: 880px;
}

.reference-box {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.check-list {
  display: grid;
  gap: 0.65rem;
  padding-left: 1.1rem;
}

.file-button {
  display: grid;
  place-items: center;
  text-align: center;
}

.file-button input {
  width: 1px;
  height: 1px;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.status-line {
  min-height: 1.5rem;
  margin-top: 0.75rem;
  color: var(--muted);
  font-weight: 800;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.25rem;
  padding: 0.45rem max(0.5rem, env(safe-area-inset-left)) calc(0.45rem + env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  min-height: 50px;
  padding: 0.35rem 0.2rem;
  font-size: 0.78rem;
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.8rem;
  z-index: 30;
  width: min(92vw, 430px);
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 560px) {
  .choice-grid,
  .metric-grid,
  .insight-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (min-width: 860px) {
  .app-shell {
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto 1fr;
  }

  .topbar {
    grid-column: 1 / -1;
  }

  .menu-toggle {
    display: none;
  }

  .sidebar {
    position: sticky;
    top: 70px;
    grid-row: 2;
    width: auto;
    height: calc(100vh - 70px);
    transform: none;
    box-shadow: none;
  }

  .content {
    grid-column: 2;
    padding: 1.5rem 1.5rem 3rem;
  }

  .bottom-nav {
    display: none;
  }

  .two-column {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

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

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

  .hero-panel {
    border-radius: 0 0 var(--radius) var(--radius);
    margin: 0 0 1.25rem;
  }
}

@media (max-width: 390px) {
  .scale-row {
    gap: 0.25rem;
  }

  .scale-row label {
    font-size: 0.68rem;
    padding: 0.35rem 0.1rem;
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  .topbar,
  .sidebar,
  .bottom-nav,
  .section-head button,
  .toast,
  #planForm {
    display: none !important;
  }

  .app-shell,
  .content,
  .view,
  #view-plan {
    display: block !important;
    width: 100%;
    padding: 0;
  }

  .view:not(#view-plan) {
    display: none !important;
  }

  .card {
    border: 1px solid #bbb;
    box-shadow: none;
  }
}
