:root {
  --bg: #0B1026;
  --card: #161D42;
  --card2: #1C2450;
  --border: #2A3268;
  --text: #E9ECF8;
  --text-dim: #9AA3D0;
  --accent: #B9A6F0;
  --accent2: #F0A868;
  --good: #7FD8A8;
  --warn: #F0C868;
  --stage-awake: #F0A868;
  --stage-rem: #6FA8D8;
  --stage-light: #7C8FD6;
  --stage-deep: #4A3E86;
  --noise-snore: #B9A6F0;
  --noise-cough: #F0A868;
  --noise-talk: #6FA8D8;
  --noise-other: #7A82A8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(ellipse 120% 80% at 50% -10%, #1a2258 0%, var(--bg) 55%);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.font-display { font-family: 'Fraunces', serif; }
.font-mono { font-family: 'IBM Plex Mono', monospace; }

#app {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: 90px;
}

.topbar { padding: 22px 20px 6px; font-family: 'IBM Plex Mono', monospace; font-size: 11px; letter-spacing: 2px; color: var(--text-dim); text-transform: uppercase; }

.screen { padding: 0 20px 24px; display: none; }
.screen.active { display: block; }

h1.page-title { font-family: 'Fraunces', serif; font-size: 24px; font-weight: 500; margin: 4px 0 4px; }
.subtitle { color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 0;
}

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 2px 12px;
  font-family: 'Fraunces', serif; font-size: 19px; font-weight: 600;
}

.stat-row { display: flex; gap: 8px; margin-top: 14px; }
.stat-chip {
  flex: 1; background: var(--card2); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 6px;
}
.stat-chip .val { font-family: 'IBM Plex Mono', monospace; font-size: 16px; font-weight: 600; }
.stat-chip .lbl { font-size: 10.5px; color: var(--text-dim); }

.btn-primary, .btn-ghost {
  width: 100%; margin-top: 14px; border-radius: 16px; padding: 15px 18px; font-size: 15px;
  font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; border: none; font-family: inherit;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), #8f7bd8); color: #1a1440; }
.btn-ghost { background: var(--card2); color: var(--text); border: 1px solid var(--border); font-weight: 600; font-size: 13.5px; padding: 12px 16px; }
.btn-danger { border-color: var(--accent2); color: var(--accent2); }

.row-card {
  width: 100%; background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; margin-bottom: 8px; color: var(--text); font-family: inherit;
}
.row-card .rc-title { font-size: 13.5px; font-weight: 600; }
.row-card .rc-sub { font-size: 11.5px; color: var(--text-dim); }
.row-card .rc-score { font-family: 'IBM Plex Mono', monospace; font-size: 16px; font-weight: 600; }

.pill { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--card2); color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit; }
.pill.active { border-color: var(--accent); background: rgba(185,166,240,0.18); color: var(--accent); }

.icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.15em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

nav.bottomnav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 460px;
  background: rgba(18,24,58,0.92); backdrop-filter: blur(10px); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 10px 6px 14px; z-index: 40;
}
nav.bottomnav button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: none;
  color: var(--text-dim); padding: 4px 10px; cursor: pointer; font-family: inherit; font-size: 10.5px;
}
nav.bottomnav button.active { color: var(--accent); font-weight: 600; }

.field-label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px; }
input[type="time"], textarea {
  width: 100%; background: var(--card2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; color: var(--text); font-family: inherit; font-size: 14px;
}
textarea { resize: none; }

.toggle { width: 44px; height: 26px; border-radius: 13px; border: none; position: relative; cursor: pointer; flex-shrink: 0; background: var(--border); }
.toggle.on { background: var(--accent); }
.toggle .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: #fff; transition: left .15s; }
.toggle.on .knob { left: 21px; }

.level-bar { height: 8px; border-radius: 4px; background: var(--card2); overflow: hidden; }
.level-bar .fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .2s; }

.score-ring text { font-family: 'IBM Plex Mono', monospace; }

.noise-row { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.noise-row:last-child { border-bottom: none; }
.noise-dot { width: 9px; height: 9px; border-radius: 5px; flex-shrink: 0; }

.alarm-overlay {
  position: fixed; inset: 0; background: rgba(11,16,38,0.97); z-index: 100; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 30px; text-align: center;
}

.ambient-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.ambient-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 10px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--card2); cursor: pointer; color: var(--text);
  font-family: inherit;
}
.ambient-btn.active { border-color: var(--accent); background: rgba(185,166,240,0.14); color: var(--accent); }

.routine-row { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); background: none; border-left: none; border-right: none; border-top: none; cursor: pointer; color: var(--text); text-align: left; font-family: inherit; font-size: 13.5px; }
.routine-row:last-child { border-bottom: none; }
.routine-check { width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.routine-check.checked { background: var(--good); border-color: var(--good); }

.melody-row { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.melody-row:last-child { border-bottom: none; }
.melody-pick { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: none; cursor: pointer; color: var(--text); text-align: left; font-family: inherit; font-size: 13.5px; }
.radio-dot { width: 18px; height: 18px; border-radius: 9px; border: 2px solid var(--border); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.radio-dot.checked { border-color: var(--accent); }
.radio-dot.checked::after { content: ""; width: 9px; height: 9px; border-radius: 5px; background: var(--accent); }
.icon-btn { background: var(--card2); border: none; border-radius: 9px; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--accent); cursor: pointer; }

.empty-state { text-align: center; color: var(--text-dim); font-size: 13px; padding: 22px; }

.install-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; width: calc(100% - 40px); max-width: 420px;
  background: var(--card2); border: 1px solid var(--accent); border-radius: 16px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.install-banner button.close { background: none; border: none; color: var(--text-dim); cursor: pointer; margin-left: auto; }
