:root {
  --bg: #f2f2f5;
  --card: #ffffff;
  --ink: #111114;
  --muted: #6b6e76;
  --track: #e2e2e8;
  --line: #e4e4ea;
  --yes: #1fb45a;
  --yes-top: #34d274;
  --yes-bottom: #14954a;
  --no: #e5383b;
  --no-top: #f5585b;
  --no-bottom: #c21f24;
  --abstain: #8a8f98;
  --abstain-top: #a3a8b0;
  --abstain-bottom: #6c717a;
  --orange: #ff9500;
  --blue: #0a84ff;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0f;
    --card: #1c1c22;
    --ink: #f5f5f7;
    --muted: #a1a3aa;
    --track: #26262e;
    --line: #2a2a32;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* ---------- Main screen ---------- */
#ask {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 8px) 20px calc(env(safe-area-inset-bottom) + 14px);
}
.top { display: flex; justify-content: space-between; align-items: center; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); font-size: 24px; border-radius: 22px; }
.icon-btn:active { background: var(--track); }

.question { display: flex; flex-direction: column; gap: 8px; }
#question {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: var(--card);
  color: var(--ink);
  border-radius: 24px;
  padding: 18px 16px;
  font: 700 22px/1.25 var(--font);
  text-align: center;
  overflow: hidden;
}
#question::placeholder { color: var(--muted); opacity: .6; }
#question:disabled { opacity: 1; -webkit-text-fill-color: var(--ink); }
.hint { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

.clock { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.ring { position: relative; width: min(236px, 62vw); aspect-ratio: 1; border-radius: 50%; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 16; }
.ring .track { stroke: var(--track); }
.ring .progress { stroke: var(--ink); stroke-linecap: round; transition: stroke .3s; }
.ring.idle .progress { opacity: .85; }
.ring.warn .progress { stroke: var(--orange); }
.ring.danger .progress { stroke: var(--no); }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.time { direction: ltr; unicode-bidi: isolate; font-size: clamp(52px, 17vw, 68px); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.ring.danger .time { color: var(--no); }
.caption { font-size: 15px; font-weight: 500; color: var(--muted); }

.pill {
  min-width: 200px;
  min-height: 52px;
  padding: 0 28px;
  border-radius: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 700;
}
.pill svg { font-size: 15px; }
.pill.primary { background: var(--ink); color: var(--bg); }
.pill.secondary { background: var(--card); color: var(--muted); }
.pill:active { transform: scale(.97); }

.answers { display: flex; gap: 12px; height: 172px; }
.answer {
  flex: 1;
  border-radius: 34px;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1.5px solid rgba(255,255,255,.25);
  transition: transform .15s, box-shadow .15s, filter .15s;
  padding: 0 6px;
}
.answer svg { font-size: 44px; stroke-width: 3.2; }
.answer span { font-size: 30px; font-weight: 900; letter-spacing: .5px; }
.answer.yes { background: linear-gradient(var(--yes-top), var(--yes-bottom)); box-shadow: 0 8px 16px rgba(31,180,90,.45); }
.answer.no { background: linear-gradient(var(--no-top), var(--no-bottom)); box-shadow: 0 8px 16px rgba(229,56,59,.45); }
.answer.abstain { flex: 0 0 104px; background: linear-gradient(var(--abstain-top), var(--abstain-bottom)); box-shadow: 0 8px 16px rgba(138,143,152,.45); }
.answer.abstain svg { font-size: 30px; }
.answer.abstain span { font-size: 15px; text-align: center; }
.answer:active { transform: scale(.95); filter: brightness(.94); box-shadow: none; }

/* ---------- Result ---------- */
.result {
  position: fixed; inset: 0; z-index: 10;
  color: #fff;
  display: flex; justify-content: center;
  animation: pop .35s ease-out;
}
.result.yes { background: linear-gradient(var(--yes-top), var(--yes-bottom)); }
.result.no { background: linear-gradient(var(--no-top), var(--no-bottom)); }
.result.abstain { background: linear-gradient(var(--abstain-top), var(--abstain-bottom)); }
.result-inner {
  width: 100%; max-width: 460px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top) + 24px) 28px calc(env(safe-area-inset-bottom) + 20px);
}
.result-icon {
  margin-top: auto;
  width: 168px; height: 168px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center; font-size: 92px;
  animation: bounce .5s cubic-bezier(.3,1.6,.5,1);
}
.result-icon svg { stroke-width: 3.4; }
.result h1 { font-size: clamp(40px, 15vw, 64px); font-weight: 900; margin: 22px 0 0; letter-spacing: 1px; }
.result-question { font-size: 20px; font-weight: 600; opacity: .92; margin: 16px 0 0; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.result-detail { font-size: 17px; font-weight: 600; opacity: .9; margin: 18px 0 0; }
.result-note { font-size: 15px; opacity: .85; margin: 6px 0 0; }
.result-actions { margin-top: auto; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pill.light { width: 100%; background: #fff; }
.result.yes .pill.light { color: var(--yes); }
.result.no .pill.light { color: var(--no); }
.result.abstain .pill.light { color: var(--abstain); }
.link-btn { display: inline-flex; gap: 6px; align-items: center; font-size: 15px; font-weight: 600; color: #fff; padding: 6px; }
@keyframes pop { from { opacity: 0; transform: scale(1.06); } to { opacity: 1; transform: none; } }
@keyframes bounce { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg);
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 10px) max(16px, calc((100vw - 460px) / 2)) calc(env(safe-area-inset-bottom) + 24px);
  animation: slide .25s ease-out;
}
@keyframes slide { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-bar { display: flex; justify-content: space-between; align-items: center; min-height: 44px; }
.text-btn { font-size: 17px; color: var(--blue); padding: 8px 4px; }
.text-btn.strong { font-weight: 700; }
.text-btn.danger { color: var(--no); font-weight: 700; }
.sheet-title { font-size: 34px; font-weight: 800; margin: 6px 0 16px; }
.group { background: var(--card); border-radius: 14px; overflow: hidden; }
.group-title { margin: 22px 0 6px 16px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .3px; }
.row {
  min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; font-size: 17px; width: 100%; text-align: left; color: var(--ink); text-decoration: none;
}
.row + .row { border-top: 1px solid var(--line); }
.row.link { color: var(--yes); }
.muted { color: var(--muted); }
.footnote { margin: 8px 16px 18px; font-size: 13px; color: var(--muted); line-height: 1.4; }
select {
  font: inherit; color: var(--muted); background: transparent; border: 0; text-align: right; padding: 4px;
}
.switch {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px;
  background: var(--track); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s;
}
.switch:checked { background: var(--yes); }
.switch:checked::after { transform: translateX(20px); }

/* History */
.summary { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 18px; }
.summary .big { font-size: 40px; font-weight: 800; }
.summary .big small { font-size: 17px; font-weight: 600; color: var(--muted); margin-left: 8px; }
.bar { display: flex; gap: 3px; height: 12px; margin: 12px 0; }
.bar span { border-radius: 4px; min-width: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 15px; font-weight: 600; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.avg { margin-top: 10px; font-size: 13px; color: var(--muted); }
.day { margin: 18px 0 6px 16px; font-size: 13px; text-transform: uppercase; color: var(--muted); }
.entry { display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 16px; }
.entry + .entry { border-top: 1px solid var(--line); }
.dot { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 15px; }
.dot svg { stroke-width: 3.4; }
.dot.yes { background: linear-gradient(var(--yes-top), var(--yes-bottom)); }
.dot.no { background: linear-gradient(var(--no-top), var(--no-bottom)); }
.dot.abstain { background: linear-gradient(var(--abstain-top), var(--abstain-bottom)); }
.entry-text { flex: 1; min-width: 0; }
.entry-q { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.entry-q.untitled { color: var(--muted); }
.entry-text { cursor: pointer; }
.entry-q.expanded { display: block; -webkit-line-clamp: unset; overflow: visible; }
.entry-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry-verdict { font-weight: 800; font-size: 15px; }
.entry-verdict.yes { color: var(--yes); } .entry-verdict.no { color: var(--no); } .entry-verdict.abstain { color: var(--abstain); }
.del { color: var(--muted); font-size: 18px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 18px; }
.del:active { background: var(--track); }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty strong { display: block; color: var(--ink); font-size: 20px; margin-bottom: 6px; }
.history-actions { display: flex; justify-content: center; margin-top: 22px; }

/* Onboarding */
.onboarding .onb-inner { max-width: 420px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 24px 12px; }
.onb-icon { width: 104px; height: 104px; border-radius: 24px; margin-top: auto; }
.onboarding h2 { font-size: 34px; font-weight: 800; margin: 24px 0 8px; }
.onb-sub { font-size: 19px; color: var(--muted); margin: 0; }
.steps { list-style: none; padding: 0; margin: 30px 0; text-align: left; display: flex; flex-direction: column; gap: 22px; }
.steps li { display: flex; gap: 16px; align-items: flex-start; }
.steps p { margin: 3px 0 0; color: var(--muted); font-size: 15px; }
.step-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; margin-top: 5px; }
.step-dot.blue { background: var(--blue); } .step-dot.green { background: var(--yes); } .step-dot.red { background: var(--no); }
.pill.go { width: 100%; margin-top: auto; background: linear-gradient(var(--yes-top), var(--yes-bottom)); color: #fff; }

/* Confirm modal */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 24px; }
.modal-card { background: var(--card); border-radius: 18px; padding: 20px; max-width: 320px; width: 100%; text-align: center; }
.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-card p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.modal-actions { display: flex; justify-content: space-around; }

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