:root {
  --bg: #0c0e21;
  --bg-deep: #060714;
  --card: #161a3a;
  --card-2: #1d2147;
  --hairline: #2b2f5c;
  --text: #eeecf9;
  --text-muted: #8d8bb5;
  --moon: #f5d48a;
  --moon-dim: #6b5a3a;
  --teal: #6fe3c4;
  --danger: #e8768a;
  --shadow: 0 20px 60px rgba(3, 4, 16, 0.55);
  --radius: 18px;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Sora', system-ui, sans-serif;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1px 1px at 10% 20%, #fff, transparent),
    radial-gradient(1px 1px at 80% 10%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60% 70%, #fff, transparent),
    radial-gradient(1px 1px at 30% 85%, #fff, transparent),
    radial-gradient(1px 1px at 90% 60%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 45% 35%, #fff, transparent),
    radial-gradient(1px 1px at 15% 55%, #fff, transparent),
    radial-gradient(1px 1px at 70% 90%, #fff, transparent),
    linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 55%, #10133012 100%);
  opacity: 0.55;
}

.app {
  max-width: 960px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* ---------- hero ---------- */

.hero { text-align: center; margin-bottom: 48px; }

.hero-eyebrow {
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--moon);
  opacity: 0.85;
  margin-bottom: 14px;
}

.hero-title {
  font-family: 'Fraunces', serif;
  font-optical-sizing: auto;
  font-weight: 500;
  font-size: clamp(32px, 5vw, 46px);
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.hero-status {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 28px;
  min-height: 20px;
}

.toggle-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 18px 40px;
  border-radius: 999px;
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 17px;
  background: linear-gradient(180deg, #f7dd9e, var(--moon));
  color: #241a08;
  box-shadow: 0 12px 30px rgba(245, 212, 138, 0.25), 0 2px 0 rgba(0,0,0,0.15) inset;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}
.toggle-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 16px 34px rgba(245, 212, 138, 0.32); }
.toggle-btn:active:not(:disabled) { transform: translateY(0px) scale(0.98); }
.toggle-btn:disabled { opacity: 0.5; cursor: default; }

.toggle-btn.is-sleeping {
  background: linear-gradient(180deg, #2a2f5f, #1c2049);
  color: var(--teal);
  box-shadow: 0 12px 30px rgba(111, 227, 196, 0.15), 0 2px 0 rgba(0,0,0,0.25) inset;
  border: 1px solid rgba(111, 227, 196, 0.35);
}

.toggle-btn-icon { font-size: 20px; }

.hero-timer {
  margin-top: 18px;
  font-family: 'Fraunces', serif;
  font-size: 28px;
  color: var(--teal);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* ---------- layout ---------- */

main {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; }
}

.panel {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 22px 22px 26px;
  box-shadow: var(--shadow);
}

/* ---------- calendar ---------- */

.calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.month-label {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 20px;
  margin: 0;
}

.nav-btn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.nav-btn:hover { background: rgba(255,255,255,0.05); border-color: var(--moon); }

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.weekday-row span {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-cell {
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.02);
  padding: 6px 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.day-cell:hover { border-color: var(--hairline); background: rgba(255,255,255,0.045); }
.day-cell:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.day-cell.is-empty { visibility: hidden; cursor: default; }
.day-cell.is-today { border-color: var(--moon); }
.day-cell.is-selected { background: rgba(111, 227, 196, 0.1); border-color: var(--teal); }

.day-num {
  font-size: 12px;
  color: var(--text-muted);
}
.day-cell.is-today .day-num { color: var(--moon); font-weight: 600; }

/* signature element: a mini 24h timeline showing exactly where sleep fell */
.day-track {
  position: relative;
  height: 7px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
.day-track .seg {
  position: absolute;
  top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--moon-dim), var(--moon));
  border-radius: 4px;
}
.day-track .seg.is-open {
  background: linear-gradient(90deg, #234a44, var(--teal));
}

.day-duration {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.day-cell.has-sleep .day-duration { color: var(--moon); }

.calendar-legend {
  display: flex;
  gap: 18px;
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 14px; height: 6px; border-radius: 3px; display: inline-block; }
.legend-swatch--sleep { background: linear-gradient(90deg, var(--moon-dim), var(--moon)); }
.legend-swatch--now { background: linear-gradient(90deg, #234a44, var(--teal)); }

/* ---------- entries panel ---------- */

.entries-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.entries-head h2 {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 19px;
  margin: 0;
}

.add-btn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.add-btn:hover { border-color: var(--teal); background: rgba(111, 227, 196, 0.08); }

.entries-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.entries-empty { color: var(--text-muted); font-size: 14px; padding: 8px 2px; }

.entry-card {
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.02);
}

.entry-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.entry-duration {
  font-family: 'Fraunces', serif;
  font-size: 17px;
  color: var(--moon);
}
.entry-duration.is-open { color: var(--teal); }

.entry-times {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.entry-note {
  font-size: 13px;
  color: var(--text);
  margin-top: 6px;
  opacity: 0.9;
}

.entry-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.entry-actions button {
  appearance: none;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text-muted);
  font-family: 'Sora', sans-serif;
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.entry-actions button:hover { color: var(--text); border-color: var(--moon); }
.entry-actions button.danger:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 16, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--card-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}

.modal h3 {
  font-family: 'Fraunces', serif;
  font-weight: 500;
  font-size: 20px;
  margin: 0 0 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.field em { font-style: normal; opacity: 0.7; }

.field input {
  font-family: 'Sora', sans-serif;
  font-size: 14px;
  color: var(--text);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  color-scheme: dark;
}
.field input:focus { border-color: var(--teal); }

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: -4px 0 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.btn-ghost, .btn-primary {
  appearance: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-family: 'Sora', sans-serif;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-ghost {
  background: transparent;
  border-color: var(--hairline);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); }
.btn-primary {
  background: var(--moon);
  color: #241a08;
}
.btn-primary:hover { filter: brightness(1.05); }
