/* ── CSS custom properties ─────────────────────────────── */
:root {
  --purple:      #9B59B6;
  --purple-dark: #7D3C98;
  --purple-light:#D7BDE2;
  --deep:        #3D2B5A;
  --gold:        #F4C430;
  --success:     #6BCBA0;
  --card-bg:     rgba(255, 255, 255, 0.74);
  --text-muted:  #7B6FA0;
  --radius-lg:   24px;
  --radius-md:   14px;
  --radius-sm:   10px;
}

/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--deep);
  min-height: 100dvh;
  background: linear-gradient(135deg, #C9B8E8, #F2C2CE, #B8DDD4, #F9D4BB, #D4B8E8);
  background-size: 400% 400%;
  animation: aurora 12s ease infinite;
  overscroll-behavior: none;
}

@keyframes aurora {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ── Layout ────────────────────────────────────────────── */
.page-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px env(safe-area-inset-bottom, 20px);
  padding-top: 0;
}

main {
  padding-bottom: 40px;
}

/* ── Navigation ────────────────────────────────────────── */
.nav {
  display: flex;
  gap: 8px;
  padding: 16px 0 12px;
  justify-content: center;
}

.nav-link {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 8px 20px;
  border-radius: 50px;
  color: var(--deep);
  background: rgba(255,255,255,0.45);
  transition: background 0.2s, transform 0.15s;
  touch-action: manipulation;
}

.nav-link.active {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 2px 12px rgba(155,89,182,0.35);
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: 0 4px 24px rgba(155,89,182,0.13);
  margin-bottom: 16px;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--deep);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Page header ───────────────────────────────────────── */
.page-header {
  text-align: center;
  padding: 20px 0 16px;
}

.page-header h1 {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--deep);
  line-height: 1.2;
}

.page-header .date-chip {
  display: inline-block;
  margin-top: 6px;
  background: rgba(255,255,255,0.55);
  border-radius: 50px;
  padding: 4px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Form fields ───────────────────────────────────────── */
.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--deep);
}

input[type="time"],
textarea {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: rgba(255,255,255,0.8);
  border: 2px solid var(--purple-light);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--deep);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
}

input[type="time"]:focus,
textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(155,89,182,0.18);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

textarea::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Pill buttons (sleep latency) ──────────────────────── */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-group input[type="radio"] {
  display: none;
}

.pill-group label {
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 50px;
  border: 2px solid var(--purple-light);
  background: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.pill-group input[type="radio"]:checked + label {
  background: var(--purple);
  border-color: var(--purple);
  color: #fff;
  box-shadow: 0 2px 10px rgba(155,89,182,0.3);
}

/* ── Quality slider ────────────────────────────────────── */
.slider-wrap {
  padding: 4px 0 8px;
}

.slider-emoji-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.3rem;
  margin-bottom: 6px;
  padding: 0 2px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--purple) 0%,
    var(--purple) var(--value, 40%),
    var(--purple-light) var(--value, 40%),
    var(--purple-light) 100%
  );
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--purple);
  box-shadow: 0 2px 10px rgba(155,89,182,0.35);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.slider-value-display {
  text-align: center;
  margin-top: 10px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--purple);
}

/* ── Save button ───────────────────────────────────────── */
.btn-save {
  display: block;
  width: 100%;
  padding: 18px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--purple), #C39BD3);
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(155,89,182,0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  touch-action: manipulation;
  margin-top: 8px;
}

.btn-save:active {
  transform: scale(0.94);
  box-shadow: 0 2px 10px rgba(155,89,182,0.25);
}

/* ── HTMX loading indicator ────────────────────────────── */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator {
  display: inline;
}
.htmx-request.btn-save .btn-label {
  display: none;
}
.htmx-request.btn-save {
  opacity: 0.75;
  pointer-events: none;
}

/* ── Success state ─────────────────────────────────────── */
.success-card {
  text-align: center;
  padding: 36px 24px;
}

.checkmark-wrap {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes pop-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.checkmark-svg {
  width: 44px;
  height: 44px;
}

.checkmark-svg path {
  stroke: #fff;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: draw-check 0.5s 0.3s ease forwards;
}

@keyframes draw-check {
  to { stroke-dashoffset: 0; }
}

.success-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
  color: var(--deep);
}

.success-duration {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.success-quality {
  font-size: 1.3rem;
  margin-bottom: 24px;
}

.btn-edit {
  display: inline-block;
  padding: 12px 28px;
  border-radius: 50px;
  background: rgba(255,255,255,0.7);
  border: 2px solid var(--purple-light);
  color: var(--purple);
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: background 0.15s;
}

.btn-edit:active {
  background: var(--purple-light);
}

/* ── History page ──────────────────────────────────────── */
.history-header {
  text-align: center;
  padding: 20px 0 16px;
}

.history-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
}

.history-entry {
  cursor: default;
}

.history-entry .entry-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.entry-date {
  font-size: 1rem;
  font-weight: 800;
  color: var(--deep);
}

.entry-duration {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.entry-times {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.entry-stars {
  font-size: 1.15rem;
  margin-bottom: 6px;
  letter-spacing: 2px;
}

.entry-notes {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 600;
}

/* ── Chart card ────────────────────────────────────────── */
.chart-card {
  padding: 20px;
}

.chart-card canvas {
  width: 100% !important;
}

/* ── Animations: stars float up on success ─────────────── */
@keyframes float-up {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-80px) scale(0.5); }
}

.star-particle {
  position: fixed;
  pointer-events: none;
  font-size: 1.4rem;
  animation: float-up 1s ease forwards;
  z-index: 9999;
}

/* ── Routine page ──────────────────────────────────────── */
.routine-header {
  text-align: center;
  padding: 20px 0 16px;
}

.routine-header h1 {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--deep);
  line-height: 1.2;
}

.routine-subtitle {
  display: inline-block;
  margin-top: 6px;
  background: rgba(255,255,255,0.55);
  border-radius: 50px;
  padding: 4px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.routine-timeline {
  position: relative;
  padding-left: 44px;
}

.routine-timeline::before {
  content: '';
  position: absolute;
  left: 18px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: repeating-linear-gradient(
    to bottom,
    #C8C6BE 0px,
    #C8C6BE 3px,
    transparent 3px,
    transparent 7px
  );
}

.routine-phase-banner {
  margin: 16px 0 12px;
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.05em;
}

.routine-phase-banner.wind-down {
  background: #D8EED8;
  border: 0.8px solid #A8D4A8;
  color: #2A6A2A;
}

.routine-phase-banner.night {
  background: #D8D4EC;
  border: 0.8px solid #A8A0D0;
  color: #3A3480;
}

.routine-entry {
  position: relative;
  margin-bottom: 10px;
}

.routine-dot {
  position: absolute;
  left: -33px;
  top: 14px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #D4A820;
  background: #F5C842;
  z-index: 1;
}

.routine-entry.day  .routine-dot { background: #F5C842; border-color: #D4A820; }
.routine-entry.wind .routine-dot { background: #B0C8E8; border-color: #6898C8; }
.routine-entry.night .routine-dot { background: #9098C8; border-color: #5060A8; }

.routine-card {
  background: rgba(255,255,255,0.93);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.10);
  border-left: 4px solid #E8D870;
}

.routine-entry.wind  .routine-card { border-left-color: #A8C8E8; }
.routine-entry.night .routine-card { border-left-color: #8898D8; }

.routine-card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.routine-time {
  font-size: 0.80rem;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.routine-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--deep);
  line-height: 1.3;
}

.routine-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.routine-detail {
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 1px;
}

.routine-detail-sub {
  font-size: 0.78rem;
  font-weight: 600;
  color: #4A6898;
  line-height: 1.4;
  margin-top: 2px;
  padding-left: 10px;
  border-left: 2px solid rgba(104,152,200,0.35);
}

.dont-badge {
  display: inline-block;
  background: #FDE8E8;
  color: #A33030;
  font-size: 0.70rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 50px;
  white-space: nowrap;
}

.routine-footer-note {
  text-align: center;
  padding: 12px 8px 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.routine-section {
  border-radius: var(--radius);
  padding: 16px 16px 10px;
  margin-bottom: 14px;
}

.routine-section.wake {
  background: linear-gradient(150deg, #FFFAE0 0%, #FFF0A8 100%);
  border: 1.5px solid #E0C030;
}

.routine-section.sleep {
  background: linear-gradient(150deg, #EEF0FF 0%, #DCDEFF 100%);
  border: 1.5px solid #8090D0;
}

.routine-section-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--deep);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
