/* SleepWave: calm night palette, mobile first, large touch targets. */
:root {
  --bg: #0b1020;
  --bg-2: #0f1630;
  --surface: #151c38;
  --surface-2: #1c2547;
  --line: #27315a;
  --text: #e8ebf7;
  --muted: #98a1c4;
  --accent: #9fb1ff;
  --accent-strong: #7f94f5;
  --accent-ink: #0b1020;
  --moon: #f3dfae;
  --ok: #8fd6b0;
  --warn: #f1c27d;
  --danger: #f0929b;
  --radius: 16px;
  --radius-sm: 12px;
  --tap: 48px;
  --tabbar-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -200px, #1a2350 0%, var(--bg) 60%) no-repeat, var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }

/* Layout */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) 8px calc(var(--safe-left) + 16px);
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; font-size: 18px; }
.brand-moon {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--moon);
  box-shadow: inset -7px -3px 0 0 var(--bg);
}
.view {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 8px calc(var(--safe-right) + 16px) calc(var(--tabbar-h) + var(--safe-bottom) + 32px) calc(var(--safe-left) + 16px);
  outline: none;
}
.view.no-tabbar { padding-bottom: calc(var(--safe-bottom) + 32px); }
.view > section { animation: fade-in .25s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Typography */
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; font-weight: 700; }
h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.page-title { margin: 8px 0 16px; }
.disclaimer { color: var(--muted); font-size: 12.5px; margin-top: 20px; }

/* Layout helpers */
.stack > * + * { margin-top: 12px; }
.stack-lg > * + * { margin-top: 20px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Cards */
.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* Buttons */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, transform .05s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 40px; padding: 6px 14px; font-size: 14px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.view:focus, .view:focus-visible { outline: none; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field > .label, label.label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input, input[type="text"], input[type="email"], input[type="number"], input[type="time"], input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #6a7399; }
.code-input { text-align: center; font-size: 28px; letter-spacing: .5em; padding-left: calc(14px + .5em); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; height: var(--tap); accent-color: var(--accent); background: transparent; }
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 12px; min-height: var(--tap); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Segmented choices (1-5 scales etc.) */
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg > button, .seg > label {
  flex: 1 1 0; min-width: 48px; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.seg > [aria-pressed="true"], .seg > .on, .seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }

/* Chips and badges */
.chip, .badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.badge-ok { color: var(--ok); border-color: #2f5a47; }
.badge-warn { color: var(--warn); border-color: #5f4a28; }
.badge-accent { color: var(--accent); border-color: #3b4a8d; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 10px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-all; }

.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); object-fit: cover; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 22px; color: var(--moon); }

/* Notices */
.notice { border-radius: var(--radius-sm); padding: 12px 14px; border: 1px solid var(--line); background: var(--bg); font-size: 14px; }
.notice-error { border-color: #6a3340; color: var(--danger); }
.notice-info { border-color: #3b4a8d; color: var(--accent); }
.notice-warn { border-color: #5f4a28; color: var(--warn); }
.dev-code { text-align: center; font-size: 22px; letter-spacing: .3em; font-weight: 700; color: var(--moon); }

/* Install banner */
.banner-slot { max-width: 640px; width: 100%; margin: 0 auto; padding: 0 calc(var(--safe-right) + 16px) 0 calc(var(--safe-left) + 16px); }
.banner {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid #3b4a8d; border-radius: var(--radius);
  padding: 12px 14px; margin: 4px 0 8px; font-size: 14px;
}
.banner .grow { line-height: 1.4; }
.banner-close { appearance: none; background: transparent; border: 0; color: var(--muted); font-size: 22px; min-width: 40px; min-height: 40px; cursor: pointer; }
.steps { padding-left: 20px; margin: 8px 0 0; }
.steps li { margin: 6px 0; }

/* Provider buttons */
.provider { justify-content: flex-start; padding-left: 20px; border-radius: var(--radius-sm); }
.provider .mark { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; }
.provider-google .mark { background: #fff; color: #4285f4; }
.provider-kakao .mark { background: #fee500; color: #191919; }
.provider-naver .mark { background: #03c75a; color: #fff; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.login-hero { text-align: center; padding: 28px 0 20px; }
.login-hero .moon { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 16px; background: var(--moon); box-shadow: inset -22px -10px 0 0 var(--bg), 0 0 40px rgba(243,223,174,.18); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: rgba(11, 16, 32, .94);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.tabbar-inner { display: flex; width: 100%; max-width: 640px; }
.tab {
  flex: 1 1 0; min-width: 0; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
  padding: 6px 2px;
}
.tab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab[aria-current="page"] { color: var(--accent); }

/* Toasts */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 50;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 0 16px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  max-width: 520px; width: fit-content;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 16px; box-shadow: 0 8px 28px rgba(0,0,0,.45);
  animation: fade-in .2s ease both;
}
.toast-success { border-color: #2f5a47; }
.toast-error { border-color: #6a3340; }
.toast button { appearance: none; border: 0; background: transparent; color: var(--accent); font: inherit; font-weight: 700; min-height: 40px; padding: 0 8px; cursor: pointer; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 48px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media (min-width: 700px) {
  .view { padding-top: 16px; }
  .tabbar { position: sticky; }
}

/* In-page confirmation (replaces native confirm/alert) */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(3, 5, 12, .72);
}
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 16px 48px rgba(0,0,0,.55);
}
.modal p { margin-bottom: 16px; line-height: 1.6; }

/* Disclosure used for "직접 조절" and privacy details */
details.disclosure { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, var(--surface) 0%, var(--bg-2) 100%); }
details.disclosure > summary {
  list-style: none; cursor: pointer; min-height: var(--tap);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; font-weight: 600;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: "+"; color: var(--muted); font-size: 20px; }
details.disclosure[open] > summary::after { content: "\2212"; }
details.disclosure > .disclosure-body { padding: 0 16px 16px; }

/* One-tap questions */
.question { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
.question legend { padding: 0; margin-bottom: 8px; font-weight: 600; line-height: 1.4; }
.choices { display: grid; gap: 8px; }
.choice {
  min-height: 52px; padding: 8px 6px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600; line-height: 1.25; cursor: pointer; touch-action: manipulation;
}
.choice[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.choice:hover { border-color: var(--accent); }
.choices.five { grid-template-columns: repeat(5, 1fr) !important; }
.choices.five .choice { font-size: 17px; }

/* Today */
.today { display: flex; flex-direction: column; gap: 20px; padding-top: 4px; }
.today-hero { text-align: center; padding: 12px 0 0; }
.today-hero h1 { font-size: 26px; line-height: 1.35; margin: 0 0 8px; }
.today-hero .sub { color: var(--muted); margin: 0 0 20px; font-size: 15px; }
.play-big {
  display: flex; width: 100%; min-height: 76px; align-items: center; justify-content: center; gap: 12px;
  border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink);
  font: inherit; font-size: 22px; font-weight: 800; cursor: pointer; touch-action: manipulation;
  box-shadow: 0 10px 36px rgba(159, 177, 255, .22);
}
.play-big:active { transform: scale(.985); }
.play-big:disabled { opacity: .6; }
.play-big svg { width: 26px; height: 26px; fill: currentColor; }
.safety { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 14px 0 0; text-align: center; }
.player { text-align: center; }
.player .time { font-size: 56px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; line-height: 1.1; margin: 4px 0; }
.player .now { color: var(--muted); margin-bottom: 12px; }
.player .now b { color: var(--text); }
.vol { display: block; text-align: left; margin: 12px 0; }
.vol .label { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.entry { padding: 12px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .when { font-weight: 700; }
.stars { color: var(--moon); letter-spacing: 2px; }
