:root {
  color-scheme: light;
  --ink: #1c2841;
  --muted: #59677b;
  --paper: #f8f7f4;
  --card: #ffffff;
  --surface: #e5e8ec;
  --blue: #365a7a;
  --blue-light: #eef2f6;
  --lavender: #c7c5e9;
  --lavender-light: #f1f0fa;
  --sage: #a8c2b0;
  --sage-light: #edf3ef;
  --line: #d8dee5;
  --wrong: #a34d55;
  --wrong-light: #f8eded;
  --chart-average: #a6532a;
  font-family: 'Poppins', 'Avenir Next', ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex='0']:focus-visible {
  outline: 3px solid var(--lavender);
  outline-offset: 2px;
}
.shell { width: min(1050px, calc(100% - 32px)); margin: 0 auto; min-height: 100vh; }
.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  font-family: 'Raleway', 'Avenir Next', ui-sans-serif, system-ui, sans-serif;
  font-weight: 650;
  font-size: 20px;
}
.brand-logo { display: block; width: 85px; height: 48px; object-fit: contain; }
.brand-copy { display: block; line-height: 1.15; }
.brand small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
  font-family: 'Poppins', 'Avenir Next', ui-sans-serif, system-ui, sans-serif;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.settings-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  font-size: 18px;
}
.settings-button:hover { border-color: var(--blue); }
.view { display: none; padding: 58px 0; }
.view.active { display: block; }
.hidden { display: none !important; }

.eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}
h1, h2, h3, p { margin-top: 0; }
h1, h2 {
  font-family: 'Raleway', 'Avenir Next', ui-sans-serif, system-ui, sans-serif;
  font-weight: 650;
  letter-spacing: -0.025em;
}
.primary-button,
.secondary-button,
.danger-button {
  min-height: 46px;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 750;
  cursor: pointer;
}
.primary-button {
  border: 0;
  background: var(--blue);
  color: #fff;
}
.primary-button:hover { background: var(--ink); }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
}
.secondary-button:hover { border-color: var(--blue); background: var(--blue-light); }

.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.11em;
}
.study-launch-card {
  position: relative;
  width: min(680px, 100%);
  margin: 0 auto;
  overflow: hidden;
  padding: 34px;
  border: 1px solid #d9d6ef;
  border-radius: 28px;
  background: linear-gradient(135deg, #fff 60%, var(--lavender-light));
  box-shadow: 0 18px 50px rgba(28, 40, 65, 0.08);
  text-align: center;
}
.study-launch-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 7px;
  background: var(--blue);
  content: '';
}
.launch-mark {
  width: 58px;
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: end;
  gap: 5px;
  margin: 0 auto 20px;
  padding: 13px;
  border: 1px solid #d9d6ef;
  border-radius: 18px;
  background: var(--lavender-light);
}
.launch-mark span {
  width: 6px;
  border-radius: 6px;
  background: var(--blue);
}
.launch-mark span:nth-child(1) { height: 45%; }
.launch-mark span:nth-child(2) { height: 78%; }
.launch-mark span:nth-child(3) { height: 58%; }
.study-launch-card .eyebrow { margin-bottom: 7px; }
.study-launch-card h2 { margin: 0 0 10px; font-size: clamp(27px, 4vw, 35px); }
.study-mode-start {
  width: min(360px, 100%);
  min-height: 58px;
  margin-top: 25px;
  border-radius: 16px;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(54, 90, 122, 0.2);
  font-size: 16px;
}
.study-mode-start::before { content: '▶'; margin-right: 10px; font-size: 12px; }
.study-mode-start:hover { background: var(--ink); transform: translateY(-1px); }
.home-note {
  max-width: 680px;
  margin: 25px auto 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

.study-view.active {
  margin: 34px 0;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid #d6d9eb;
  border-radius: 30px;
  background: linear-gradient(145deg, #f1f0fa, #eef2f6 72%, #fff);
}
.study-view-heading { margin: 0 auto 18px; text-align: center; }
.mode-badge-study {
  background: var(--ink);
  color: #fff;
}
.session-identity-card,
.pomodoro-card {
  width: min(680px, 100%);
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  box-shadow: 0 8px 24px rgba(28, 40, 65, 0.045);
}
.session-identity-card {
  display: grid;
  gap: 5px;
  padding: 19px 22px;
  border-left: 4px solid var(--blue);
}
.session-identity-card .eyebrow { margin-bottom: 3px; }
.session-identity-card strong { font-size: 20px; }
.session-id { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.audio-controls { display: flex; justify-content: center; margin: 0 auto 14px; }
.audio-toggle {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 9px 14px;
  background: var(--card);
  cursor: pointer;
  font-weight: 700;
}
.audio-toggle[aria-pressed='true'] { border-color: #b9cec0; background: var(--sage-light); }
.audio-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #748091;
}
.audio-toggle[aria-pressed='true'] .audio-dot {
  background: #3b7a57;
  box-shadow: 0 0 0 4px rgba(168, 194, 176, 0.35);
}
.pomodoro-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 22px;
}
.pomodoro-card.is-break { border-color: #b9cec0; background: var(--sage-light); }
.pomodoro-copy { display: grid; gap: 4px; }
.pomodoro-copy .eyebrow { margin-bottom: 2px; }
.pomodoro-copy strong { font-size: 16px; }
.pomodoro-time { font-size: clamp(27px, 4vw, 34px); font-variant-numeric: tabular-nums; }
.pomodoro-actions { grid-column: 1 / -1; display: flex; gap: 9px; }
.pomodoro-toggle,
.pomodoro-reset {
  min-height: 43px;
  border-radius: 12px;
  padding: 10px 15px;
  font-weight: 750;
  cursor: pointer;
}
.pomodoro-toggle { flex: 1 1 auto; border: 0; background: var(--blue); color: #fff; }
.pomodoro-toggle:hover { background: var(--ink); }
.pomodoro-reset { border: 1px solid var(--line); background: transparent; }
.study-mode-end {
  display: block;
  width: min(680px, 100%);
  min-height: 50px;
  margin: 22px auto 0;
  border-color: #c8b9be;
  background: #fff;
  color: var(--wrong);
}
.study-mode-end:hover { border-color: var(--wrong); background: var(--wrong-light); }

.stats-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}
.stats-heading h1 { margin: 3px 0 0; font-size: clamp(34px, 5vw, 48px); }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stats-section-label { margin: 30px 0 10px; }
.stat-card {
  min-height: 138px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
}
.stat-card.featured { border-color: var(--ink); background: var(--ink); color: #fff; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card.featured span { color: #e5e8ec; }
.stat-card strong { font-size: clamp(28px, 4vw, 36px); font-weight: 700; }
.local-note { margin: 16px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.sleep-history-entry,
.sleep-detail-summary,
.sleep-chart-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
}
.sleep-history-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 15px;
  padding: 20px 22px;
}
.sleep-history-entry h2,
.sleep-detail-summary h3,
.sleep-chart-heading h3 { margin: 0; font-size: 19px; }
.sleep-history-entry p,
.sleep-detail-summary p { margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.sleep-history-entry .primary-button { width: auto; flex: 0 0 auto; }
.sleep-history-note { margin: -12px 0 18px; }
.sleep-history-card-heading,
.sleep-chart-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sleep-history-card-heading h3 { margin: 0; }
.sleep-status {
  flex: 0 0 auto;
  border-radius: 99px;
  padding: 5px 10px;
  background: var(--sage-light);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
}
.sleep-status.interrupted { background: var(--wrong-light); color: var(--wrong); }
.sleep-status.active { background: var(--lavender-light); color: var(--ink); }
.sleep-history-metadata { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.sleep-history-card .history-actions { margin-top: 14px; }
.sleep-detail-content { display: grid; gap: 14px; }
.sleep-detail-summary { padding: 22px; }
.sleep-detail-summary > p { margin-top: 8px; }
.sleep-detail-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.sleep-detail-metric {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--blue-light);
}
.sleep-detail-metric span { color: var(--muted); font-size: 12px; }
.sleep-detail-metric strong { font-size: clamp(20px, 3vw, 28px); }
.sleep-chart-card { min-width: 0; padding: 20px; }
.sleep-chart-heading strong { color: var(--blue); font-size: 18px; }
.sleep-chart-readout { min-height: 20px; margin: 16px 0 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.sleep-chart-plot {
  position: relative;
  height: 190px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(25% - 1px),
    var(--line) 25%,
    transparent calc(25% + 1px)
  );
  cursor: crosshair;
  touch-action: pan-y;
}
.sleep-chart-columns { position: absolute; inset: 10px 0 0; display: grid; align-items: end; gap: 2px; }
.sleep-chart-column { height: 100%; display: flex; align-items: end; }
.sleep-chart-column span {
  display: block;
  width: 100%;
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: var(--blue);
  opacity: 0.72;
}
.sleep-chart-plot.movement .sleep-chart-column span { background: #9690c9; }
.sleep-chart-column.selected span { opacity: 1; box-shadow: 0 0 0 1px var(--ink); }
.sleep-chart-average {
  position: absolute;
  inset: 10px 0 0;
  width: 100%;
  height: calc(100% - 10px);
  overflow: visible;
  pointer-events: none;
}
.sleep-chart-average polyline {
  fill: none;
  stroke: var(--chart-average);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.sleep-chart-axis,
.sleep-chart-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
}
.sleep-chart-axis { margin-top: 7px; font-variant-numeric: tabular-nums; }
.sleep-chart-legend { justify-content: flex-start; flex-wrap: wrap; margin-top: 14px; }
.sleep-chart-legend-samples::before,
.sleep-chart-legend-average::before {
  display: inline-block;
  width: 14px;
  margin-right: 6px;
  vertical-align: middle;
  content: '';
}
.sleep-chart-legend-samples::before { height: 8px; border-radius: 3px; background: var(--blue); }
.sleep-chart-legend-average::before { height: 3px; background: var(--chart-average); }
.sleep-chart-empty { margin: 18px 0 0; color: var(--muted); }

.history-list { display: grid; gap: 12px; }
.history-card,
.history-empty {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
}
.history-card h3,
.history-empty h3 { margin: 0; font-size: 19px; }
.history-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-meta,
.history-result,
.history-empty p { margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.history-actions { display: flex; gap: 9px; margin-top: 15px; }
.history-actions .primary-button { width: auto; margin: 0; }

.user-card {
  padding: 22px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
}
.user-card h2 { margin: 0; font-size: 21px; }
.user-card p { max-width: 650px; margin: 9px 0 0; color: var(--muted); line-height: 1.55; }
.notification-settings-actions { display: flex; gap: 12px; margin-top: 18px; }
.profile-label { display: block; margin: 16px 0 7px; font-size: 13px; font-weight: 700; }
.profile-input {
  width: min(240px, 100%);
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid #b7c1cc;
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
}
.auth-gate-card .profile-input { display: block; width: 100%; margin: 8px 0 16px; }
.auth-gate-card .primary-button { width: 100%; margin-top: 4px; }
.profile-input-invalid { border-color: var(--wrong); background: var(--wrong-light); }
.profile-options-invalid { padding: 5px; border: 1px solid var(--wrong); border-radius: 14px; }
.profile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; max-width: 760px; }
.profile-grid .profile-input { width: 100%; }
[data-user-gender] { min-width: 92px; }
[data-user-gender][aria-pressed='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}
[data-user-gender][aria-pressed='true']::before { content: '✓'; margin-right: 7px; }
.profile-required { color: var(--wrong); font-size: 13px; }
.danger-card { border-color: #dfb8bb; background: var(--wrong-light); }
.danger-button { margin-top: 19px; border: 1px solid #c78b90; background: transparent; color: var(--wrong); }

.auth-gate-view { max-width: 520px; margin: 0 auto; text-align: center; }
.auth-gate-view h1 { margin: 8px 0; font-size: 42px; }
.auth-gate-copy { margin: 12px auto 24px; color: var(--muted); line-height: 1.5; }
.auth-gate-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  text-align: left;
}
.centered.active { display: flex; min-height: calc(100vh - 82px); flex-direction: column; justify-content: center; align-items: center; }
.session-restore,
.pomodoro-alert {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(28, 40, 65, 0.46);
  backdrop-filter: blur(7px);
}
.session-restore-card,
.pomodoro-alert-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 24px 80px rgba(28, 40, 65, 0.2);
}
.session-restore-card h2,
.pomodoro-alert-card h2 { margin: 6px 0 10px; font-size: 30px; }
.session-restore-card p:not(.eyebrow),
.pomodoro-alert-card p:not(.eyebrow) { color: var(--muted); line-height: 1.5; }
.session-restore-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.session-restore-actions .primary-button { width: auto; }
.pomodoro-alert-card { text-align: center; }
.pomodoro-alert-card p:not(.eyebrow) { margin: 0 0 22px; }
.pomodoro-alert-card .primary-button { width: 100%; }

@media (max-width: 760px) {
  .shell { width: min(100% - 24px, 620px); }
  .topbar { min-height: 68px; }
  .brand { gap: 8px; font-size: 18px; }
  .brand-logo { width: 67px; height: 38px; }
  .brand small { font-size: 8px; letter-spacing: 0.04em; }
  .topbar-actions { gap: 6px; }
  .settings-button { width: 35px; height: 35px; }
  .view { padding: 36px 0; }
  .study-launch-card { padding: 28px 22px; }
  .study-view.active { margin: 20px 0; padding: 24px 16px; border-radius: 24px; }
  .pomodoro-card { grid-template-columns: minmax(0, 1fr) auto; padding: 18px; }
  .pomodoro-actions { grid-column: 1 / -1; }
  .pomodoro-actions button { min-height: 46px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-card { min-height: 120px; padding: 16px; }
  .sleep-history-entry { align-items: flex-start; flex-direction: column; }
  .sleep-history-entry .primary-button { width: 100%; }
  .sleep-detail-metrics { grid-template-columns: 1fr; }
  #sleep-detail-date { font-size: clamp(24px, 7vw, 30px); line-height: 1.15; }
  .sleep-chart-card { padding: 16px; }
  .sleep-chart-plot { height: 160px; }
  .profile-grid { grid-template-columns: 1fr; }
  .history-actions { flex-wrap: wrap; }
}
@media (max-width: 430px) {
  .brand-copy { display: none; }
  .stats-heading { align-items: flex-start; }
  .stats-heading .secondary-button { min-height: 40px; padding: 8px 13px; }
  .sleep-stats-grid { grid-template-columns: 1fr 1fr; }
  .sleep-stats-grid .stat-card:last-child { grid-column: 1 / -1; }
  .session-restore-actions { flex-direction: column-reverse; }
  .session-restore-actions button { width: 100%; }
}
