@property --spin { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
@view-transition { navigation: auto; }

:root {
  --canvas: #f5f0e8;
  --paper: #fffcf7;
  --ink: #2a2521;
  --ink-2: #6e6359;
  --line: rgba(42, 37, 33, .12);
  --bubble: #ebe2d5;
  --good: #2f7d4f;
  --good-soft: #e3f1e6;
  --bad: #b0442e;
  --bad-soft: #f8e4dd;
  --accent: #d9622b;
  --shadow: rgba(42, 37, 33, .35);
  --backdrop: rgba(42, 37, 33, .35);
  --aura-opacity: .55;
  --noise-opacity: .5;
  --theme-color: #f5f0e8;
  --spectrum: #2f6bff, #17b3a3, #9ad15a, #f5a63c, #ee5f8f, #7a6cf5, #2f6bff;
  --serif: 'Instrument Serif', serif;
  --sans: 'Albert Sans', sans-serif;
  --spring: cubic-bezier(.3, 1.45, .5, 1);
  --out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --canvas: #171411;
  --paper: #221e1a;
  --ink: #f3ece2;
  --ink-2: #a99d90;
  --line: rgba(243, 236, 226, .12);
  --bubble: #2f2924;
  --good: #6cc48d;
  --good-soft: rgba(108, 196, 141, .14);
  --bad: #ef7a5f;
  --bad-soft: rgba(239, 122, 95, .14);
  --accent: #f08a4b;
  --shadow: rgba(0, 0, 0, .7);
  --backdrop: rgba(0, 0, 0, .55);
  --aura-opacity: .2;
  --noise-opacity: .3;
  --theme-color: #171411;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; font-family: var(--sans); color: var(--ink); background: var(--canvas); overflow-x: hidden; transition: background-color .4s, color .4s; }
body::after { content: ''; position: fixed; inset: 0; z-index: 5; pointer-events: none; opacity: var(--noise-opacity); background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.06'/%3E%3C/svg%3E"); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.aura { position: fixed; left: 50%; top: -22vh; z-index: 0; width: min(900px, 140vw); height: 520px; translate: -50% 0; filter: blur(70px); opacity: var(--aura-opacity); pointer-events: none; transition: opacity .4s; }
.aura i { position: absolute; width: 46%; aspect-ratio: 1; border-radius: 50%; background: var(--c); animation: drift 18s ease-in-out infinite alternate; animation-delay: var(--d); }

.orb {
  position: relative; flex: none; display: block;
  width: 30px; height: 30px;
  border-radius: 46% 54% 52% 48% / 50% 46% 54% 50%;
  background: radial-gradient(circle at 32% 26%, rgba(255, 255, 255, .8), transparent 42%), conic-gradient(from var(--spin), var(--spectrum));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35);
  animation: spin 5s linear infinite, morph 6s ease-in-out infinite alternate;
}
.orb-lg { width: 92px; height: 92px; }
.orb-lg::after { content: ''; position: absolute; inset: -35%; z-index: -1; border-radius: 50%; background: conic-gradient(from 90deg, var(--spectrum)); filter: blur(30px); opacity: .45; animation: breathe 4s ease-in-out infinite; }
.is-thinking .orb-lg { animation-duration: 1.4s, 2s; }

/* ---------- Header ---------- */
.top { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; padding: max(1.1rem, env(safe-area-inset-top)) max(1.6rem, env(safe-area-inset-right)) 1.1rem max(1.6rem, env(safe-area-inset-left)); animation: fade .8s both; }
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; letter-spacing: -.01em; text-decoration: none; white-space: nowrap; view-transition-name: brand; }
.brand .orb { width: 26px; height: 26px; }
.switch { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 999px; background: var(--bubble); }
.switch-pill { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px); border-radius: 999px; background: var(--paper); box-shadow: 0 2px 8px rgba(42, 37, 33, .12); view-transition-name: mode-pill; }
.switch a { position: relative; z-index: 1; padding: .5rem 1.3rem; border-radius: 999px; font-weight: 600; font-size: .9rem; color: var(--ink-2); text-align: center; text-decoration: none; white-space: nowrap; transition: color .3s; }
.switch a:hover, .switch a[aria-current="page"] { color: var(--ink); }
.stats { justify-self: end; display: flex; align-items: center; gap: .4rem; }
.stat { padding: .4rem .8rem; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: .85rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat b { color: var(--accent); }
.stat.is-bumped { animation: bump .5s var(--spring); }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--paper); border: 1px solid var(--line); color: var(--ink-2); transition: color .2s, transform .3s var(--spring); }
.icon-btn:hover { color: var(--ink); transform: translateY(-2px); }
.icon-btn svg { width: 18px; height: 18px; }
:root[data-theme="dark"] .icon-moon, :root:not([data-theme="dark"]) .icon-sun { display: none; }

/* ---------- Conversation ---------- */
.quiz { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 1.6rem; max-width: 760px; min-height: calc(100vh - 76px); min-height: calc(100dvh - 76px); margin: 0 auto; padding: 1.5rem max(1.5rem, env(safe-area-inset-right)) 0 max(1.5rem, env(safe-area-inset-left)); }
.intro { isolation: isolate; display: grid; justify-items: center; gap: .9rem; padding: 1.5rem 0 .5rem; text-align: center; animation: rise 1s var(--out) both; }
h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(2.4rem, 6vw, 3.8rem); line-height: 1; letter-spacing: -.01em; text-wrap: balance; }
h1 em { background: linear-gradient(90deg, #2f6bff, #17b3a3 40%, #f5a63c 75%, #ee5f8f); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: .08em; }
.intro p { color: var(--ink-2); font-size: .95rem; }
.thread { display: flex; flex-direction: column; gap: 1.6rem; }

.msg { display: flex; gap: .9rem; align-items: flex-start; }
.msg-main { flex: 1; min-width: 0; }
.ai { --d: .1s; --t1: .25s; --t2: .9s; animation: rise .6s var(--d) var(--out) both; }
.ai > .orb { margin-top: .15rem; }
.typing { display: flex; gap: 5px; padding: .7rem 0; overflow: hidden; animation: fade .3s var(--t1) both, collapse .25s var(--t2) forwards; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); animation: dot 1s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
.ai-body { display: grid; gap: 1rem; padding-bottom: .8rem; font-size: 1.12rem; line-height: 1.6; -webkit-mask: linear-gradient(#000 40%, transparent 60%) 0 100% / 100% 300% no-repeat; mask: linear-gradient(#000 40%, transparent 60%) 0 100% / 100% 300% no-repeat; animation: stream 1.2s var(--t2) ease-out forwards; }
.ai-body b { font-weight: 700; }

.product { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem; border-radius: 20px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 12px 30px -18px var(--shadow); }
.tile { flex: none; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: linear-gradient(140deg, var(--a), var(--b)); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 10px 18px -10px var(--b); }
.tile svg { width: 55%; }
.product-text { min-width: 0; }
.product strong { display: block; font-size: 1.15rem; line-height: 1.3; overflow-wrap: anywhere; }
.product small { color: var(--ink-2); font-size: .88rem; }
.pill { margin-left: auto; padding: .3rem .7rem; border-radius: 999px; background: var(--bubble); font-size: .78rem; font-weight: 600; white-space: nowrap; }

.user { justify-content: flex-end; }
.user p { position: relative; max-width: 78%; padding: .8rem 1.2rem; border-radius: 22px 22px 6px 22px; background: var(--bubble); font-size: 1.08rem; font-weight: 500; overflow-wrap: anywhere; animation: bubble .5s var(--spring) both; }
.user p::after { content: '✕'; position: absolute; left: -10px; top: -10px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--bad); color: #fff; font-size: .75rem; font-weight: 700; animation: badge .5s .6s var(--spring) both; }
.user.is-right p::after { content: '✓'; background: var(--good); }
.reply { --d: .2s; --t1: .3s; --t2: 1s; }

.verdict-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.score-up { display: inline-flex; gap: .5rem; align-items: center; padding: .45rem .9rem; border: 1.5px solid transparent; border-radius: 999px; background: linear-gradient(var(--paper), var(--paper)) padding-box, conic-gradient(from var(--spin), var(--spectrum)) border-box; font-size: .9rem; font-weight: 700; animation: spin 3s linear infinite; }
.game-over { padding: .45rem .9rem; border-radius: 999px; background: var(--bad-soft); color: var(--bad); font-size: .9rem; font-weight: 700; }
.best-badge { padding: .45rem .9rem; border-radius: 999px; background: linear-gradient(110deg, #2f6bff, #17b3a3 45%, #f5a63c 80%, #ee5f8f); color: #fff; font-size: .9rem; font-weight: 700; animation: badge .6s 1.6s var(--spring) both; }
.links { display: flex; flex-wrap: wrap; gap: .5rem; }
.link-chip { display: inline-flex; align-items: center; gap: .45rem; max-width: 100%; padding: .5rem .95rem; border: 1.5px solid var(--line); border-radius: 999px; background: var(--paper); font-size: .88rem; font-weight: 600; line-height: 1.3; text-decoration: none; transition: transform .3s var(--spring), box-shadow .3s; }
.link-chip svg { flex: none; width: 14px; height: 14px; }
.link-chip:hover { border-color: transparent; background: linear-gradient(var(--paper), var(--paper)) padding-box, conic-gradient(from var(--spin), var(--spectrum)) border-box; transform: translateY(-2px); box-shadow: 0 10px 22px -14px var(--shadow); animation: spin 2.5s linear infinite; }
.when { display: inline-flex; align-items: center; gap: .45rem; padding: .5rem .95rem; border-radius: 999px; background: var(--bubble); font-size: .88rem; font-weight: 600; }
.when svg { width: 14px; height: 14px; }

.error-card { display: grid; gap: .8rem; justify-items: start; padding: 1.2rem 1.4rem; border-radius: 20px; background: var(--bad-soft); color: var(--ink); }

/* ---------- Composer ---------- */
.composer { position: sticky; bottom: 0; z-index: 2; margin-top: auto; display: grid; gap: .8rem; padding: 1.5rem 0 max(1.4rem, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--canvas) 28%); }
.suggest-label { font-size: .82rem; font-weight: 600; color: var(--ink-2); animation: fade .5s 1.1s both; }
.chips { display: flex; flex-wrap: wrap; gap: .55rem; }
.chip {
  display: inline-flex; align-items: baseline; gap: .5rem;
  max-width: 100%; padding: .75rem 1.15rem;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--paper);
  font-weight: 600; font-size: 1rem; line-height: 1.3; text-align: left;
  transition: transform .3s var(--spring), box-shadow .3s;
  animation: chip-in .6s var(--spring) both, spin 2.5s linear infinite;
  animation-delay: calc(1.2s + var(--i) * 80ms), 0s;
  animation-play-state: running, paused;
}
.chip:hover, .chip:focus-visible { border-color: transparent; background: linear-gradient(var(--paper), var(--paper)) padding-box, conic-gradient(from var(--spin), var(--spectrum)) border-box; transform: translateY(-3px); box-shadow: 0 10px 22px -12px var(--shadow); animation-play-state: running, running; }
.chip-key { color: var(--ink-2); font-weight: 500; }
.chip-text { overflow-wrap: anywhere; }
.chips:empty, .suggest-label[hidden] { display: none; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .6rem; }
.actions:empty { display: none; }
.next { padding: .8rem 1.5rem; border-radius: 999px; background: var(--ink); color: var(--paper); font-weight: 600; transition: transform .3s var(--spring); animation: chip-in .6s 1.5s var(--spring) both; }
.next:hover { transform: translateY(-2px); }
.hint { text-align: center; font-size: .78rem; color: var(--ink-2); }
.hint kbd { padding: .05rem .4rem; border-radius: 6px; background: var(--bubble); font: inherit; font-weight: 600; }

/* ---------- Modals ---------- */
.modal { width: min(480px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); margin: auto; padding: 0; border: 0; background: transparent; color: var(--ink); overflow: visible; }
.modal::backdrop { background: var(--backdrop); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.modal[open] .modal-card { animation: modal-in .45s var(--spring); }
.modal-card { position: relative; display: grid; gap: 1rem; max-height: calc(100dvh - 2rem); overflow: auto; padding: 1.8rem 1.6rem 1.5rem; border-radius: 28px; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 30px 60px -30px var(--shadow); }
.modal-card .orb { width: 40px; height: 40px; }
.modal-card h2 { font-family: var(--serif); font-size: 2.2rem; font-weight: 400; line-height: 1.05; }
.modal-card p, .modal-card li { color: var(--ink-2); line-height: 1.55; }
.modal-card ul { display: grid; gap: .45rem; padding-left: 1.1rem; }
.modal-card strong { color: var(--ink); }
.modal-card .small { font-size: .82rem; }
.modal-close { position: absolute; top: 1rem; right: 1rem; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; margin-top: .4rem; }
.btn { padding: .7rem 1.2rem; border-radius: 999px; font-weight: 600; transition: transform .3s var(--spring); }
.btn:hover { transform: translateY(-2px); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-ghost { background: var(--bubble); }
.btn-danger { background: var(--bad); color: #fff; }

/* ---------- Motion ---------- */
::view-transition-group(mode-pill) { animation-duration: .55s; animation-timing-function: var(--spring); }

@keyframes spin { to { --spin: 360deg; } }
@keyframes morph { to { border-radius: 55% 45% 42% 58% / 44% 56% 46% 54%; } }
@keyframes breathe { 50% { scale: 1.15; opacity: .6; } }
@keyframes drift { to { translate: var(--x) var(--y); scale: 1.2; } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; translate: 0 16px; } }
@keyframes collapse { to { opacity: 0; height: 0; padding: 0; } }
@keyframes dot { 50% { translate: 0 -4px; opacity: .4; } }
@keyframes stream { to { -webkit-mask-position: 0 0; mask-position: 0 0; } }
@keyframes chip-in { from { opacity: 0; scale: .8; translate: 0 10px; } }
@keyframes bubble { from { opacity: 0; scale: .7; translate: 20px 10px; } }
@keyframes badge { from { opacity: 0; scale: .3; } to { opacity: 1; scale: 1; } }
@keyframes bump { 40% { scale: 1.15; } }
@keyframes modal-in { from { opacity: 0; scale: .92; translate: 0 12px; } }

@media (max-width: 900px) {
  .top { grid-template-columns: 1fr auto; gap: .8rem; }
  .switch { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 600px) {
  .top { padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right)); }
  .brand { font-size: .95rem; }
  .stat { padding: .35rem .65rem; font-size: .8rem; }
  .stat-label { display: none; }
  .switch a { padding: .5rem .6rem; font-size: .85rem; }
  .quiz { gap: 1.2rem; padding-inline: max(1rem, env(safe-area-inset-left)) max(1rem, env(safe-area-inset-right)); }
  .intro { padding-top: .5rem; }
  .orb-lg { width: 64px; height: 64px; }
  .msg { gap: .7rem; }
  .msg > .orb { width: 24px; height: 24px; }
  .ai-body { font-size: 1.04rem; }
  .product { flex-wrap: wrap; padding: .9rem 1rem; }
  .tile { width: 48px; height: 48px; border-radius: 14px; }
  .pill { margin-left: 0; }
  .chips { display: grid; grid-template-columns: 1fr; }
  .chip { width: 100%; }
}
@media (hover: none) { .hint { display: none; } }
@media (max-width: 440px) {
  .brand-text { display: none; }
  .brand .orb { width: 30px; height: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
