:root {
  color-scheme: dark;
  --ink: #eaf7f5;
  --muted: #91aaa8;
  --deep: #071b22;
  --deep-2: #0a2730;
  --panel: #10323a;
  --panel-soft: #153d44;
  --teal: #23d6b1;
  --teal-dark: #08705f;
  --lime: #b8ef64;
  --orange: #ff9f43;
  --red: #ff6577;
  --paper: #f4f8f7;
  --paper-2: #e8f0ee;
  --dark-text: #102b31;
  --dark-muted: #51686b;
  --border: rgba(210, 240, 236, 0.15);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--deep); }
body {
  margin: 0;
  min-width: 320px;
  background: var(--deep);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(35, 214, 177, 0.45);
  outline-offset: 3px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
  background: rgba(7, 27, 34, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}
.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.02em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--deep);
  background: linear-gradient(135deg, var(--teal), var(--lime));
  box-shadow: 0 8px 24px rgba(35, 214, 177, 0.22);
}
.brand-mark::before { content: "H"; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-button, .text-button, .danger-text-button {
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
}
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 21px;
}
.icon-button:hover { background: rgba(255, 255, 255, 0.08); }
.text-button { color: var(--teal); font-weight: 750; padding: 10px; }
.stats-section .text-button, .history-section .text-button { color: var(--teal-dark); }
.stats-section .text-button:disabled, .history-section .text-button:disabled { color: #607477; }
.danger-text-button { color: var(--red); font-weight: 750; padding: 12px 16px; }

.section-shell {
  width: min(1160px, calc(100% - 40px));
  margin-inline: auto;
}
.hero {
  min-height: calc(100svh - 68px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 72px 0 64px;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 4% -8% auto auto;
  width: min(44vw, 520px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(35, 214, 177, 0.18), transparent 67%);
  pointer-events: none;
}
.privacy-chip, .count-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 750;
}
.privacy-chip { color: var(--teal); background: rgba(35, 214, 177, 0.1); border: 1px solid rgba(35, 214, 177, 0.25); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 5px rgba(35, 214, 177, 0.12); }
.eyebrow { margin: 22px 0 8px; color: var(--teal-dark); font-size: 12px; font-weight: 900; letter-spacing: 0.13em; }
.hero .eyebrow { color: var(--muted); }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 {
  max-width: 880px;
  margin: 0;
  font-size: clamp(48px, 8vw, 92px);
  line-height: 0.95;
  letter-spacing: -0.065em;
}
h1 span { color: var(--teal); }
.hero-copy {
  max-width: 680px;
  margin: 26px 0 0;
  color: #b7ccca;
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.55;
}
.hero-actions { display: flex; align-items: center; gap: 12px; margin-top: 32px; }
.primary-button, .secondary-button {
  min-height: 54px;
  border-radius: 16px;
  padding: 0 22px;
  font-weight: 850;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
.primary-button {
  color: #05251f;
  background: linear-gradient(135deg, var(--teal), #63e5c9);
  box-shadow: 0 12px 34px rgba(35, 214, 177, 0.22);
}
.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.secondary-button { color: var(--ink); background: rgba(255,255,255,0.055); border-color: var(--border); }
.button-icon { margin-right: 8px; }
.full-width { width: 100%; }
.support-line { min-height: 22px; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.support-line.warning { color: var(--orange); }
.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  list-style: none;
  padding: 0;
  margin: 54px 0 0;
}
.steps li {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 2px 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,0.025);
}
.steps li > span { grid-row: span 2; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: var(--teal); background: rgba(35,214,177,0.11); font-weight: 900; }
.steps strong { align-self: end; }
.steps small { color: var(--muted); line-height: 1.35; }

.stats-section, .history-section, .insight-section {
  width: 100%;
  max-width: none;
  padding: 78px max(20px, calc((100vw - 1160px) / 2));
  background: var(--paper);
  color: var(--dark-text);
}
.history-section { background: var(--paper-2); }
.insight-section { background: #dce8e5; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.section-heading.compact { align-items: center; }
.section-heading .eyebrow, .insight-section .eyebrow { margin-top: 0; }
h2 { margin: 0; font-size: clamp(31px, 5vw, 50px); line-height: 1.05; letter-spacing: -0.045em; }
h3 { margin: 0; font-size: 18px; }
.count-chip { color: #216c60; background: #d6eee9; white-space: nowrap; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card {
  min-height: 148px;
  display: flex;
  flex-direction: column;
  padding: 20px;
  border: 1px solid #d4dfdd;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 35px rgba(28, 65, 65, 0.06);
}
.stat-card.featured { color: #eafffb; border-color: #143d43; background: linear-gradient(145deg, #0b2a32, #17454b); }
.stat-card > span { color: var(--dark-muted); font-size: 13px; font-weight: 750; }
.stat-card.featured > span, .stat-card.featured small { color: #9bc2bd; }
.stat-card strong { margin-top: auto; font-size: clamp(28px, 4vw, 45px); letter-spacing: -0.05em; }
.stat-card.featured strong { color: var(--teal); }
.stat-card small { color: var(--dark-muted); }
.chart-card {
  position: relative;
  margin-top: 18px;
  padding: 20px;
  border: 1px solid #d4dfdd;
  border-radius: 22px;
  background: #fff;
  overflow: hidden;
}
.chart-title-row p { margin: 4px 0 0; color: var(--dark-muted); font-size: 13px; }
canvas { display: block; width: 100%; max-width: 100%; height: auto; }
#progress-chart { margin-top: 16px; aspect-ratio: 1200 / 420; }
.empty-overlay { position: absolute; inset: 88px 20px 20px; display: grid; place-items: center; color: var(--dark-muted); background: rgba(255,255,255,0.82); font-weight: 750; }
.history-list { display: grid; gap: 10px; }
.history-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) 1fr 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 18px 20px;
  border: 1px solid #ccd9d6;
  border-radius: 18px;
  color: var(--dark-text);
  background: rgba(255,255,255,0.75);
  text-align: left;
  cursor: pointer;
}
.history-row:hover { background: #fff; border-color: #9fc4bd; }
.history-row strong.duration { font-size: 28px; color: #087c69; letter-spacing: -0.04em; }
.history-row small, .history-row span { color: var(--dark-muted); }
.history-row .row-date { display: flex; flex-direction: column; }
.history-row .row-note { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chevron { font-size: 25px; color: #4f706c; }
.empty-state { padding: 56px 20px; text-align: center; color: var(--dark-muted); }
.empty-state > span { display: block; font-size: 48px; color: #80a8a1; }
.empty-state h3 { margin-top: 8px; color: var(--dark-text); }
.empty-state p { max-width: 520px; margin: 8px auto 0; }
.insight-section { display: grid; grid-template-columns: 0.8fr 1.4fr; gap: 42px; }
.insight-section > div:first-child p:last-child { max-width: 500px; color: var(--dark-muted); line-height: 1.6; }
.insight-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.insight-grid article { padding: 20px; border: 1px solid #c3d3cf; border-radius: 20px; background: rgba(255,255,255,0.45); }
.insight-icon { display: inline-grid; place-items: center; min-width: 52px; height: 44px; padding: 0 9px; border-radius: 13px; color: #0b6d5e; background: #c9e9e2; font-weight: 900; }
.insight-grid h3 { margin-top: 36px; }
.insight-grid p { color: var(--dark-muted); line-height: 1.5; font-size: 14px; }
footer { display: flex; justify-content: space-between; gap: 20px; padding: 26px max(20px, calc((100vw - 1160px) / 2)) max(26px, env(safe-area-inset-bottom)); color: var(--muted); font-size: 13px; }
footer strong { color: var(--ink); }

.recording-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: radial-gradient(circle at top, #17464e, var(--deep) 55%);
  overflow: auto;
}
.recording-overlay[hidden] { display: none; }
.recording-card { min-height: calc(100svh - 36px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.recording-badge { color: var(--teal); font-weight: 900; letter-spacing: 0.16em; font-size: 12px; }
.recording-card h2 { max-width: 680px; margin-top: 16px; }
.countdown-value { margin: 30px 0; color: var(--teal); font-size: clamp(110px, 30vw, 210px); line-height: 0.85; font-weight: 950; letter-spacing: -0.08em; }
.live-duration { display: flex; flex-direction: column; margin: 28px 0; }
.live-duration strong { color: var(--teal); font-size: clamp(76px, 22vw, 150px); line-height: 0.9; letter-spacing: -0.08em; }
.live-duration span { color: var(--muted); font-weight: 700; }
.recording-instruction { max-width: 540px; color: #b1c8c5; line-height: 1.5; }
.activity-meter { width: min(540px, 100%); height: 10px; margin-top: 28px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,0.08); }
.activity-meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--orange), var(--red)); transition: width 80ms linear; }
.live-meta { width: min(540px, 100%); display: flex; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 13px; }
.live-meta strong { color: var(--ink); }
.recording-actions { display: flex; align-items: center; gap: 12px; margin-top: 36px; }

.modal {
  width: min(720px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--ink);
  background: transparent;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal::backdrop { background: rgba(1, 12, 16, 0.78); backdrop-filter: blur(8px); }
.modal-card { position: relative; max-height: calc(100dvh - 28px); padding: 28px; overflow-y: auto; color: var(--ink); background: var(--deep-2); }
.dialog-close { position: absolute; right: 14px; top: 14px; }
.modal-card h2 { padding-right: 44px; }
.result-duration { display: flex; flex-direction: column; align-items: center; margin: 26px 0; }
.result-duration strong { color: var(--teal); font-size: clamp(72px, 19vw, 120px); line-height: 0.9; letter-spacing: -0.075em; }
.result-duration span { color: var(--muted); }
.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.result-grid > div { min-width: 0; padding: 13px; border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,0.035); }
.result-grid span { display: block; color: var(--muted); font-size: 11px; }
.result-grid strong { display: block; margin-top: 3px; font-size: 17px; white-space: nowrap; }
#result-chart, #session-chart { margin: 20px 0; border-radius: 14px; background: #f7fbfa; aspect-ratio: 1000 / 360; }
.field-label { display: block; margin: 14px 0 7px; color: var(--muted); font-size: 12px; font-weight: 750; }
.text-input, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 0 13px;
  color: var(--ink);
  background: #0d3139;
}
.result-message, .session-note { min-height: 22px; color: var(--muted); font-size: 13px; }
.result-actions { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); gap: 10px; }
.result-actions > * { width: 100%; }
.modal-actions, .data-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.boundary-editor { margin-top: 4px; padding-top: 18px; border-top: 1px solid var(--border); }
.boundary-editor h3 { margin: 0 0 6px; font-size: 18px; }
.boundary-editor > p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.boundary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.boundary-grid label { color: var(--muted); font-size: 12px; font-weight: 750; }
.boundary-grid input { margin-top: 6px; }
.boundary-editor .secondary-button { width: 100%; }
.boundary-editor .boundary-status { min-height: 18px; margin: 8px 0 0; color: var(--teal); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 17px 0; border-bottom: 1px solid var(--border); }
.setting-row span { display: flex; flex-direction: column; gap: 4px; }
.setting-row small { color: var(--muted); }
.setting-row select { width: auto; min-width: 130px; }
.setting-row input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--teal); }
.privacy-note { margin: 22px 0; padding: 16px; border: 1px solid rgba(35,214,177,0.2); border-radius: 15px; background: rgba(35,214,177,0.06); }
.privacy-note p { margin: 6px 0 0; color: var(--muted); line-height: 1.45; font-size: 13px; }
.toast { position: fixed; z-index: 200; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); max-width: calc(100% - 32px); transform: translateX(-50%); padding: 12px 18px; border-radius: 99px; color: var(--deep); background: var(--teal); box-shadow: var(--shadow); font-weight: 800; text-align: center; }
.toast.error { color: white; background: var(--red); }

@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .insight-section { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; margin-top: 38px; }
  .history-row { grid-template-columns: 1.2fr 0.8fr auto; }
  .history-row .row-note { display: none; }
  .insight-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 600px) {
  .section-shell { width: min(100% - 28px, 1160px); }
  .hero { min-height: auto; padding: 58px 0 42px; }
  .hero::before { width: 90vw; }
  h1 { font-size: clamp(48px, 16vw, 70px); }
  .hero-copy { font-size: 17px; }
  .hero-actions { align-items: stretch; flex-direction: column; }
  .hero-actions button { width: 100%; }
  .stats-section, .history-section, .insight-section { padding: 58px 14px; }
  .section-heading { align-items: flex-start; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { min-height: 126px; padding: 15px; border-radius: 16px; }
  .stat-card strong { font-size: 30px; }
  .chart-card { padding: 14px; }
  #progress-chart { min-height: 190px; }
  .history-row { gap: 10px; padding: 15px; }
  .history-row strong.duration { font-size: 24px; }
  .insight-grid { grid-template-columns: 1fr; }
  .insight-grid h3 { margin-top: 20px; }
  footer { flex-direction: column; }
  .recording-actions { width: 100%; flex-direction: column; }
  .recording-actions button { width: 100%; }
  .result-grid { grid-template-columns: 1fr 1fr; }
  .modal-card { padding: 24px 18px; }
  .setting-row { align-items: flex-start; }
  .setting-row select { min-width: 115px; }
  .data-actions { flex-direction: column; }
  .data-actions button { width: 100%; }
}

@media (display-mode: standalone) {
  .app-header { padding-top: max(14px, env(safe-area-inset-top)); }
}

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