/* ============ Design Tokens ============ */
:root {
  color-scheme: dark;
  --bg: #0d0b1a;
  --bg-2: #15122a;
  --ink: #f6f2ff;
  --muted: #a39dc2;
  --line: rgba(255, 255, 255, .12);

  --coral: #ff6b5e;
  --coral-soft: #fff0ed;
  --violet: #7b5cff;
  --violet-soft: #f1edff;
  --mint: #3ee0b5;

  --card: #fffaf3;
  --card-ink: #1b1630;
  --card-muted: #8a84a3;

  --grad: linear-gradient(135deg, var(--violet) 0%, #c45cf0 50%, var(--coral) 100%);
  --radius-card: 28px;
  --shadow-card: 0 30px 60px -20px rgba(0, 0, 0, .65), 0 10px 25px -10px rgba(60, 30, 140, .5);

  --font-display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;

  --card-w: min(84vw, 360px, calc((100dvh - 280px) * .714));
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* ============ Ambient background ============ */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; }
.bg::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 0%, var(--bg) 75%);
}
.blob {
  position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%;
  filter: blur(80px); opacity: .35; animation: drift 22s ease-in-out infinite alternate;
}
.b1 { background: var(--violet); top: -25vmax; left: -15vmax; }
.b2 { background: var(--coral); bottom: -30vmax; right: -20vmax; animation-delay: -7s; }
.b3 { background: #2bb3c0; top: 30%; left: 40%; width: 35vmax; height: 35vmax; opacity: .18; animation-delay: -14s; }
@keyframes drift {
  to { transform: translate(6vmax, 4vmax) scale(1.1); }
}

/* ============ Layout ============ */
.app {
  position: relative; z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 560px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  display: grid; place-items: center;
  width: 34px; height: 40px; border-radius: 10px;
  background: var(--grad);
  font-family: var(--font-display); font-weight: 800; font-size: 22px;
  box-shadow: 0 6px 20px -6px rgba(123, 92, 255, .8);
  transform: rotate(-6deg);
}
.brand-text { font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: -.01em; }
.brand-text em {
  font-style: normal;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  transition: background .2s, transform .2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }
.icon-btn:active { transform: scale(.94); }

/* ============ Stage / deck ============ */
.stage {
  position: relative;
  display: grid; place-items: center;
  perspective: 1400px;
  min-height: 0;
}
.stage > * { grid-area: 1 / 1; }

.deck { position: relative; width: var(--card-w); aspect-ratio: 5 / 7; }
.deck-card {
  position: absolute; inset: 0;
  border-radius: var(--radius-card);
  transition: transform .4s cubic-bezier(.2, .8, .2, 1), opacity .3s;
}
.deck-card .face.back { position: absolute; inset: 0; transform: none; }

/* Card */
.card {
  position: relative;
  width: var(--card-w); aspect-ratio: 5 / 7;
  z-index: 5;
}
.card-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transition: transform .75s cubic-bezier(.3, 1.3, .4, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card.drawing { animation: lift .75s cubic-bezier(.3, .9, .3, 1); }
@keyframes lift {
  0%   { transform: translateY(0) scale(1); }
  45%  { transform: translateY(-28px) scale(1.06); }
  100% { transform: translateY(0) scale(1); }
}
.card { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.card:not(.dragging):not(.leaving) { transition: transform .35s cubic-bezier(.3, 1.4, .5, 1); }
.card.dragging { cursor: grabbing; }
.card.leaving { pointer-events: none; animation: leave-up .5s cubic-bezier(.5, 0, .75, 0) forwards; }
.card.leaving.to-a { animation-name: leave-left; }
.card.leaving.to-b { animation-name: leave-right; }
@keyframes leave-left  { to { transform: translate(-130%, -6%) rotate(-22deg); opacity: 0; } }
@keyframes leave-right { to { transform: translate(130%, -6%) rotate(22deg); opacity: 0; } }
@keyframes leave-up    { to { transform: translateY(-120%) rotate(-4deg) scale(.9); opacity: 0; } }

.face {
  position: absolute; inset: 0;
  border-radius: var(--radius-card);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Back side */
.face.back {
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,.28), transparent 40%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 2px, transparent 2px 16px),
    var(--grad);
  display: grid; place-items: center; align-content: center; gap: 18px;
  border: 1px solid rgba(255, 255, 255, .25);
}
.face.back::before {
  content: ""; position: absolute; inset: 12px;
  border-radius: calc(var(--radius-card) - 10px);
  border: 1.5px dashed rgba(255, 255, 255, .35);
}
.back-ring {
  width: 44%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .14);
  border: 2px solid rgba(255, 255, 255, .55);
  backdrop-filter: blur(4px);
}
.back-ring span {
  font-family: var(--font-display); font-weight: 800;
  font-size: calc(var(--card-w) * .26); line-height: 1;
  text-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.back-label {
  font-family: var(--font-display); font-weight: 700;
  text-transform: uppercase; letter-spacing: .22em; font-size: 11px; opacity: .9;
}

/* Front side */
.face.front {
  transform: rotateY(180deg);
  background: var(--card);
  color: var(--card-ink);
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
  padding: 26px 20px;
}
.eyebrow {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(20px, calc(var(--card-w) * .075), 27px);
  letter-spacing: -.02em; text-align: center; margin-bottom: 8px;
}
.opt {
  position: relative; text-align: left;
  display: flex; align-items: center; gap: 12px;
  padding: 16px 16px; border-radius: 20px;
  font-size: clamp(15px, calc(var(--card-w) * .048), 18px); font-weight: 600; line-height: 1.3;
  color: var(--card-ink);
  border: 2px solid transparent;
  transition: transform .25s cubic-bezier(.3, 1.5, .5, 1), background .25s, color .25s, box-shadow .25s, opacity .25s;
  flex: 1 1 0; min-height: 0;
}
.opt-a { background: var(--coral-soft); border-color: rgba(255, 107, 94, .35); }
.opt-b { background: var(--violet-soft); border-color: rgba(123, 92, 255, .35); }
.opt:hover { transform: translateY(-2px); }
.opt:active { transform: scale(.98); }
.tag {
  flex: none; width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 15px; color: #fff;
}
.opt-a .tag { background: var(--coral); }
.opt-b .tag { background: var(--violet); }

.opt.chosen { color: #fff; transform: scale(1.03); }
.opt-a.chosen { background: var(--coral); box-shadow: 0 12px 28px -10px var(--coral); }
.opt-b.chosen { background: var(--violet); box-shadow: 0 12px 28px -10px var(--violet); }
.opt.chosen .tag { background: rgba(255, 255, 255, .25); }
.opt.dimmed { opacity: .45; }

.or {
  align-self: center;
  font-family: var(--font-display); font-weight: 800; text-transform: uppercase;
  font-size: 12px; letter-spacing: .25em; color: var(--card-muted);
  padding: 4px 12px; border-radius: 99px; background: #efe9df;
}
.badge {
  position: absolute; top: 14px; right: 14px;
  font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 99px; background: #e5fbf4; color: #128a69;
}

/* Empty state */
.empty { text-align: center; z-index: 2; }
.empty-title { font-family: var(--font-display); font-weight: 800; font-size: 32px; margin: 0 0 6px; }
.empty-sub { color: var(--muted); margin: 0; }

/* ============ Controls ============ */
.controls { display: grid; justify-items: center; gap: 12px; padding-top: 18px; }
.counter { margin: 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-width: min(100%, 300px); height: 58px; padding: 0 28px; border-radius: 99px;
  background: var(--grad); background-size: 150% 150%;
  font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -.01em; color: #fff;
  box-shadow: 0 14px 34px -12px rgba(196, 92, 240, .9), inset 0 1px 0 rgba(255, 255, 255, .35);
  transition: transform .2s, box-shadow .2s, background-position .4s;
}
.primary:hover { background-position: 100% 0; transform: translateY(-1px); }
.primary:active { transform: scale(.97); }
.primary:disabled { opacity: .6; cursor: default; }
.ghost {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 99px;
  color: var(--muted); font-size: 14px; font-weight: 500;
  border: 1px solid transparent;
  transition: color .2s, border-color .2s;
}
.ghost:hover { color: var(--ink); border-color: var(--line); }
:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }

/* ============ Sheet (add question) ============ */
.sheet {
  width: min(100%, 480px); max-width: 100%;
  margin: auto auto 0; padding: 0;
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: 28px 28px 0 0;
  background: var(--bg-2); color: var(--ink);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
}
.sheet[open] { animation: sheet-in .35s cubic-bezier(.2, .9, .3, 1); }
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet::backdrop { background: rgba(5, 4, 12, .6); backdrop-filter: blur(6px); }
.sheet form { padding: 12px 20px max(24px, env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.sheet-handle { width: 40px; height: 5px; border-radius: 99px; background: var(--line); justify-self: center; margin-bottom: 6px; }
.sheet h2 { margin: 0; font-family: var(--font-display); font-size: 24px; letter-spacing: -.02em; }
.sheet-sub { margin: 0 0 6px; color: var(--muted); }
.field { display: grid; gap: 6px; }
.field span { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.field-a span { color: var(--coral); }
.field-b span { color: #a48dff; }
.field textarea {
  width: 100%; resize: none;
  padding: 12px 14px; border-radius: 16px;
  background: rgba(255, 255, 255, .05); border: 1.5px solid var(--line); color: var(--ink);
  font: 500 16px/1.35 var(--font-body);
  transition: border-color .2s, background .2s;
}
.field-a textarea:focus { border-color: var(--coral); outline: none; background: rgba(255, 107, 94, .06); }
.field-b textarea:focus { border-color: var(--violet); outline: none; background: rgba(123, 92, 255, .08); }
.sheet-or { justify-self: center; font-family: var(--font-display); font-weight: 800; font-size: 12px; letter-spacing: .25em; text-transform: uppercase; color: var(--muted); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.sheet-actions .primary { min-width: 0; height: 50px; font-size: 16px; }
.sheet-actions .spacer { flex: 1; }
.link-btn {
  color: var(--muted); font-size: 14px; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line);
  padding: 8px 0;
}
.link-btn:hover { color: var(--ink); }

.sheet-body { padding: 12px 20px max(24px, env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.q-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 8px;
  max-height: min(55dvh, 460px); overflow-y: auto; overscroll-behavior: contain;
}
.q-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 12px 14px; border-radius: 16px;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line);
}
.q-text { flex: 1; display: grid; gap: 2px; font-size: 14px; line-height: 1.35; min-width: 0; }
.q-a { color: #ffb2aa; }
.q-b { color: #c7b9ff; }
.q-or { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.q-del {
  flex: none; width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; color: var(--muted);
  transition: background .2s, color .2s;
}
.q-del:hover { background: rgba(255, 107, 94, .15); color: var(--coral); }
.q-del:disabled { opacity: .4; }
.q-empty { color: var(--muted); margin: 8px 0; }

@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: 28px; border-bottom: 1px solid var(--line); }
  @keyframes sheet-in { from { transform: translateY(20px) scale(.97); opacity: 0; } }
}

/* ============ Toast ============ */
.toast {
  display: none;
  position: fixed; inset: auto; left: 50%; top: max(20px, env(safe-area-inset-top)); z-index: 20;
  margin: 0; max-width: calc(100vw - 32px); width: max-content;
  transform: translate(-50%, 0);
  padding: 10px 18px; border-radius: 99px;
  background: rgba(30, 26, 55, .95); color: var(--ink);
  border: 1px solid var(--line); backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  font: 500 14px/1.3 var(--font-body); text-align: center;
}
.toast.show { display: block; animation: toast-in .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes toast-in { from { transform: translate(-50%, -150%); } }

/* ============ Desktop ============ */
@media (min-width: 900px) {
  :root { --card-w: min(380px, calc((100dvh - 290px) * .714)); }
  .brand-text { font-size: 22px; }
}

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