/* ---------------------------------------------------------------------------
   Night Observatory — a deep-space visual system for personal sleep data.

   The sky is decorative and deliberately static; open data regions use dark
   text shadows and localized fades for reliable contrast. The asleep stages
   remain an ordinal moonlight ramp while Awake uses a separate warm hue.
--------------------------------------------------------------------------- */

:root {
  color-scheme: dark;

  --page: #040714;
  --surface: #0b1329;
  --surface-soft: #080e20;
  --surface-raised: #111c37;
  --surface-control: #17213e;

  --text-primary: #f7f9ff;
  --text-secondary: #c1cbe0;
  --text-muted: #aab8d0;

  --gridline: #2a3b60;
  --baseline: #314262;
  --border: rgba(167, 190, 242, 0.15);
  --border-strong: rgba(180, 201, 248, 0.27);
  --section-divider: rgba(162, 192, 237, 0.22);

  --accent: #91a7ff;
  --accent-bright: #b4c3ff;
  --accent-cyan: #68d7e8;
  --moon: #f4e7bd;
  --good: #63d5a3;

  /* Sleep stages */
  --stage-rem: #afd8ff;
  --stage-light: #708ff2;
  --stage-deep: #38529d;
  --stage-awake: #ef9278;

  --radius: 16px;
  --radius-sm: 10px;
  --gap: 16px;

  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

/* Author `display` rules (flex/grid on .setup and .dash) outrank the UA
   stylesheet's [hidden] rule, so `hidden` silently stops working on them.
   This puts it back. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: #02040c;
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.night-sky,
.night-sky::before,
.night-sky::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.night-sky {
  z-index: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(2, 5, 16, 0.08), rgba(1, 3, 11, 0.28)),
    url('assets/deep-space-background.jpg') 56% center / cover no-repeat;
  filter: saturate(0.92) contrast(1.06);
  transform: scale(1.015);
}

.night-sky::before {
  content: '';
  opacity: 0.36;
  background-image:
    radial-gradient(circle at 17px 29px, #ffffff 0 0.75px, transparent 1.2px),
    radial-gradient(circle at 91px 113px, #aecbff 0 0.65px, transparent 1.1px),
    radial-gradient(circle at 147px 61px, #f5e8bd 0 0.7px, transparent 1.2px),
    radial-gradient(circle at 213px 157px, #dfe8ff 0 0.65px, transparent 1.1px);
  background-size: 239px 211px, 313px 277px, 419px 367px, 547px 443px;
  mask-image: radial-gradient(ellipse at center, #000 0 58%, transparent 100%);
}

.night-sky::after {
  content: '';
  background:
    radial-gradient(ellipse at 50% 38%, transparent 0 22%, rgba(1, 4, 13, 0.12) 58%, rgba(1, 3, 10, 0.6) 100%),
    linear-gradient(180deg, rgba(3, 7, 20, 0.08) 0%, rgba(2, 5, 15, 0.18) 52%, rgba(1, 3, 9, 0.68) 100%);
}

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 38px 28px 96px;
}

/* --- Top bar ------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 32px;
  padding: 0 3px;
}

.topbar__identity {
  min-width: 0;
}

.topbar__title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 25px;
  font-weight: 680;
  letter-spacing: -0.03em;
}

.brand-moon {
  width: 18px;
  height: 24px;
  flex: none;
  overflow: visible;
  filter: drop-shadow(0 0 7px rgba(244, 231, 189, 0.24));
}

.brand-moon path {
  fill: var(--moon);
}

.topbar__device {
  margin: 7px 0 0 33px;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 7px;
}

.topbar__device::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(99, 213, 163, 0.1);
  flex: none;
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.segmented {
  display: inline-flex;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 0;
  gap: 18px;
}

.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 2px 9px;
  min-height: 42px;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.settings-btn,
.refresh-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.settings-btn svg,
.refresh-btn svg,
.icon-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-btn svg,
.refresh-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: 0;
  place-self: center;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.refresh-btn.is-refreshing svg {
  animation: refresh-spin 0.8s linear infinite;
}

@keyframes refresh-spin {
  to {
    transform: rotate(360deg);
  }
}

.segmented button:hover {
  color: var(--text-primary);
  background: transparent;
}

.segmented button[aria-pressed='true'] {
  background: transparent;
  color: var(--text-primary);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.segmented button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.primary-btn,
.ghost-btn {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.primary-btn {
  background: var(--accent);
  border: 1px solid transparent;
  color: #070b1c;
}

.primary-btn:hover {
  background: var(--accent-bright);
}

.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.primary-btn:disabled:hover {
  background: var(--accent);
}

.ghost-btn {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.ghost-btn:hover {
  color: var(--text-primary);
  background: var(--surface-control);
  border-color: var(--border-strong);
}

.ghost-btn.settings-btn,
.ghost-btn.refresh-btn {
  display: inline-grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  transition: color 0.14s ease, transform 0.14s ease;
}

.ghost-btn.settings-btn:hover,
.ghost-btn.refresh-btn:hover {
  background: transparent;
  color: var(--accent-bright);
  transform: translateY(-1px);
}

:where(button, a, input, select, summary):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* --- Cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow:
    inset 0 1px 0 rgba(220, 231, 255, 0.025),
    0 18px 44px rgba(0, 0, 0, 0.18);
}

.card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.card__title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.card__meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.section-kicker {
  margin: 0 0 4px;
  color: var(--moon);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: 0;
}

.section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.dash {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

.dash > *,
.night-module,
.card,
.hero__body,
.hero__figure,
.hero__facts {
  min-width: 0;
  max-width: 100%;
}

.dash > [data-dashboard-module] {
  animation: dashboard-enter 0.3s ease-out both;
}

@keyframes dashboard-enter {
  from {
    opacity: 0;
    transform: translateY(7px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Hero ---------------------------------------------------------------- */

.night-module {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 28px 30px 30px;
  background:
    radial-gradient(circle at 88% 8%, rgba(244, 231, 189, 0.085), transparent 18rem),
    linear-gradient(120deg, rgba(105, 126, 220, 0.17), rgba(62, 125, 169, 0.045) 54%, transparent 78%),
    var(--surface);
  border-color: rgba(171, 192, 244, 0.23);
  box-shadow: inset 0 1px 0 rgba(229, 235, 255, 0.04);
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(180, 195, 255, 0.64), rgba(104, 215, 232, 0.22), transparent);
  pointer-events: none;
}

.hero__head {
  margin-bottom: 26px;
}

.hero__body {
  display: grid;
  grid-template-columns: minmax(240px, 0.95fr) 126px minmax(320px, 1.2fr);
  align-items: center;
  gap: 34px;
}

.hero__value {
  margin: 0;
  font-size: clamp(58px, 6.2vw, 76px);
  line-height: 0.96;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.hero__label {
  margin: 9px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.hero__goal {
  width: fit-content;
  margin: 14px 0 0;
  padding: 2px 0 2px 9px;
  border: 0;
  border-left: 2px solid var(--accent);
  border-radius: 0;
  background: transparent;
  color: var(--accent-bright);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.hero__score {
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

.hero__score svg {
  width: 112px;
  height: 112px;
  display: block;
  filter: drop-shadow(0 4px 7px rgba(88, 111, 207, 0.2));
}

.hero__score-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.25;
}

.hero__score-copy strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.hero__facts {
  margin: 0;
  padding-left: 32px;
  border-left: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 28px;
}

.hero__facts div {
  min-width: 0;
}

.hero__facts dt {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.hero__facts dd {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Hypnogram ----------------------------------------------------------- */

.hypno {
  margin: 0;
  background: #080f22;
}

.hypno__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 18px;
}

.chart {
  display: block;
  width: 100%;
  overflow: visible;
  transition: width 0.18s ease;
}

.chart[data-density='single'] {
  max-width: 360px;
}

.chart[data-density='sparse'] {
  max-width: 720px;
}

.chart[data-fill-host='true'] {
  max-width: none;
}

.data-mark {
  transition: opacity 0.16s ease, stroke 0.16s ease, filter 0.16s ease;
}

.data-mark.is-selected,
.data-mark.is-selected path {
  stroke: var(--text-primary);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 4px 7px rgba(125, 149, 255, 0.28));
}

.hit:focus-visible {
  outline: none;
  stroke: var(--text-primary);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.chart-detail {
  min-height: 46px;
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding: 13px 2px 0;
  display: grid;
  grid-template-columns: minmax(105px, 1.35fr) repeat(3, minmax(80px, 1fr));
  gap: 10px 18px;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.chart-detail[hidden] {
  display: none;
}

.chart-detail strong {
  color: var(--text-primary);
  font-size: 13px;
}

.chart-detail span {
  min-width: 0;
}

.chart-detail b {
  color: var(--text-primary);
  font-weight: 500;
}

/* --- Legend -------------------------------------------------------------- */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.legend .swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: none;
  box-shadow: 0 0 0 2px rgba(218, 229, 255, 0.045);
}

.legend--totals {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 20px;
}

.legend--totals li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 2px 8px;
}

.legend--totals .legend__value {
  color: var(--text-primary);
  font-weight: 500;
}

.legend--totals .legend__pct {
  grid-column: 2 / -1;
  color: var(--text-muted);
  font-size: 12px;
}

/* --- Secondary chart --------------------------------------------------- */

.chart-disclosure {
  padding: 0;
  background: #080f22;
}

.chart-disclosure__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 20px 26px;
}

.chart-disclosure__summary > span {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chart-disclosure__body {
  padding: 18px 26px 24px;
  border-top: 1px solid var(--border);
}

.stage-chart-key {
  justify-content: flex-end;
  margin-left: auto;
}

.stage-chart-key li {
  color: var(--text-muted);
  font-size: 12.5px;
}

.stage-chart-key .swatch {
  width: 8px;
  height: 8px;
}

.stage-chart-key .swatch--no-stages {
  border: 1px dashed #c7d2e5;
  border-radius: 2px;
  box-sizing: border-box;
}

/* --- Table view ---------------------------------------------------------- */

.table-card {
  padding: 0;
  background: #080f22;
}

.table-card__summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 20px 22px;
  cursor: pointer;
  list-style: none;
}

.table-card__summary::-webkit-details-marker {
  display: none;
}

.table-card__summary::after {
  content: '';
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(45deg);
  margin-left: auto;
  transition: transform 0.16s ease;
}

.table-card[open] .table-card__summary::after {
  transform: rotate(225deg);
}

.table-scroll {
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table th,
.table td {
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--gridline);
}

.table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
}

.table th:first-child,
.table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: #080f22;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover td {
  background: var(--surface-raised);
}

#duration-section,
#schedule-section {
  padding: 26px 28px;
}

/* --- Setup --------------------------------------------------------------- */

.setup {
  display: flex;
  justify-content: center;
  padding: 8px 0 24px;
}

.setup__card {
  max-width: 620px;
  padding: 30px;
}

.setup__title {
  margin: 0 0 10px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.setup__lede {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.setup__state {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 20px;
}

.setup__state strong {
  color: var(--text-primary);
}

.setup__state code,
.steps code,
.setup__lede code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--surface-control);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.setup__card--narrow {
  max-width: 420px;
}

.problems {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.problems li {
  font-size: 13px;
  color: var(--text-secondary);
  background: #2a1925;
  border: 1px solid rgba(239, 146, 120, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
}

.steps {
  margin: 0 0 22px;
  padding-left: 22px;
  color: var(--text-secondary);
  font-size: 14px;
}

.steps li {
  margin-bottom: 9px;
}

.steps a {
  color: var(--accent-bright);
}

.setup__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.paste {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.paste__label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 9px;
}

.paste__row {
  display: flex;
  gap: 9px;
}

.paste__row input {
  flex: 1;
  min-width: 0;
  background: #060b1b;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 13px;
  padding: 9px 12px;
}

.paste__row input:focus {
  outline: none;
  border-color: var(--accent);
}

.paste__row input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.setup__error {
  margin: 18px 0 0;
  font-size: 13px;
  color: #f29a8a;
}

/* --- Banners and empty state --------------------------------------------- */

.banner {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-control);
  border: 1px solid rgba(145, 167, 255, 0.24);
  border-radius: 12px;
  padding: 12px 15px;
}

.empty {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
  padding: 72px 24px;
}

.empty__title {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 500;
}

.empty__body {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* --- Tooltip ------------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: #111c37;
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-secondary);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.42);
  min-width: 132px;
  transform: translate(-50%, -100%);
}

.tooltip__title {
  color: var(--text-primary);
  font-weight: 600;
  margin-bottom: 5px;
  font-size: 13px;
}

.tooltip__row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

.tooltip__key {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tooltip__row .swatch {
  width: 9px;
  height: 9px;
  border-radius: 2.5px;
  flex: none;
}

.tooltip__num {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* --- Settings ------------------------------------------------------------ */

.settings-dialog {
  width: min(440px, calc(100vw - 32px));
  height: calc(100vh - 40px);
  max-height: none;
  margin: 20px 20px 20px auto;
  padding: 0;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.settings-dialog::backdrop {
  background: rgba(2, 4, 13, 0.76);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.settings-panel__head,
.settings-panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  flex: none;
}

.settings-panel__head {
  border-bottom: 1px solid var(--border);
}

.settings-panel__head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.settings-panel__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 22px;
}

.settings-panel__foot {
  border-top: 1px solid var(--border);
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text-primary);
  background: transparent;
}

.settings-group {
  margin: 0;
  padding: 24px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
}

.settings-group:last-child {
  border-bottom: 0;
}

.settings-group legend {
  padding: 0;
  font-size: 14px;
  font-weight: 600;
}

.settings-group__lede {
  margin: 4px 0 15px;
  color: var(--text-muted);
  font-size: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
}

.setting-row label,
.setting-row__label {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.setting-row p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
}

.setting-row--account {
  margin-top: 14px;
}

.account-disconnect-btn {
  flex: none;
}

.account-disconnect-btn:hover {
  color: var(--stage-awake);
  background: rgba(239, 146, 120, 0.08);
}

.setting-row select {
  min-width: 114px;
  min-height: 42px;
  color: var(--text-primary);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
}

.stepper {
  min-width: 128px;
  display: grid;
  grid-template-columns: 36px minmax(62px, 1fr) 36px;
  align-items: stretch;
  min-height: 42px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stepper button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}

.stepper button:hover {
  color: var(--text-primary);
  background: var(--surface-control);
}

.stepper output {
  display: grid;
  place-items: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.module-settings {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.module-setting {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 7px 8px 7px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.module-setting__toggle {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 44px;
  cursor: pointer;
}

.module-setting input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.module-setting__label {
  color: var(--text-secondary);
  font-size: 13px;
}

.module-setting__copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.module-setting__copy small {
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.35;
}

.module-setting--range-dependent {
  border-color: rgba(104, 215, 232, 0.24);
}

.module-setting--range-dependent .module-setting__copy small {
  color: #8edce8;
}

.module-setting__order {
  display: flex;
  gap: 3px;
}

.module-setting__order button {
  appearance: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}

.module-setting__order button:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--surface-control);
}

.module-setting__order button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

@media (min-width: 1400px) {
  body:has(.settings-dialog[open]) .app {
    max-width: min(1280px, calc(100vw - 496px));
    margin-left: 24px;
    margin-right: 472px;
  }
}

/* --- Chart text ---------------------------------------------------------- */

.axis-label {
  fill: var(--text-muted);
  font-size: 12.5px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}

.value-label {
  fill: var(--text-secondary);
  font-size: 12.5px;
  font-family: var(--font);
  font-weight: 500;
}

.ref-label {
  fill: var(--text-muted);
  font-size: 12px;
  font-family: var(--font);
}

.score-value {
  fill: var(--text-primary);
  font-size: 29px;
  font-weight: 700;
  font-family: var(--font);
}

.hit {
  fill: transparent;
  cursor: pointer;
}

/* --- Responsive ---------------------------------------------------------- */

@media (max-width: 860px) {
  .hero__body {
    grid-template-columns: minmax(0, 1fr) 126px;
    gap: 28px 22px;
  }

  .hero__facts {
    grid-column: 1 / -1;
    padding: 22px 0 0;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

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

@media (max-width: 560px) {
  .app {
    padding: 20px 14px 56px;
  }

  .topbar {
    align-items: flex-start;
    margin-bottom: 24px;
  }

  .topbar__title {
    font-size: 24px;
  }

  .topbar__controls {
    width: 100%;
  }

  .segmented {
    order: -1;
    flex: 1 0 100%;
    width: 100%;
    gap: 0;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding-inline: 8px;
  }

  .refresh-btn {
    margin-left: auto;
  }

  .card {
    padding: 20px;
    border-radius: 16px;
  }

  .hero {
    padding: 22px 20px 24px;
  }

  .hero__value {
    font-size: clamp(48px, 14vw, 58px);
  }

  .hero__body {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 24px 12px;
  }

  .hero__score svg {
    width: 84px;
    height: 84px;
  }

  .hero__score-copy strong {
    max-width: 84px;
    font-size: 11px;
  }

  .hero__facts {
    gap: 16px 20px;
  }

  .hero__facts dd {
    font-size: 16px;
  }

  .hypno__head,
  .card__head {
    align-items: flex-start;
  }

  .hypno__head {
    flex-direction: column;
    gap: 6px;
  }

  .hypno__head .card__meta {
    white-space: nowrap;
  }

  .legend--totals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
  }

  .legend--totals li {
    min-width: 0;
    font-size: 12px;
  }

  .legend--totals .legend__pct {
    font-size: 10.5px;
    line-height: 1.35;
  }

  .chart-detail {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .chart-disclosure__summary,
  .table-card__summary {
    min-height: 62px;
    padding: 18px 20px;
  }

  .chart-disclosure__body {
    padding: 0 20px 20px;
  }

  #duration-section,
  #schedule-section {
    padding: 22px 20px;
  }

  .settings-dialog {
    width: 100vw;
    height: calc(100vh - 20px);
    max-width: none;
    max-height: calc(100vh - 20px);
    margin: auto 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .settings-panel__head,
  .settings-panel__foot {
    padding: 16px;
  }

  .settings-panel__body {
    padding: 0 16px;
  }

  .setting-row {
    align-items: flex-start;
  }

  .setting-row > div:first-child {
    padding-top: 4px;
  }

  .module-setting {
    min-height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }

  .refresh-btn.is-refreshing svg {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   Sleep Observatory — open editorial canvas.

   Dashboard modules sit directly on the night sky and are separated by rhythm,
   alignment, and hairline rails rather than bounded panel surfaces.
---------------------------------------------------------------------------- */

.app {
  max-width: 1280px;
  padding: 26px 34px 92px;
}

.topbar {
  position: relative;
  min-height: 68px;
  margin-bottom: 38px;
  padding: 4px 6px;
  flex-wrap: nowrap;
}

.topbar__title {
  font-size: 24px;
  font-weight: 520;
  letter-spacing: -0.025em;
}

.topbar__controls {
  margin-left: auto;
  flex-wrap: nowrap;
}

.topbar__utilities {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: auto;
}

.refresh-status {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  margin: 0 6px 0 0;
  white-space: nowrap;
  line-height: 1;
}

.refresh-status__label {
  color: rgba(211, 221, 240, 0.58);
  font-size: 12px;
  font-weight: 450;
  letter-spacing: 0;
}

.refresh-status__value {
  color: rgba(224, 232, 247, 0.82);
  font-size: 12px;
  font-weight: 520;
  font-variant-numeric: tabular-nums;
}

.topbar__utilities .settings-btn,
.topbar__utilities .refresh-btn {
  width: 40px;
  height: 40px;
  min-height: 40px;
}

@media (min-width: 980px) {
  .topbar .segmented {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
}

.segmented {
  gap: 2px;
  padding: 3px;
  border: 1px solid rgba(218, 231, 255, 0.15);
  border-radius: 999px;
  background: rgba(4, 9, 23, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 -1px 0 rgba(73, 99, 153, 0.14);
}

.segmented button {
  position: relative;
  min-height: 36px;
  padding: 6px clamp(11px, 1.7vw, 20px);
  border: 1px solid transparent;
  border-radius: 999px;
  color: rgba(210, 221, 242, 0.68);
  font-size: 13px;
  font-weight: 480;
  transition:
    color 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.segmented button::after {
  display: none;
}

.segmented button:hover:not([aria-pressed='true']) {
  background: rgba(220, 233, 255, 0.07);
  color: rgba(241, 246, 255, 0.9);
}

.segmented button[aria-pressed='true'] {
  color: var(--text-primary);
  border-color: rgba(215, 231, 255, 0.24);
  background:
    linear-gradient(145deg, rgba(194, 219, 255, 0.22), rgba(107, 177, 214, 0.1)),
    rgba(104, 136, 201, 0.14);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -1px 0 rgba(75, 107, 172, 0.2),
    0 5px 14px rgba(0, 4, 18, 0.22);
}

.segmented button:active,
.ghost-btn.settings-btn:active,
.ghost-btn.refresh-btn:active {
  transform: scale(0.96);
}

.topbar__utilities .settings-btn,
.topbar__utilities .refresh-btn {
  width: 38px;
  height: 38px;
  min-height: 38px;
  border: 1px solid rgba(218, 231, 255, 0.16);
  border-radius: 50%;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.1), transparent 56%),
    rgba(9, 18, 39, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 5px 14px rgba(0, 3, 14, 0.16);
  color: rgba(225, 235, 251, 0.76);
  transition:
    color 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.topbar__utilities .settings-btn:hover,
.topbar__utilities .refresh-btn:hover {
  border-color: rgba(153, 225, 239, 0.34);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), transparent 58%),
    rgba(75, 130, 172, 0.22);
  color: var(--accent-cyan);
  transform: translateY(-1px) scale(1.03);
}

.topbar #logout-btn {
  border-color: rgba(218, 231, 255, 0.16);
  border-radius: 999px;
  background: rgba(9, 18, 39, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.dash {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: 34px;
  row-gap: 0;
}

#hero-section,
#stages-section,
#table-section,
.banner {
  grid-column: 1 / -1;
}

#duration-section {
  grid-column: 1 / 7;
}

#schedule-section {
  grid-column: 7 / -1;
}

@media (min-width: 901px) {
  .dash--schedule-full #schedule-section {
    grid-column: 1 / -1;
    padding-left: 6px;
    border-left: 0;
  }
}

.observatory-section,
.dash .card {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.night-module {
  gap: 0;
}

.hero {
  position: relative;
  overflow: visible;
  padding: 4px 6px 40px;
}

.hero::before {
  display: none;
}

.hero__head {
  align-items: flex-start;
  margin: 0 0 8px;
}

.hero__context {
  display: none;
}

.hero__head .card__title {
  color: var(--text-secondary);
  font-size: 17px;
  font-weight: 450;
  letter-spacing: 0;
}

.hero__head .card__meta {
  padding-top: 4px;
  color: rgba(193, 203, 224, 0.66);
}

.hero__body {
  grid-template-columns: minmax(290px, 0.78fr) 190px minmax(520px, 1.55fr);
  gap: clamp(34px, 4.2vw, 76px);
}

.hero__figure {
  align-self: center;
}

.hero__value {
  font-size: clamp(70px, 7vw, 102px);
  font-weight: 520;
  line-height: 0.94;
  letter-spacing: -0.055em;
  text-shadow: 0 10px 42px rgba(0, 0, 0, 0.3);
}

.hero__label {
  margin-top: 11px;
  color: var(--text-secondary);
  font-size: 14px;
}

.hero__goal-copy {
  max-width: 420px;
  margin-top: 22px;
}

.hero__goal {
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 450;
}

.hero__goal-track {
  display: block;
  width: min(100%, 420px);
  height: 8px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(79, 99, 135, 0.38);
}

.hero__goal-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #53cbe1, #8adfea);
  box-shadow: 0 0 16px rgba(104, 215, 232, 0.25);
  transition: width 0.45s ease;
}

.hero__score {
  gap: 8px;
}

.hero__score svg {
  width: 166px;
  height: 166px;
  filter: drop-shadow(0 0 14px rgba(104, 215, 232, 0.18));
}

.hero__score-copy {
  gap: 2px;
}

.hero__score-copy strong {
  color: var(--accent-cyan);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.21em;
  text-transform: uppercase;
}

.hero__facts {
  align-self: stretch;
  padding: 10px 0;
  border: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
}

.hero__facts div {
  display: flex;
  min-width: 0;
  padding: 22px clamp(12px, 1.4vw, 24px);
  border-left: 1px solid rgba(164, 190, 235, 0.2);
  flex-direction: column;
  justify-content: center;
}

.hero__facts dt {
  display: flex;
  min-height: 2.7em;
  align-items: flex-end;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 450;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
}

.hero__facts dd {
  font-size: clamp(19px, 1.9vw, 27px);
  font-weight: 480;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.hypno {
  margin: 0;
  padding: 28px 6px 34px;
  border: 0;
  border-bottom: 1px solid rgba(162, 192, 237, 0.2);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.hypno__head {
  margin-bottom: 18px;
}

.hypno__actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.calendar-values-toggle {
  display: inline-flex;
  min-height: 44px;
  padding: 6px 0;
  align-items: center;
  gap: 9px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 520;
  cursor: pointer;
}

.calendar-values-toggle:hover {
  color: var(--text-primary);
}

.calendar-values-toggle__track {
  position: relative;
  width: 30px;
  height: 16px;
  flex: none;
  border: 1px solid rgba(162, 192, 237, 0.28);
  border-radius: 999px;
  background: rgba(76, 94, 130, 0.45);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.calendar-values-toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.72);
  transition: transform 0.16s ease, background 0.16s ease;
}

.calendar-values-toggle[aria-pressed='true'] .calendar-values-toggle__track {
  border-color: rgba(104, 215, 232, 0.7);
  background: rgba(104, 215, 232, 0.34);
}

.calendar-values-toggle[aria-pressed='true'] .calendar-values-toggle__thumb {
  background: #fff;
  transform: translateX(14px);
}

.calendar-values-toggle__state {
  width: 18px;
  color: var(--text-muted);
  font-size: 11.5px;
  text-align: left;
}

.calendar-values-toggle[aria-pressed='true'] .calendar-values-toggle__state {
  color: var(--accent-cyan);
}

.section-kicker {
  margin-bottom: 5px;
  color: var(--accent-cyan);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.hypno .card__title,
.observatory-chart .card__title,
.chart-disclosure .card__title,
.table-card .card__title {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 520;
  letter-spacing: -0.02em;
}

.hypno .card__meta {
  color: rgba(211, 221, 240, 0.78);
}

#hypnogram {
  min-height: 116px;
}

.journey-label {
  fill: var(--text-secondary);
  font-family: var(--font);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.journey-segment {
  filter: drop-shadow(0 0 3px rgba(116, 156, 255, 0.12));
}

.calendar-month {
  fill: var(--text-primary);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0.02em;
}

.calendar-weekday {
  fill: rgba(211, 221, 240, 0.76);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.calendar-duration {
  fill: #fff;
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.calendar-duration--missing {
  fill: rgba(255, 255, 255, 0.38);
  font-size: 12px;
  font-weight: 450;
}

.calendar-duration--outside {
  fill: transparent;
}

.calendar-night.data-mark {
  filter: drop-shadow(0 5px 10px rgba(2, 8, 24, 0.3));
}

.calendar-year-month {
  fill: var(--text-secondary);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.calendar-year-weekday {
  fill: rgba(211, 221, 240, 0.78);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
}

.year-calendar-day {
  shape-rendering: crispEdges;
}

.year-calendar-day--missing {
  stroke-dasharray: 2 2;
}

.legend--totals {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(162, 192, 237, 0.14);
}

.legend--totals.legend--period {
  display: flex;
  gap: 10px 24px;
}

.legend--totals.legend--period li {
  display: flex;
  gap: 7px;
}

.hypno--legend-in-header .hypno__head {
  align-items: flex-end;
}

.hypno--legend-in-header .hypno__actions {
  margin-left: auto;
}

.legend--totals.legend--period.legend--heading {
  margin: 0;
  padding: 0;
  border: 0;
  gap: 8px 20px;
}

.legend--totals.legend--period.legend--heading li {
  color: var(--text-muted);
  font-size: 12.5px;
}

.legend--totals.legend--period.legend--heading .swatch {
  width: 8px;
  height: 8px;
}

.legend-line {
  width: 18px;
  height: 0;
  border-top: 1px dashed var(--accent-cyan);
}

.observatory-chart {
  min-width: 0;
  margin-top: 34px;
  padding: 28px 6px 26px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#schedule-section {
  padding-left: 34px;
  border-left: 1px solid rgba(162, 192, 237, 0.2);
}

.observatory-chart .card__head {
  margin-bottom: 14px;
}

.chart-detail {
  border-top-color: rgba(162, 192, 237, 0.15);
}

.chart-disclosure,
.table-card {
  padding: 0;
  border-bottom: 1px solid rgba(162, 192, 237, 0.2);
  background: transparent;
}

.chart-disclosure {
  margin-top: 34px;
  border: 0;
  border-top: 1px solid rgba(162, 192, 237, 0.2);
  border-bottom: 1px solid rgba(162, 192, 237, 0.2);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.chart-disclosure__summary,
.table-card__summary {
  min-height: 76px;
  padding: 22px 6px;
}

.chart-disclosure__summary {
  padding-inline: 6px;
}

.chart-disclosure__body {
  padding: 18px 6px 28px;
  border-top: 1px solid rgba(162, 192, 237, 0.14);
}

.table-scroll {
  border-top: 1px solid rgba(162, 192, 237, 0.14);
  overscroll-behavior-x: contain;
  scrollbar-color: rgba(145, 167, 255, 0.48) transparent;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.table-scroll::-webkit-scrollbar {
  height: 6px;
}

.table-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.table-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(145, 167, 255, 0.48);
}

.banner {
  margin-bottom: 24px;
}

.mobile-detail-carousel {
  grid-column: 1 / -1;
  margin-top: 18px;
  padding: 16px 0 0;
  border: 0;
  border-top: 1px solid rgba(162, 192, 237, 0.18);
  border-radius: 0;
  background: transparent;
}

.mobile-detail-carousel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
}

.mobile-detail-carousel__head .section-kicker {
  margin: 0;
}

.mobile-detail-tabs {
  display: flex;
  width: 100%;
  border-bottom: 1px solid rgba(162, 192, 237, 0.18);
}

.mobile-detail-tabs button {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 9px 5px 10px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 520;
  white-space: nowrap;
  cursor: pointer;
}

.mobile-detail-tabs button::after {
  content: '';
  position: absolute;
  right: 8px;
  bottom: -1px;
  left: 8px;
  height: 2px;
  background: var(--accent-cyan);
  transform: scaleX(0);
  transition: transform 0.16s ease;
}

.mobile-detail-tabs button[aria-selected='true'] {
  color: var(--text-primary);
}

.mobile-detail-tabs button[aria-selected='true']::after {
  transform: scaleX(1);
}

.mobile-detail-pages {
  display: flex;
  align-items: flex-start;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  transition: height 0.18s ease;
  -webkit-overflow-scrolling: touch;
}

.mobile-detail-pages::-webkit-scrollbar {
  display: none;
}

.mobile-detail-pages > [data-dashboard-module] {
  flex: 0 0 100%;
  width: 100%;
  max-width: 100%;
  margin-top: 0;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1340px) {
  .hero__body {
    grid-template-columns: minmax(270px, 0.8fr) 168px minmax(390px, 1.3fr);
    gap: 30px;
  }

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

  .hero__facts div {
    padding-inline: 10px;
  }

  .hero__facts dd {
    font-size: 21px;
  }
}

@media (max-width: 900px) {
  .app {
    padding-inline: 24px;
  }

  .topbar {
    flex-wrap: wrap;
    margin-bottom: 32px;
    padding: 4px 6px;
  }

  .topbar__controls {
    flex-wrap: wrap;
  }

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

  #hero-section,
  #duration-section,
  #schedule-section,
  #stages-section,
  #table-section,
  .banner {
    grid-column: 1;
  }

  .hero__body {
    grid-template-columns: minmax(0, 1fr) 170px;
  }

  .hero__facts {
    grid-column: 1 / -1;
    padding-top: 14px;
    border-top: 1px solid rgba(162, 192, 237, 0.18);
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hero__facts div:nth-child(3),
  .hero__facts div:nth-child(4) {
    border-top: 0;
  }

  #schedule-section {
    padding-left: 22px;
    border-left: 0;
  }
}

@media (max-width: 620px) {
  .app {
    padding: 18px 14px 56px;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      'identity utilities'
      'range range';
    align-items: flex-start;
    margin-bottom: 24px;
    padding: 0;
    gap: 6px 8px;
  }

  .topbar__identity {
    grid-area: identity;
    align-self: center;
  }

  .topbar__title {
    font-size: 23px;
  }

  .topbar__controls {
    display: contents;
    width: auto;
    margin: 0;
  }

  .topbar__utilities {
    grid-area: utilities;
    display: grid;
    grid-template-columns: repeat(2, 44px);
    grid-template-areas:
      'status status'
      'refresh settings';
    justify-self: end;
    align-self: start;
    margin: 0;
  }

  .segmented {
    grid-area: range;
    order: initial;
    width: 100%;
    gap: 2px;
    padding: 3px;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding-inline: 3px;
    font-size: clamp(11px, 3.1vw, 12px);
    white-space: nowrap;
  }

  .refresh-btn {
    grid-area: refresh;
    margin-left: 0;
  }

  .settings-btn {
    grid-area: settings;
  }

  .topbar__utilities .settings-btn,
  .topbar__utilities .refresh-btn {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .refresh-status {
    grid-area: status;
    display: grid;
    justify-items: end;
    gap: 0;
    margin: 0 4px 3px 0;
    line-height: 1.1;
  }

  .topbar__device-sync {
    display: none;
  }

  .topbar #logout-btn:not([hidden]) {
    grid-column: 1 / -1;
    justify-self: end;
  }

  .hero {
    padding: 0 0 30px;
  }

  .hero__head {
    margin-bottom: 18px;
  }

  .hero__head .card__meta {
    max-width: 52%;
    text-align: right;
  }

  .hero__body {
    grid-template-columns: minmax(0, 1fr) 104px;
    gap: 18px 10px;
  }

  .hero__value {
    font-size: clamp(52px, 15vw, 68px);
  }

  .hero__label {
    font-size: 12px;
  }

  .hero__goal-copy {
    margin-top: 18px;
  }

  .hero__score svg {
    width: 100px;
    height: 100px;
  }

  .hero__score-copy strong {
    max-width: 100px;
    font-size: 8px;
  }

  .hero__facts {
    padding: 12px 0 0;
    border-top: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 24px;
  }

  .hero__facts div {
    padding: 10px 0;
    border: 0;
  }

  .hero__facts div:nth-child(3),
  .hero__facts div:nth-child(4) {
    border-top: 0;
  }

  .hero__facts dd {
    font-size: 17px;
  }

  .hypno {
    padding: 22px 0 26px;
    border-top: 1px solid var(--section-divider);
    border-bottom: 0;
  }

  .hypno__head {
    align-items: flex-start;
  }

  .hypno__head > div:first-child {
    width: 100%;
    align-self: stretch;
    margin: 0;
    text-align: left;
  }

  .hypno__actions {
    width: 100%;
    justify-content: space-between;
  }

  .hypno--legend-in-header .hypno__head {
    flex-direction: column;
    gap: 10px;
  }

  .hypno--legend-in-header .hypno__actions {
    width: 100%;
    margin-left: 0;
    justify-content: center;
  }

  .legend--totals.legend--period.legend--heading {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
  }

  .legend--totals,
  .legend--totals.legend--period {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
  }

  .legend--totals.legend--period {
    display: grid;
  }

  .observatory-chart {
    margin-top: 18px;
    padding: 22px 0 24px;
  }

  #schedule-section {
    padding-left: 0;
  }

  .chart-disclosure__summary,
  .table-card__summary {
    padding-inline: 0;
  }

  .chart-disclosure__summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding-block: 18px;
  }

  .stage-chart-key {
    justify-content: flex-start;
    margin-left: 0;
    gap: 8px 18px;
  }

  .chart-disclosure__body {
    padding-inline: 0;
    border-top: 0;
  }

  .chart-disclosure {
    margin-top: 18px;
    border-top: 0;
    border-bottom: 0;
  }

  .mobile-detail-carousel {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--section-divider);
  }

  .mobile-detail-tabs {
    margin-bottom: 8px;
    border-bottom: 0;
  }

  .chart-detail {
    margin-top: 10px;
    padding-top: 0;
    border-top: 0;
  }

  .legend--totals {
    padding-top: 0;
    border-top: 0;
  }

  .table-card {
    margin-top: 28px;
    border-top: 1px solid var(--section-divider);
    border-bottom: 0;
  }

  .table-scroll {
    border-top: 0;
  }

  .hero__score-copy strong {
    font-size: 10px;
  }

  .settings-panel__head .icon-btn,
  .settings-panel__foot .ghost-btn,
  .settings-panel__foot .primary-btn {
    min-height: 44px;
  }

  .settings-panel__head .icon-btn {
    width: 44px;
    height: 44px;
  }

  .setting-row {
    gap: 10px;
  }

  .setting-row select {
    min-height: 44px;
  }

  .stepper {
    min-width: 144px;
    min-height: 46px;
    grid-template-columns: 44px minmax(56px, 1fr) 44px;
    flex: none;
  }

  .module-setting__order button {
    width: 44px;
    height: 44px;
  }

  .table-scroll {
    max-height: min(62vh, 560px);
    overflow: auto;
  }

  .table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #080f22;
  }

  .table th:first-child {
    z-index: 3;
  }
}

@media (max-width: 350px) {
  .topbar__title {
    gap: 8px;
    font-size: 20px;
  }

  .topbar__device {
    margin-top: 5px;
    margin-left: 26px;
    font-size: 11.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-detail-pages {
    scroll-behavior: auto;
    transition: none;
  }
}

.legend--totals.legend--period.legend--sleep-scale {
  display: block;
  width: min(100%, 680px);
  margin-inline: auto;
}

.legend--totals.legend--period.legend--sleep-scale .sleep-scale {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
}

.sleep-scale__main,
.sleep-scale__missing {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 12.5px;
  white-space: nowrap;
}

.sleep-scale__bar {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 2px;
  width: clamp(150px, 22vw, 210px);
  height: 10px;
}

.sleep-scale__bar i,
.sleep-scale__missing i {
  display: block;
  width: auto;
  height: 100%;
}

.sleep-scale__bar i:first-child {
  border-radius: 2px 0 0 2px;
}

.sleep-scale__bar i:last-child {
  border-radius: 0 2px 2px 0;
}

.sleep-scale__missing i {
  width: 11px;
  height: 11px;
  border: 1px dashed rgba(162, 192, 237, 0.58);
}

@media (max-width: 620px) {
  .legend--totals.legend--period.legend--sleep-scale .sleep-scale {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .sleep-scale__main {
    width: 100%;
    justify-content: center;
  }

  .sleep-scale__bar {
    width: min(46vw, 172px);
  }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .segmented,
  .topbar__utilities .settings-btn,
  .topbar__utilities .refresh-btn {
    background: #111e38;
  }
}
