*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d0f18;
  --bg-p:       #13162080;
  --bg-p2:      #1c1f30;
  --border:     #252840;
  --text:       #dde3f0;
  --muted:      #6b7594;
  --dim:        #3d4260;
  --accent:     #7c3aed;
  --accent-lo:  rgba(124,58,237,0.18);
  --green:      #10b981;
  --yellow:     #f59e0b;
  --red:        #ef4444;
  --c-wake:     #6b7594;
  --c-rem:      #a855f7;
  --c-n1:       #7dd3fc;
  --c-n2:       #3b82f6;
  --c-n3:       #4f46e5;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 15px; }

#root { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ── Header ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1.5rem; background: #11142080;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  backdrop-filter: blur(8px);
}
.hdr-left { display: flex; align-items: center; gap: 0.65rem; }
.logo { font-size: 1.7rem; }
.hdr-title h1 { font-size: 1.1rem; font-weight: 600; letter-spacing: 0.02em; }
.hdr-title p  { font-size: 0.7rem; color: var(--muted); }
.hdr-right { display: flex; align-items: center; gap: 1rem; }
.time-group { display: flex; flex-direction: column; align-items: center; }
.time-label { font-size: 0.6rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.time-value { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.time-divider { color: var(--dim); font-size: 1.3rem; }
.tz-badge {
  background: var(--bg-p2); border: 1px solid var(--border);
  border-radius: 1rem; padding: 0.18rem 0.65rem;
  font-size: 0.7rem; color: var(--muted);
}

/* ── Nav ── */
nav {
  display: flex; background: #0f1120; border-bottom: 1px solid var(--border);
  flex-shrink: 0; padding: 0 1rem; overflow-x: auto;
}
nav::-webkit-scrollbar { display: none; }
.tab-btn {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 0.6rem 1rem; cursor: pointer;
  font-size: 0.82rem; font-weight: 500; transition: all 0.15s; white-space: nowrap;
}
.tab-btn:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Main ── */
#content {
  flex: 1; overflow-y: auto; padding: 1.1rem 1.25rem;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#content::-webkit-scrollbar { width: 4px; }
#content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tab { display: none; }
.tab.active { display: block; }

/* ── Cards ── */
.card {
  background: #12152280; border: 1px solid var(--border);
  border-radius: 0.7rem; padding: 1.1rem; margin-bottom: 1rem;
  backdrop-filter: blur(4px);
}
.card h2 {
  font-size: 0.95rem; font-weight: 600; margin-bottom: 0.9rem;
  padding-bottom: 0.45rem; border-bottom: 1px solid var(--border);
}
.muted { color: var(--muted); font-size: 0.82rem; line-height: 1.65; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* ── Form ── */
.form-group { margin-bottom: 0.8rem; }
.form-group label {
  display: block; font-size: 0.72rem; color: var(--muted);
  margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.06em;
}
.form-group select,
.form-group input[type="time"] {
  width: 100%; background: var(--bg-p2); border: 1px solid var(--border);
  border-radius: 0.4rem; color: var(--text); padding: 0.45rem 0.7rem;
  font-size: 0.88rem; outline: none; transition: border-color 0.15s;
  appearance: auto;
}
.form-group select:focus,
.form-group input:focus { border-color: var(--accent); }

.chrono-row { display: flex; gap: 0.4rem; }
.chrono-btn {
  flex: 1; background: var(--bg-p2); border: 1px solid var(--border);
  border-radius: 0.4rem; color: var(--muted); padding: 0.38rem 0.3rem;
  font-size: 0.75rem; cursor: pointer; text-align: center;
  transition: all 0.15s; user-select: none;
}
.chrono-btn:hover { color: var(--text); }
.chrono-btn.selected {
  background: var(--accent-lo); border-color: var(--accent); color: var(--text);
}

.calc-btn {
  width: 100%; background: var(--accent); border: none; border-radius: 0.45rem;
  color: white; padding: 0.6rem; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; margin-top: 0.4rem; transition: opacity 0.15s;
}
.calc-btn:hover { opacity: 0.82; }

/* ── Schedule results ── */
.rec-band {
  background: var(--accent-lo); border: 1px solid var(--accent);
  border-radius: 0.45rem; padding: 0.55rem 0.75rem; margin-bottom: 0.75rem;
  font-size: 0.82rem;
}
.rec-band strong { color: #c4b5fd; font-size: 1rem; }

.sched-grid { display: flex; flex-direction: column; gap: 0.45rem; }
.sched-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.5rem 0.7rem; background: var(--bg-p2);
  border-radius: 0.45rem; border-left: 3px solid var(--dim);
}
.sched-item.wd   { border-left-color: var(--yellow); }
.sched-item.bed  { border-left-color: var(--c-n3); }
.sched-item.wk   { border-left-color: var(--green); }
.sched-times { display: flex; flex-direction: column; min-width: 4rem; }
.sched-local { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.sched-utc   { font-size: 0.65rem; color: var(--dim); }
.sched-label { font-size: 0.8rem; color: var(--muted); }

.cycles-note {
  margin-top: 0.65rem; padding: 0.45rem 0.7rem; background: var(--bg-p2);
  border-radius: 0.4rem; border-left: 3px solid var(--c-n2);
  font-size: 0.78rem; color: var(--muted);
}
.cycles-note strong { color: var(--c-n1); }

/* ── World chart ── */
.world-bars { display: flex; flex-direction: column; gap: 0.38rem; }
.world-row { display: flex; align-items: center; gap: 0.65rem; }
.world-country {
  font-size: 0.74rem; color: var(--muted); width: 5.5rem;
  text-align: right; flex-shrink: 0;
}
.world-bar-wrap {
  flex: 1; background: #1c1f30; border-radius: 0.2rem;
  height: 1rem; position: relative; overflow: hidden;
}
.world-bar {
  height: 100%; border-radius: 0.2rem;
  background: var(--c-n2); transition: width 0.5s ease;
}
.world-bar.ur { background: var(--green); }
.world-avg-line {
  position: absolute; top: 0; bottom: 0; width: 2px;
  background: rgba(245,158,11,0.55);
}
.world-hrs { font-size: 0.7rem; color: var(--dim); width: 2.3rem; flex-shrink: 0; }
.world-note { margin-top: 0.5rem; font-size: 0.7rem; color: var(--dim); }

/* ── Hypnogram ── */
.hypnogram-wrap {
  width: 100%; background: var(--bg-p2); border-radius: 0.5rem;
  padding: 0.75rem 0.5rem 0.5rem; overflow: hidden;
}
canvas#hypnogram { width: 100%; height: auto; display: block; }
.stages-legend { display: flex; gap: 1.2rem; margin-top: 0.7rem; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 0.35rem; font-size: 0.76rem; color: var(--muted); }
.legend-item span { width: 0.85rem; height: 0.85rem; border-radius: 0.15rem; display: inline-block; }
.legend-item.wake span { background: var(--c-wake); }
.legend-item.rem  span { background: var(--c-rem); }
.legend-item.n1   span { background: var(--c-n1); }
.legend-item.n2   span { background: var(--c-n2); }
.legend-item.n3   span { background: var(--c-n3); }

.stage-cards {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.7rem; margin-bottom: 1rem;
}
.stage-card {
  background: #12152280; border: 1px solid var(--border);
  border-radius: 0.5rem; padding: 0.75rem; border-top: 3px solid;
}
.stage-card.wake { border-top-color: var(--c-wake); }
.stage-card.n1   { border-top-color: var(--c-n1); }
.stage-card.n2   { border-top-color: var(--c-n2); }
.stage-card.n3   { border-top-color: var(--c-n3); }
.stage-card.rem  { border-top-color: var(--c-rem); }
.stage-card h3 { font-size: 0.78rem; font-weight: 700; margin-bottom: 0.35rem; }
.stage-card p  { font-size: 0.74rem; color: var(--muted); line-height: 1.55; }

/* ── Wind Down ── */
.winddown-timeline { position: relative; padding-left: 1.4rem; }
.winddown-timeline::before {
  content: ''; position: absolute; left: 0.55rem; top: 0.8rem; bottom: 0.8rem;
  width: 2px; background: var(--border);
}
.wd-step { position: relative; margin-bottom: 1.2rem; }
.wd-step::before {
  content: ''; position: absolute; left: -0.85rem; top: 0.35rem;
  width: 0.65rem; height: 0.65rem; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.wd-time { font-size: 0.65rem; color: var(--dim); text-transform: uppercase;
  letter-spacing: 0.07em; margin-bottom: 0.15rem; }
.wd-step h3 { font-size: 0.88rem; font-weight: 600; margin-bottom: 0.3rem; }
.wd-step ul { list-style: none; padding: 0; }
.wd-step ul li {
  font-size: 0.78rem; color: var(--muted); padding: 0.18rem 0 0.18rem 1rem;
  position: relative;
}
.wd-step ul li::before { content: '→'; position: absolute; left: 0; color: var(--dim); }
.tip-box {
  background: var(--bg-p2); border: 1px solid var(--border);
  border-left: 3px solid var(--yellow); border-radius: 0.4rem;
  padding: 0.6rem 0.85rem; margin-top: 0.45rem;
  font-size: 0.78rem; color: var(--muted); line-height: 1.6;
}

.sub-h { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.45rem; }
.plain-list { list-style: none; padding: 0; }
.plain-list li {
  font-size: 0.78rem; color: var(--muted); padding: 0.28rem 0;
  border-bottom: 1px solid var(--border); line-height: 1.55;
}
.plain-list li:last-child { border-bottom: none; }

.env-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; margin-top: 0.75rem; }
.env-item {
  background: var(--bg-p2); border-radius: 0.45rem; padding: 0.65rem;
  display: flex; gap: 0.65rem; align-items: flex-start;
}
.env-icon { font-size: 1.3rem; flex-shrink: 0; }
.env-item h4 { font-size: 0.78rem; font-weight: 600; margin-bottom: 0.18rem; }
.env-item p  { font-size: 0.73rem; color: var(--muted); line-height: 1.5; }

/* ── Help ── */
.help-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.help-card { background: var(--bg-p2); border-radius: 0.5rem; padding: 0.85rem; }
.help-card h3 { font-size: 0.83rem; font-weight: 600; margin-bottom: 0.35rem; }
.help-card p  { font-size: 0.78rem; color: var(--muted); margin-bottom: 0.35rem; line-height: 1.55; }
.help-card ul { padding-left: 1.1rem; }
.help-card li { font-size: 0.77rem; color: var(--muted); padding: 0.15rem 0; line-height: 1.55; }

.night-waking { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; margin-bottom: 0.75rem; }
.nw-card {
  background: var(--bg-p2); border-radius: 0.5rem; padding: 0.75rem;
  border-top: 3px solid var(--accent);
}
.nw-card h3 { font-size: 0.78rem; font-weight: 700; margin-bottom: 0.3rem; }
.nw-card p  { font-size: 0.75rem; color: var(--muted); line-height: 1.55; }

.adjust-steps { display: flex; flex-direction: column; gap: 0.45rem; counter-reset: step; }
.adjust-step {
  counter-increment: step; display: flex; gap: 0.7rem; align-items: flex-start;
  background: var(--bg-p2); border-radius: 0.4rem; padding: 0.55rem 0.75rem;
}
.adjust-step::before {
  content: counter(step); background: var(--accent); color: white;
  width: 1.25rem; height: 1.25rem; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 0.72rem;
  font-weight: 700; flex-shrink: 0; margin-top: 0.05rem;
}
.adjust-step div { font-size: 0.78rem; color: var(--muted); line-height: 1.55; }
.adjust-step strong { display: block; color: var(--text); margin-bottom: 0.15rem; font-size: 0.82rem; }

.doctor-box {
  background: rgba(239,68,68,0.06); border: 1px solid rgba(239,68,68,0.25);
  border-radius: 0.5rem; padding: 0.75rem 1rem; margin-top: 0.75rem;
  font-size: 0.78rem; color: var(--muted); line-height: 1.6;
}
.doctor-box strong { color: #fca5a5; }

/* ── Responsive ── */
@media (max-width: 800px) {
  .grid-2        { grid-template-columns: 1fr; }
  .stage-cards   { grid-template-columns: repeat(2, 1fr); }
  .help-cards    { grid-template-columns: 1fr; }
  .night-waking  { grid-template-columns: 1fr; }
  .env-grid      { grid-template-columns: 1fr; }
  .hdr-right     { display: none; }
}
@media (max-width: 500px) {
  .stage-cards { grid-template-columns: 1fr; }
}
