:root {
  --bg: #0b1020;
  --surface: #141a2e;
  --surface-2: #1c2440;
  --line: #262f50;
  --text: #e8ebf7;
  --muted: #8e97b8;
  --faint: #5d6688;
  --accent: #9aa7ff;
  --accent-ink: #0b1020;
  --moon: #f2c46d;
  --good: #5fd3a0;
  --bad: #ff7a8a;
  --half: #f2c46d;
  --radius: 16px;
  --tabbar: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

#app { max-width: 480px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 24px); }
.boot { display: grid; place-items: center; height: 60dvh; font-size: 48px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; }
.top h1 { font-size: 20px; margin: 0; letter-spacing: .2px; }
.top h1 span { color: var(--moon); }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; color: var(--muted);
}
.offline { color: var(--half); font-size: 12px; margin-left: 8px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 0 0 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); font-size: 12px; }

.plan { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.plan .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan .v.target { color: var(--moon); }
.plan .k { font-size: 12px; color: var(--muted); }

/* ---------- check-in ---------- */
.checkin { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.big {
  border: 1.5px solid var(--line); background: var(--surface-2); border-radius: 14px;
  padding: 16px 10px; font-size: 16px; font-weight: 600; min-height: 64px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.big:active { transform: scale(.97); }
.big .ico { display: block; font-size: 22px; margin-bottom: 2px; }
.big.hit.on { background: color-mix(in srgb, var(--good) 22%, var(--surface-2)); border-color: var(--good); }
.big.miss.on { background: color-mix(in srgb, var(--bad) 18%, var(--surface-2)); border-color: var(--bad); }

.people { display: grid; gap: 8px; margin: 14px 0 4px; }
.person { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; }
.person .who { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.hit { background: var(--good); }
.dot.miss { background: var(--bad); }
.status { color: var(--muted); font-size: 14px; }
.status.hit { color: var(--good); }
.status.miss { color: var(--bad); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.verdict { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 14px; color: var(--muted); }
.verdict.both { color: var(--good); }
.verdict.none, .verdict.half { color: var(--half); }

details.more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.more summary { color: var(--muted); font-size: 14px; list-style: none; cursor: pointer; padding: 4px 0; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before { content: '＋ '; }
details.more[open] summary::before { content: '－ '; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row label, .row .lbl { font-size: 15px; }
.row .sub { display: block; font-size: 12px; color: var(--faint); }

/* toggle switch */
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 2px; top: 2px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + span { background: color-mix(in srgb, var(--accent) 35%, var(--surface-2)); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=time], input[type=number], input[type=password] {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px;
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.note { margin-top: 8px; }

/* ---------- week ---------- */
.progress { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.progress .score { font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.progress .of { color: var(--muted); }
.progress .badge { margin-left: auto; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 14px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.bar.met > i { background: var(--good); }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; border-radius: 12px; background: var(--surface-2); border: 1.5px solid transparent;
  min-height: 70px; position: relative;
}
button.day { border-color: transparent; }
.day.today { border-color: var(--accent); }
.day .dn { font-size: 11px; color: var(--muted); }
.day .dd { font-size: 12px; color: var(--faint); }
.day .sym { font-size: 20px; font-weight: 700; line-height: 1.2; }
.day.both .sym { color: var(--good); }
.day.half .sym { color: var(--half); }
.day.none .sym { color: var(--bad); }
.day.pending .sym, .day.future .sym { color: var(--faint); }
.day.future { opacity: .45; }
.day .x2 { position: absolute; top: -6px; right: -2px; font-size: 10px; background: var(--moon); color: var(--accent-ink); border-radius: 6px; padding: 0 4px; font-weight: 700; }
.legend { display: flex; gap: 12px; justify-content: center; font-size: 12px; color: var(--faint); margin-top: 10px; flex-wrap: wrap; }

.badge { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge.met { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.badge.notmet { background: var(--surface-2); color: var(--muted); }
.badge.live { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.reward { margin-top: 12px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--moon) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--moon) 40%, transparent); color: var(--moon); font-weight: 600; }
.streak { margin-top: 10px; color: var(--muted); font-size: 14px; }

.weeknav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.weeknav .range { font-weight: 600; }
.iconbtn { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 44px; height: 44px; font-size: 18px; }
.iconbtn:disabled { opacity: .3; }

.nightlist { display: grid; gap: 0; }
.nightrow { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; width: 100%; }
.nightrow:first-child { border-top: 0; }
.nightrow .d { font-size: 13px; color: var(--muted); }
.nightrow .d b { display: block; color: var(--text); font-size: 15px; }
.nightrow .who { font-size: 14px; }
.nightrow .meta { font-size: 12px; color: var(--faint); }
.nightrow .sym { font-size: 20px; font-weight: 700; width: 28px; text-align: center; }
.nightrow .sym.both { color: var(--good); } .nightrow .sym.half { color: var(--half); } .nightrow .sym.none { color: var(--bad); } .nightrow .sym.pending { color: var(--faint); }

/* ---------- history ---------- */
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--faint); font-size: 10px; }
.chart .barr { fill: var(--accent); }
.chart .barr.notmet { fill: var(--faint); }
.chart .goal { stroke: var(--moon); stroke-width: 2; stroke-linecap: round; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .sel { fill: color-mix(in srgb, var(--accent) 12%, transparent); }
.chart-tip { min-height: 22px; font-size: 13px; color: var(--muted); margin-top: 8px; text-align: center; }
.chart-key { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.chart-key i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }

.weekrow { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.weekrow:first-child { border-top: 0; }
.weekrow .r { font-weight: 600; }
.weekrow .m { font-size: 12px; color: var(--faint); }
.weekrow .s { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 12px 16px; font-weight: 600; min-height: 48px; width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.nudge { font-size: 17px; }
.btn:disabled { opacity: .5; }
.btns { display: grid; gap: 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.hint b { color: var(--text); }
.err { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* ---------- gate ---------- */
.gate { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.gate .moon { font-size: 56px; text-align: center; }
.gate h1 { text-align: center; margin: 0; }
.gate p { text-align: center; color: var(--muted); margin: 0; }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pick .big { font-size: 20px; padding: 28px 10px; }

/* ---------- tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border: 0; height: var(--tabbar); color: var(--faint); font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabs button .i { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--text); }
.tabs button.on .i { filter: none; opacity: 1; }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .55); z-index: 20; animation: fade .15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 480px; margin: 0 auto;
  background: var(--surface); border-top-left-radius: 20px; border-top-right-radius: 20px; border: 1px solid var(--line);
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px); max-height: 88dvh; overflow-y: auto;
  animation: up .2s ease;
}
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 4px; margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
