:root {
  color-scheme: light;
  --navy: #1F2A44;
  --cream: #F4EFE6;
  --teal: #2E7D7A;
  --amber: #D9952B;
  --slate: #E4E7EA;
  --ink: #253047;
  --muted: #647080;
  --white: #FFFEFB;
  --red: #A73532;
  --shadow: 0 12px 30px rgba(31, 42, 68, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 100% 0, rgba(46, 125, 122, .09), transparent 28rem), var(--cream);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.app-shell { width: 100%; max-width: 760px; min-height: 100vh; margin: 0 auto; background: rgba(244, 239, 230, .78); }
.screen { min-height: 100vh; padding: 30px 18px calc(112px + env(safe-area-inset-bottom)); outline: none; }
.page-header { margin: 0 0 24px; }
.eyebrow { margin: 0 0 7px; color: var(--teal); font-size: .75rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 620px; margin-bottom: 8px; color: var(--navy); font-size: clamp(2rem, 8vw, 3.25rem); line-height: .98; letter-spacing: -.045em; }
h2 { color: var(--navy); font-size: 1.18rem; line-height: 1.25; letter-spacing: -.012em; }
h3 { color: var(--navy); font-size: 1rem; }
.subtitle, .intro { max-width: 620px; margin-bottom: 0; color: var(--muted); font-size: .98rem; line-height: 1.55; }
.intro { margin-bottom: 20px; color: var(--ink); }
.card { margin: 0 0 16px; padding: 20px; border: 1px solid rgba(31, 42, 68, .08); border-radius: 18px; background: var(--white); box-shadow: var(--shadow); }
.card h2:last-child, .card p:last-child { margin-bottom: 0; }
.card p { line-height: 1.55; }
.primary-button, .secondary-button, .unit-button, .delete-button { border: 0; border-radius: 11px; cursor: pointer; font-weight: 750; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 12px 18px; color: white; background: var(--teal); box-shadow: 0 7px 16px rgba(46, 125, 122, .2); }
.primary-button:hover { background: #256c69; }
.primary-button:focus-visible, .secondary-button:focus-visible, .unit-button:focus-visible, .delete-button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid rgba(217, 149, 43, .42); outline-offset: 2px; }
.secondary-button { min-height: 44px; padding: 10px 15px; color: var(--teal); border: 1px solid rgba(46, 125, 122, .28); background: transparent; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.status-banner { display: block; margin: 18px 0; padding: 17px 18px; border: 1px solid rgba(128, 80, 4, .18); border-left: 5px solid var(--amber); border-radius: 14px; color: #573900; background: #F7E4BE; text-decoration: none; box-shadow: var(--shadow); }
.status-banner strong { display: block; margin-bottom: 4px; color: #473100; }
.status-banner span { line-height: 1.45; }
.footer-note { margin: 24px 4px 0; color: var(--muted); font-size: .79rem; line-height: 1.5; }
.chart-card { padding: 18px 12px 10px; overflow: hidden; }
.chart-title { margin: 0 8px 10px; font-size: .78rem; color: var(--muted); font-weight: 750; }
.chart-wrap { position: relative; width: 100%; height: 210px; }
#height-chart { width: 100%; height: 100%; display: block; }
.last-log { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.last-log h2 { margin: 0; }
.section-title { margin: 28px 0 12px; }
details.help-panel { margin-bottom: 12px; border: 1px solid rgba(31, 42, 68, .1); border-radius: 14px; background: rgba(255, 254, 251, .7); }
details.help-panel summary { position: relative; padding: 16px 42px 16px 17px; color: var(--navy); cursor: pointer; font-weight: 800; list-style: none; }
details.help-panel summary::-webkit-details-marker { display: none; }
details.help-panel summary::after { position: absolute; top: 14px; right: 17px; content: "+"; color: var(--teal); font-size: 1.3rem; }
details.help-panel[open] summary::after { content: "−"; }
.help-content { padding: 0 17px 16px; color: var(--muted); line-height: 1.55; }
.help-content p, .help-content ol { margin-bottom: 0; }
.help-content ol { padding-left: 22px; }
.help-content li + li { margin-top: 6px; }
.form-section { margin: 22px 0; padding: 0; border: 0; }
.form-section legend { width: 100%; margin-bottom: 12px; padding: 0; color: var(--navy); font-size: 1.07rem; font-weight: 850; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 7px; color: var(--navy); font-size: .9rem; font-weight: 750; }
.text-input, .text-area, .time-input, .number-input { width: 100%; min-height: 46px; padding: 11px 12px; border: 1px solid #C9CED4; border-radius: 10px; color: var(--ink); background: var(--white); }
.text-area { min-height: 105px; resize: vertical; }
.input-with-unit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.unit-toggle { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--slate); }
.unit-button { min-width: 50px; min-height: 38px; padding: 7px 10px; color: var(--muted); background: transparent; }
.unit-button.active { color: white; background: var(--navy); }
.check-list { display: grid; gap: 9px; }
.check-row { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 11px; align-items: start; padding: 12px; border-radius: 10px; background: rgba(228, 231, 234, .52); line-height: 1.4; cursor: pointer; }
.check-row input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--teal); }
.danger-banner { margin: 14px 0 0; padding: 15px 16px; border-left: 5px solid var(--red); border-radius: 10px; color: #6D1D1B; background: #F8DEDC; font-weight: 750; line-height: 1.45; }
.helper { margin: -5px 0 12px; color: var(--muted); font-size: .82rem; }
.sleep-table-wrap { overflow-x: auto; border: 1px solid #D4D8DC; border-radius: 12px; background: var(--white); }
.sleep-table { width: 100%; min-width: 570px; border-collapse: collapse; }
.sleep-table th, .sleep-table td { padding: 9px; border-bottom: 1px solid var(--slate); text-align: left; }
.sleep-table tr:last-child td { border-bottom: 0; }
.sleep-table th { color: var(--navy); background: #EEF0F1; font-size: .78rem; }
.sleep-table td:first-child { color: var(--navy); font-size: .86rem; font-weight: 750; }
.sleep-table input { min-width: 95px; min-height: 40px; }
.saved-message { margin-top: 12px; color: var(--teal); font-weight: 750; }
.height-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.height-pair .field { margin-bottom: 0; }
.estimate-result { border-top: 5px solid var(--teal); background: linear-gradient(145deg, #FFFEFB, #F0F6F5); }
.estimate-result h2 { margin-bottom: 10px; font-size: 1.28rem; }
.alternate-link { display: inline-block; color: var(--teal); font-weight: 750; line-height: 1.45; }
.flag-summary { border-left: 5px solid var(--amber); background: #FCF3E0; }
.flag-summary ul { padding-left: 20px; }
.flag-summary li + li { margin-top: 7px; }
.question-list { display: grid; gap: 10px; margin-bottom: 14px; }
.question-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) 42px; gap: 8px; align-items: center; }
.question-number { color: var(--navy); font-weight: 800; text-align: center; }
.question-row input { margin: 0; }
.delete-button { width: 42px; height: 42px; color: var(--muted); background: var(--slate); font-size: 1.2rem; }
.delete-button:hover { color: white; background: var(--red); }
.tab-bar { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 760px; min-height: 74px; margin: 0 auto; padding: 7px 6px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(31, 42, 68, .12); background: rgba(255, 254, 251, .96); backdrop-filter: blur(14px); box-shadow: 0 -8px 24px rgba(31, 42, 68, .07); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 0; padding: 4px 2px; border-radius: 9px; color: #737C89; font-size: clamp(.58rem, 2.5vw, .71rem); font-weight: 750; line-height: 1.05; text-align: center; text-decoration: none; }
.tab.active { color: var(--teal); background: rgba(46, 125, 122, .08); }
.tab-icon { width: 22px; height: 22px; }
.tab-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 640px) {
  body { padding: 26px 0 0; }
  .app-shell { min-height: calc(100vh - 26px); border-radius: 26px 26px 0 0; box-shadow: 0 0 60px rgba(31, 42, 68, .1); overflow: hidden; }
  .screen { padding: 48px 52px 124px; }
  .tab-bar { bottom: 18px; width: calc(100% - 36px); border: 1px solid rgba(31, 42, 68, .12); border-radius: 18px; }
  .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
}
@media (prefers-reduced-motion: no-preference) {
  .screen > * { animation: rise .3s ease both; }
  @keyframes rise { from { opacity: 0; transform: translateY(5px); } }
}

/* Interactive companion modules */
.companion-links{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin:22px 0}
.companion-links a{display:block;padding:20px;background:var(--band,#EDF1F6);color:inherit;border-radius:14px;text-decoration:none;font-weight:700;overflow-wrap:anywhere}
.companion-module{min-width:0;background:#fffdf9;border:1px solid var(--line,#d9dce3);border-radius:16px;padding:24px;margin:22px 0}
.companion-module h2,.companion-module h3{line-height:1.35;overflow-wrap:anywhere}
.companion-module p,.companion-module li{line-height:1.65}
.companion-module blockquote{margin:18px 0;padding:16px 20px;border-left:3px solid var(--gold,#b58645);background:var(--band,#EDF1F6)}
.companion-module textarea{display:block;width:100%;box-sizing:border-box;min-height:100px;margin:10px 0 22px;padding:12px;border:1px solid #baa6b7;border-radius:10px;background:#FFF8F0;color:inherit;font:inherit;resize:vertical}
.companion-module .companion-check{display:inline-flex;align-items:flex-start;gap:9px;margin:10px 15px 10px 0;color:inherit;font-weight:inherit;line-height:1.5}
.companion-module input[type=checkbox]{width:22px;height:22px;min-height:22px;flex:0 0 22px;margin:1px 0;accent-color:var(--plum,#1F2A44)}
.companion-table{display:grid;gap:14px}.companion-table-row{display:grid;gap:10px;padding:14px;border:1px solid var(--line,#d9dce3);border-radius:12px}
.companion-table-row label{font-size:14px;color:inherit}.companion-table-row textarea{margin:5px 0 0;min-height:72px}
.companion-save{min-height:24px;font-size:14px;color:inherit}
@media(max-width:600px){.companion-links{grid-template-columns:1fr}.companion-module{padding:20px}.companion-module h2{font-size:23px}}
