/* ────────────────────────────────────────────────────────────
   Xuan v8 — visual-first, zero-text-dump UI
   Palette: obsidian night + single element accent per user
   ──────────────────────────────────────────────────────────── */

:root {
  --bg: #05060a;
  --bg-2: #0a0d17;
  --ink: #e8e9ef;
  --ink-dim: #8d90a6;
  --ink-faint: #4a4e63;
  --line: #1a1d2b;
  --gold: #f7d27a;
  --violet: #9f7cff;

  /* Element palette — the SINGLE source of visual truth */
  --wood: #4ade80;
  --fire: #ff6b6b;
  --earth: #d4a574;
  --metal: #c9d1db;
  --water: #60a5fa;

  --accent: var(--gold);
  --radius: 20px;
  --ease: cubic-bezier(.2,.8,.2,1);

  --safe-top: env(safe-area-inset-top);
  --safe-bot: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(1200px 800px at 50% -10%, #12142a 0%, transparent 60%),
    radial-gradient(800px 600px at 100% 120%, #160a1f 0%, transparent 60%),
    var(--bg);
}

.hidden { display: none !important; }
.dim { color: var(--ink-dim); }
.tiny { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }

/* ── Starfield (pure CSS, no images) ─────────────────────── */
.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1px 1px at 80% 30%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1.5px 1.5px at 30% 70%, rgba(255,255,255,.8), transparent 60%),
    radial-gradient(1px 1px at 65% 85%, rgba(255,255,255,.4), transparent 60%),
    radial-gradient(1px 1px at 50% 50%, rgba(255,255,255,.3), transparent 60%),
    radial-gradient(1.2px 1.2px at 15% 90%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1px 1px at 90% 75%, rgba(255,255,255,.5), transparent 60%);
  background-size: 600px 600px;
  animation: drift 120s linear infinite;
  opacity: .7;
}
@keyframes drift { to { background-position: 600px 600px; } }

.screen { position: relative; z-index: 1; height: 100%; }

/* ──────────────────────────────────────────────────────────
   ONBOARDING
   ────────────────────────────────────────────────────────── */
#onboarding {
  display: grid; place-items: center;
  padding: 24px; padding-top: calc(24px + var(--safe-top));
}

.card {
  width: 100%; max-width: 440px;
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 24px;
  backdrop-filter: blur(12px);
}

.brand { text-align: center; margin-bottom: 28px; }
.brand h1 {
  font-family: "SF Pro Display", system-ui, sans-serif;
  font-size: 44px; font-weight: 200; letter-spacing: 0.32em;
  background: linear-gradient(180deg, var(--gold), #c79a46);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand p { color: var(--ink-dim); font-size: 12px; letter-spacing: 0.25em; text-transform: uppercase; }
.brand .mark {
  width: 48px; height: 48px; margin: 0 auto 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6d1, var(--gold) 45%, transparent 70%);
  box-shadow: 0 0 60px 8px rgba(247,210,122,.25);
  animation: breathe 6s var(--ease) infinite;
}
@keyframes breathe {
  0%,100% { transform: scale(1); filter: brightness(1); }
  50%     { transform: scale(1.06); filter: brightness(1.15); }
}

label { display: block; margin-bottom: 14px; }
label > span {
  display: block; font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-dim); margin-bottom: 6px;
}

input[type=text], input[type=date], input[type=time], input:not([type]) {
  width: 100%; padding: 14px 16px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line); border-radius: 12px;
  color: var(--ink); font-size: 15px;
  transition: border-color .2s, background .2s;
}
input:focus { outline: none; border-color: var(--gold); background: rgba(255,255,255,.06); }

.row { display: flex; gap: 12px; }
.grow { flex: 1; }

.gender { border: 0; margin-bottom: 20px; }
.gender legend {
  font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-dim); margin-bottom: 8px;
}
.gender { display: flex; gap: 8px; flex-wrap: wrap; }
.gender legend { flex-basis: 100%; }
.gender label { flex: 1; margin: 0; cursor: pointer; }
.gender label input { display: none; }
.gender label span {
  display: block; padding: 12px; text-align: center;
  border: 1px solid var(--line); border-radius: 12px;
  transition: all .2s;
  font-size: 13px; letter-spacing: 0.08em; color: var(--ink-dim);
}
.gender label input:checked + span {
  border-color: var(--gold); color: var(--gold);
  background: rgba(247,210,122,.06);
}

button[type=submit] {
  width: 100%; margin-top: 8px; padding: 16px;
  background: linear-gradient(180deg, var(--gold), #c79a46);
  border: 0; border-radius: 14px; color: #1a1205;
  font-size: 14px; font-weight: 600; letter-spacing: 0.24em;
  text-transform: uppercase;
  cursor: pointer; position: relative;
  transition: transform .15s var(--ease), box-shadow .2s;
  box-shadow: 0 10px 40px -10px rgba(247,210,122,.5);
}
button[type=submit]:active { transform: scale(.98); }
button[type=submit] .spinner { display: none; }
button[type=submit].loading .label { opacity: 0; }
button[type=submit].loading .spinner {
  display: block; position: absolute; inset: 0; margin: auto;
  width: 20px; height: 20px; border: 2px solid rgba(26,18,5,.3);
  border-top-color: #1a1205; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.err { color: #ff6b6b; font-size: 13px; margin-top: 12px; min-height: 18px; text-align: center; }

/* ──────────────────────────────────────────────────────────
   MAIN SCREEN
   ────────────────────────────────────────────────────────── */
#main {
  display: flex; flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bot));
}

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 20px;
}
.hello { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff6d1, var(--gold) 40%, #5c3d0f 90%);
  box-shadow: 0 0 24px -4px rgba(247,210,122,.4);
  flex-shrink: 0;
}
.hello-name { font-size: 17px; font-weight: 500; letter-spacing: 0.01em; }
.hello-sub { color: var(--ink-dim); font-size: 12px; letter-spacing: 0.08em; }

.icon {
  background: transparent; border: 0; color: var(--ink-dim);
  font-size: 22px; cursor: pointer; width: 40px; height: 40px;
  border-radius: 50%; transition: background .2s;
}
.icon:hover { background: rgba(255,255,255,.04); color: var(--ink); }

/* 2×2 grid with central ASK orb */
.grid {
  flex: 1; position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}
.tile {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.015));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .2s var(--ease), border-color .2s, box-shadow .2s;
}
.tile:hover { border-color: rgba(247,210,122,.3); transform: translateY(-1px); }
.tile:active { transform: scale(.99); }
.tile-label {
  position: absolute; top: 14px; left: 16px;
  font-size: 10px; letter-spacing: 0.28em;
  color: var(--ink-faint); text-transform: uppercase;
  z-index: 2;
}
.tile-body { position: absolute; inset: 0; display: grid; place-items: center; }

/* Central ASK orb */
.ask {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 92px; height: 92px; border-radius: 50%;
  background: transparent; border: 0;
  cursor: pointer;
  display: grid; place-items: center;
  z-index: 10;
}
.ask .orb {
  position: absolute; inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--gold) 40%, #6a4410 85%, transparent 100%);
  box-shadow:
    0 0 40px 8px rgba(247,210,122,.35),
    inset 0 0 20px rgba(0,0,0,.3);
  animation: pulse 4s var(--ease) infinite;
}
.ask .ask-label {
  position: relative; z-index: 2;
  font-size: 10px; letter-spacing: 0.32em; font-weight: 600;
  color: #1a1205;
}
.ask:active .orb { filter: brightness(1.2); }
@keyframes pulse {
  0%,100% { transform: scale(1); box-shadow: 0 0 40px 8px rgba(247,210,122,.35), inset 0 0 20px rgba(0,0,0,.3); }
  50%     { transform: scale(1.05); box-shadow: 0 0 60px 14px rgba(247,210,122,.5), inset 0 0 20px rgba(0,0,0,.3); }
}

.orb.small {
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6d1, var(--gold) 45%, transparent 75%);
  box-shadow: 0 0 16px rgba(247,210,122,.5);
  display: inline-block;
}

/* Tile body visual styling */
.tile svg { display: block; width: 100%; height: 100%; }

/* ──────────────────────────────────────────────────────────
   BOTTOM SHEETS (detail + settings)
   ────────────────────────────────────────────────────────── */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 90vh; height: 90vh;
  background: linear-gradient(180deg, #0d1020, #05060a);
  border-top: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  transform: translateY(100%);
  transition: transform .35s var(--ease);
  padding: 20px 20px calc(20px + var(--safe-bot));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet[aria-hidden="false"] { transform: translateY(0); }
.sheet-grab {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--ink-faint);
  margin: 0 auto 16px;
}
.sheet-close {
  position: absolute; top: 12px; right: 12px;
  background: transparent; border: 0; color: var(--ink-dim);
  font-size: 18px; cursor: pointer; width: 32px; height: 32px;
}
.sheet-body h2 {
  font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 20px;
}
.sheet-body h3 {
  font-size: 11px; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--ink-dim); margin: 24px 0 10px;
}

.btn-line {
  display: block; width: 100%; margin-bottom: 8px; padding: 14px;
  background: transparent; border: 1px solid var(--line);
  color: var(--ink); border-radius: 12px; font-size: 14px;
  letter-spacing: 0.1em; cursor: pointer; transition: all .2s;
}
.btn-line:hover { border-color: var(--gold); color: var(--gold); }
.btn-line.danger:hover { border-color: #ff6b6b; color: #ff6b6b; }

/* Fact rows in detail sheet */
.fact-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.fact-row .k { color: var(--ink-dim); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.fact-row .v { color: var(--ink); font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-dim);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ──────────────────────────────────────────────────────────
   CHAT
   ────────────────────────────────────────────────────────── */
.chat {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5,6,10,.92);
  backdrop-filter: blur(20px);
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .35s var(--ease);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}
.chat[aria-hidden="false"] { transform: translateY(0); }

.chat-top {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.chat-title { flex: 1; font-size: 15px; letter-spacing: 0.08em; }

.chat-stream {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg {
  max-width: 82%; padding: 12px 16px; border-radius: 18px;
  font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(180deg, var(--gold), #c79a46);
  color: #1a1205;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.assistant.streaming::after {
  content: "▊"; color: var(--gold); animation: blink 1s steps(2) infinite; margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input {
  display: flex; gap: 10px; padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: rgba(5,6,10,.6);
}
.chat-input input {
  flex: 1; padding: 14px 16px;
  background: rgba(255,255,255,.06); border: 1px solid var(--line);
  border-radius: 24px; color: var(--ink); font-size: 15px;
}
.chat-input input:focus { outline: none; border-color: var(--gold); }
.chat-input button {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold), #c79a46);
  border: 0; color: #1a1205; font-size: 18px; cursor: pointer;
  flex-shrink: 0;
}
.chat-input button:active { transform: scale(.95); }

/* ──────────────────────────────────────────────────────────
   RESPONSIVE
   ────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .grid { gap: 16px; }
  .ask { width: 120px; height: 120px; }
}
