:root {
  color-scheme: light;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: rgba(15, 23, 42, 0.10);
  --line-strong: rgba(15, 23, 42, 0.18);
  --paper: #f5f8ff;
  --panel: #ffffff;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eef4ff;
  --accent-ring: rgba(37, 99, 235, 0.28);
  --sky: #0ea5e9;
  --danger: #c2410c;
  --warn-bg: #fff7ed;
  --radius: 14px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 32px -8px rgba(15, 23, 42, 0.10), 0 40px 80px -24px rgba(37, 99, 235, 0.18);
  --shadow-hover: 0 6px 18px -8px rgba(37, 99, 235, 0.35);
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  background: var(--paper);
  overflow-x: hidden;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- ambient background ---------- */
.backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.backdrop span {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: drift 26s ease-in-out infinite alternate;
}
.backdrop span:nth-child(1) { width: 520px; height: 520px; left: -140px; top: -160px; background: rgba(37, 99, 235, 0.30); }
.backdrop span:nth-child(2) { width: 460px; height: 460px; right: -120px; top: 18%; background: rgba(14, 165, 233, 0.26); animation-duration: 32s; animation-direction: alternate-reverse; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(60px, 80px, 0) scale(1.12); }
}

/* ---------- shell ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 20px;
  padding: 24px 16px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-logo { height: 36px; width: auto; display: block; }
.topbar-actions { display: flex; gap: 8px; }

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease-out), opacity 0.2s;
}
.ghost-button:hover:not(:disabled) { background: #fff; border-color: var(--line-strong); transform: translateY(-1px); }
.ghost-button:active:not(:disabled) { transform: scale(0.97); }
.ghost-button:disabled { opacity: 0.35; cursor: default; }

/* ---------- progress ---------- */
.progress-meta { display: flex; justify-content: space-between; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 8px; }
.progress-percent { font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; background: rgba(37, 99, 235, 0.10); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--sky));
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.45);
  transition: width 0.6s var(--ease-out);
}

/* ---------- card ---------- */
.stage { display: flex; align-items: flex-start; justify-content: center; }

.question-card {
  width: 100%;
  max-width: 760px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow-card);
  padding: clamp(24px, 5vw, 52px);
}

.question-mark:empty { display: none; }

.question-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 6px 12px;
  margin-bottom: 16px;
}
.question-kicker::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.question-card h1 {
  font-size: clamp(22px, 3.2vw, 30px);
  line-height: 1.22;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  font-weight: 700;
  text-wrap: balance;
}
.question-card[data-type="statement"] h1,
.question-card[data-type="complete"] h1 { font-size: clamp(28px, 4.6vw, 42px); letter-spacing: -0.03em; }

.question-help { color: var(--muted); line-height: 1.6; margin: 0 0 24px; max-width: 60ch; text-wrap: pretty; }
.question-help:empty { display: none; }
.question-card[data-type="statement"] .question-help { font-size: 17px; }

.answer-zone { display: grid; gap: 10px; }
.answer-zone:empty { display: none; }
.question-help:empty + .answer-zone { margin-top: 22px; }

/* ---------- choices ---------- */
.choice {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  text-align: left;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  line-height: 1.4;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s, transform 0.18s var(--ease-out);
}
.choice:hover:not(:disabled) { border-color: rgba(37, 99, 235, 0.55); box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.choice:active:not(:disabled) { transform: scale(0.99); }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice:disabled { opacity: 0.4; cursor: not-allowed; }

.choice-key {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: #fff;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.choice[aria-pressed="true"] .choice-key { background: var(--accent); border-color: var(--accent); color: #fff; }

.choice-label strong { display: block; font-weight: 600; color: var(--ink); }
.choice-label span { display: block; margin-top: 2px; font-size: 14px; color: var(--muted); }

.choice-check {
  position: relative;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.2s, transform 0.25s var(--ease-out);
}
.choice-check::after {
  content: "";
  position: absolute;
  left: 7.5px;
  top: 4.5px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.choice[aria-pressed="true"] .choice-check { opacity: 1; transform: none; }

/* 1-5 scale: tiles tint deeper towards "agree" */
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.scale .choice { grid-template-columns: 1fr; justify-items: center; min-height: 64px; padding: 0; font-size: 20px; }
.scale .choice-key, .scale .choice-check { display: none; }
.scale .choice:nth-child(1) { background: #fff; }
.scale .choice:nth-child(2) { background: #f8faff; }
.scale .choice:nth-child(3) { background: #f2f6ff; }
.scale .choice:nth-child(4) { background: #ebf1ff; }
.scale .choice:nth-child(5) { background: #e3ecff; }
.scale .choice[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); box-shadow: 0 10px 24px -10px rgba(37, 99, 235, 0.7); }
.scale .choice[aria-pressed="true"] strong { color: #fff; }
.scale-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

/* ---------- fields ---------- */
.text-field { display: grid; gap: 8px; font-size: 14px; font-weight: 500; color: var(--ink-soft); }
.text-field input, .text-field select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 17px;
  background: #fff;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.text-field select {
  appearance: none;
  padding-right: 44px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 16px center;
  cursor: pointer;
}
.text-field input:hover, .text-field select:hover { border-color: rgba(37, 99, 235, 0.45); }
.text-field input:focus, .text-field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.choice:focus-visible, .primary-button:focus-visible, .ghost-button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }

.multi-note { font-size: 13px; color: var(--muted); margin-top: 2px; }

.meta-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.meta-chip {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 12px;
}

.error-message { color: var(--danger); font-size: 14px; font-weight: 500; min-height: 20px; margin: 14px 0 0; }

/* ---------- controls ---------- */
.control-row { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.primary-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #3b74f0, var(--accent));
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 13px 24px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 10px 24px -10px rgba(37, 99, 235, 0.8);
  transition: transform 0.2s var(--ease-out), box-shadow 0.2s, background 0.2s;
}
.primary-button:hover:not(:disabled) { transform: translateY(-1px); background: linear-gradient(180deg, #2f67e6, var(--accent-dark)); }
.primary-button:active:not(:disabled) { transform: scale(0.97); }
.primary-button:disabled { cursor: wait; }
.button-arrow { display: inline-block; transition: transform 0.25s var(--ease-out); }
.primary-button:hover .button-arrow { transform: translateX(3px); }
.button-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.primary-button.is-busy .button-arrow { display: none; }
.primary-button.is-busy .button-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.enter-hint { font-size: 13px; color: var(--muted); }
.enter-hint kbd {
  font: inherit;
  font-weight: 600;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  background: #fff;
}
.question-card[data-type="complete"] .enter-hint { display: none; }

/* ---------- completion ---------- */
.success-mark { width: 64px; height: 64px; margin-bottom: 20px; }
.success-mark svg { width: 100%; height: 100%; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.success-mark circle { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); stroke-dasharray: 151; }
.success-mark path { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: 36; }
.success-mark.is-animated circle { stroke-dashoffset: 151; animation: draw 0.6s var(--ease-out) 0.15s forwards; }
.success-mark.is-animated path { stroke-dashoffset: 36; animation: draw 0.4s var(--ease-out) 0.6s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.notice { border-radius: var(--radius); padding: 14px 16px; background: var(--accent-soft); line-height: 1.55; font-size: 15px; }
.notice.warn { background: var(--warn-bg); border: 1px solid rgba(194, 65, 12, 0.18); }

.summary { display: grid; gap: 0; margin-top: 4px; }
.summary-item { display: grid; grid-template-columns: 52px 1fr; gap: 10px; font-size: 14px; line-height: 1.5; border-top: 1px solid var(--line); padding: 10px 0; }
.summary-item strong { color: var(--accent); font-weight: 600; }

.footer-note { text-align: center; font-size: 13px; color: var(--muted); }

@media (max-width: 640px) {
  .app-shell { gap: 16px; padding: 16px 16px 24px; }
  .brand-logo { height: 28px; }
  .question-card { border-radius: 20px; }
  .enter-hint { display: none; }
  .choice { gap: 12px; padding: 12px; }
  .scale { gap: 6px; }
  .scale .choice { min-height: 56px; font-size: 18px; }
  .primary-button { flex: 1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .success-mark circle, .success-mark path { stroke-dashoffset: 0 !important; }
}
