:root {
  --bg: #070912; --bg2: #0d1124; --panel: rgba(20, 24, 48, .72); --panel2: #151a35; --line: rgba(130, 140, 255, .14);
  --text: #e8eaff; --muted: #8d93b8; --accent: #7c5cff; --accent2: #22d3ee; --danger: #ff4d6d; --ok: #2ee6a6; --warn: #ffb547;
  --mood: #22d3ee; --mood2: #7c5cff; --radius: 16px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: radial-gradient(1200px 700px at 70% -10%, #1b1650 0%, transparent 60%), radial-gradient(900px 600px at -10% 110%, #0b2a3d 0%, transparent 60%), var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
a { color: var(--accent2); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 280px 1fr; grid-template-rows: minmax(0, 1fr); position: fixed; inset: 0; }
.side { background: rgba(9, 11, 26, .85); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 10px; font-weight: 700; letter-spacing: .5px; }
.brand .dot { width: 26px; height: 26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 6%, var(--accent2) 22%, var(--accent) 70%); box-shadow: 0 0 16px var(--accent); }
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 0; }
.newchat { margin: 6px 12px 10px; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: linear-gradient(135deg, rgba(124, 92, 255, .25), rgba(34, 211, 238, .15)); font-weight: 600; }
.convs { flex: 1; overflow-y: auto; padding: 0 8px; }
.conv { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; color: var(--muted); font-size: 14px; cursor: pointer; }
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv:hover, .conv.active { background: rgba(124, 92, 255, .14); color: var(--text); }
.conv .del { opacity: 0; background: none; border: 0; color: var(--muted); padding: 2px 6px; }
.conv:hover .del { opacity: 1; }
.side-foot { border-top: 1px solid var(--line); padding: 10px; display: grid; gap: 6px; }
.side-foot button { text-align: left; padding: 9px 10px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); }
.side-foot button:hover { background: rgba(255, 255, 255, .05); color: var(--text); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; position: relative; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(7, 9, 18, .6); backdrop-filter: blur(10px); }
.top .menu { display: none; background: none; border: 0; font-size: 22px; padding: 4px 8px; }
.top .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top select { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; font-size: 13px; }
.pill { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); color: var(--muted); }
.pill.on { color: #fff; border-color: var(--mood); box-shadow: 0 0 12px color-mix(in srgb, var(--mood) 50%, transparent); }

.chat { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 16px 140px; scroll-behavior: smooth; }
.inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

/* ---------- orb ---------- */
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 6vh 0 10px; gap: 14px; }
.orb { --s: 150px; width: var(--s); height: var(--s); border-radius: 50%; position: relative; cursor: pointer; border: 0; padding: 0;
  background: radial-gradient(circle at 35% 30%, #ffffff 0 4%, var(--mood) 22%, var(--mood2) 62%, #05060f 100%);
  box-shadow: 0 0 40px color-mix(in srgb, var(--mood) 60%, transparent), 0 0 110px color-mix(in srgb, var(--mood2) 45%, transparent), inset 0 0 30px rgba(255, 255, 255, .25);
  animation: breathe 4s ease-in-out infinite; transition: background .8s, box-shadow .8s; }
.orb::before, .orb::after { content: ''; position: absolute; inset: -14px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--mood) 45%, transparent); animation: ring 6s linear infinite; }
.orb::after { inset: -28px; border-style: dashed; opacity: .5; animation-duration: 14s; animation-direction: reverse; }
.orb.small { --s: 34px; animation-duration: 3s; }
.orb.small::before { inset: -5px; } .orb.small::after { display: none; }
.orb.listening { animation: listen 1.1s ease-in-out infinite; }
.orb.speaking { animation: speak .45s ease-in-out infinite alternate; }
.orb.thinking::before { border-top-color: #fff; animation-duration: 1.2s; }
@keyframes breathe { 50% { transform: scale(1.04); filter: brightness(1.12); } }
@keyframes listen { 50% { transform: scale(1.12); filter: brightness(1.3); } }
@keyframes speak { from { transform: scale(.98); } to { transform: scale(1.07); filter: brightness(1.25); } }
@keyframes ring { to { transform: rotate(360deg); } }
.hero h1 { margin: 10px 0 0; font-size: 28px; font-weight: 700; }
.hero p { margin: 0; color: var(--muted); max-width: 520px; }
.mood-label { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--mood); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.chip { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; color: var(--text); }
.chip:hover { border-color: var(--accent); }

/* ---------- messages ---------- */
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(680px, 88%); padding: 12px 16px; border-radius: var(--radius); line-height: 1.55; overflow-wrap: anywhere; }
.msg.user .bubble { background: linear-gradient(135deg, #5b3fff, #3b7bff); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.ai .bubble { background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 6px; }
.bubble p { margin: .4em 0; } .bubble p:first-child { margin-top: 0; } .bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: #05060f; border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; }
.bubble code { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.bubble table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.bubble th { background: rgba(124, 92, 255, .15); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; background: rgba(34, 211, 238, .1); color: var(--accent2); border: 1px solid rgba(34, 211, 238, .25); }
.shots { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.shots img { width: 180px; max-width: 46%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; color: var(--mood); }
@keyframes blink { 50% { opacity: 0; } }
.err { color: var(--danger); }

.approval { border: 1px solid var(--warn); background: rgba(255, 181, 71, .08); border-radius: 14px; padding: 12px 14px; margin-top: 10px; }
.approval b { color: var(--warn); }
.approval .row { display: flex; gap: 8px; margin-top: 10px; }
.btn { padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #3b7bff); border: 0; }
.btn.ok { background: var(--ok); color: #04130d; border: 0; }
.btn.no { background: transparent; border-color: var(--danger); color: var(--danger); }

/* ---------- composer ---------- */
.composer { position: absolute; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); }
.box { max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 8px; backdrop-filter: blur(14px); box-shadow: 0 10px 40px rgba(0, 0, 0, .4); }
.box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.box textarea { flex: 1; background: transparent; border: 0; outline: 0; resize: none; padding: 8px 6px; max-height: 180px; line-height: 1.45; }
.icon { width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .06); display: grid; place-items: center; flex: none; }
.icon svg { width: 20px; height: 20px; }
.icon.send { background: linear-gradient(135deg, var(--accent), #3b7bff); }
.icon.rec { background: var(--danger); animation: listen 1s infinite; }
.pending { max-width: 820px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.att { position: relative; display: flex; align-items: center; gap: 6px; padding: 5px 8px 5px 5px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 12px; max-width: 220px; }
.att img, .att .ph { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #05060f; display: grid; place-items: center; flex: none; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att button { background: none; border: 0; color: var(--muted); padding: 0 2px; }
.att.up { opacity: .55; }
.media-out { margin-top: 10px; }
.media-out img, .media-out video { max-width: 100%; max-height: 520px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.media-out a { font-size: 13px; display: inline-block; margin-top: 6px; }
.msg.user .atts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 6px; }
.msg.user .atts img, .msg.user .atts video { max-width: 180px; max-height: 180px; border-radius: 12px; }
.msg.user .col { display: flex; flex-direction: column; align-items: flex-end; max-width: 88%; }
.hint { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ---------- overlays ---------- */
.toast { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 60; background: var(--panel2); border: 1px solid var(--mood); padding: 12px 16px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); max-width: 92vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { width: min(760px, 100%); max-height: 88dvh; overflow-y: auto; background: #0e1228; border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.modal h2 { margin: 0 0 4px; } .modal h3 { margin: 22px 0 8px; font-size: 15px; color: var(--accent2); }
.modal .muted, .muted { color: var(--muted); font-size: 13px; }
.modal textarea, .modal input { width: 100%; background: #070912; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.modal .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.list { display: grid; gap: 6px; }
.item { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .03); font-size: 14px; }
.item span { flex: 1; }
.item button { background: none; border: 0; color: var(--danger); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.tabs button { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 13px; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .9); display: grid; place-items: center; }
.lightbox img { max-width: 96vw; max-height: 92dvh; border-radius: 10px; }

/* ---------- 3D KAI ---------- */
.kai3d { position: relative; width: var(--k3, 320px); aspect-ratio: 4 / 5; border-radius: 48% 48% 26px 26px / 38% 38% 26px 26px; overflow: hidden;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--mood) 30%, transparent), transparent 70%);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mood) 70%, transparent), 0 0 60px color-mix(in srgb, var(--mood) 35%, transparent); transition: box-shadow .5s; }
.kai3d.speaking { box-shadow: 0 0 0 3px var(--mood), 0 0 90px color-mix(in srgb, var(--mood) 60%, transparent); }
.kai3d.listening { box-shadow: 0 0 0 3px var(--mood), 0 0 40px var(--mood); }
.kai3d-stage { position: absolute; inset: 0; }
.kai3d-load { position: absolute; inset: auto 0 12px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- voice mode (full screen, for glasses / hands-free) ---------- */
.voice { position: fixed; inset: 0; z-index: 40; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--mood2) 25%, transparent), transparent 70%), var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 26px; padding: 24px; text-align: center; }
.voice .orb { --s: 210px; }
.voice .said { min-height: 3em; max-width: 640px; color: var(--muted); font-size: 17px; }
.voice .reply { max-width: 640px; font-size: 19px; line-height: 1.5; max-height: 30vh; overflow-y: auto; }
.voice .close { position: absolute; top: 18px; right: 18px; }
.vctl { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.vctl select { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; margin-left: 6px; }
.tr { display: grid; gap: 12px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; overflow-y: auto; }
.card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 28px; display: grid; gap: 14px; text-align: center; backdrop-filter: blur(14px); }
.card .orb { --s: 90px; margin: 6px auto 4px; }
.card input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #070912; text-align: center; font-size: 16px; }
.card .btn { width: 100%; padding: 12px; }
#qr { background: #fff; padding: 10px; border-radius: 12px; width: fit-content; margin: 0 auto; }
#qr img { display: block; }
.secret { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; color: var(--muted); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: 84vw; max-width: 320px; transform: translateX(-100%); transition: transform .25s; }
  .side.open { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .7); }
  .top .menu { display: block; }
  .top select { max-width: 120px; }
  .hero { padding-top: 3vh; }
  .orb { --s: 120px; }
  .modal .grid2 { grid-template-columns: 1fr; }
}
