:root {
  color-scheme: dark;
  --bg: #050506;
  --panel: rgba(12, 10, 13, 0.92);
  --panel-strong: #100d11;
  --text: #fff8f5;
  --muted: #968a92;
  --line: rgba(255, 255, 255, 0.13);
  --ember: #f20d27;
  --ember-soft: #ff455a;
  --blue: #168cff;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
}

:root[data-accent="violet"] { --ember: #9b62ff; --ember-soft: #c6a5ff; }
:root[data-accent="blue"] { --ember: #238cff; --ember-soft: #79bdff; }
:root[data-accent="green"] { --ember: #14b878; --ember-soft: #70e0b1; }

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }

body {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 88% 8%, rgba(242, 13, 39, .34), transparent 25%),
    radial-gradient(circle at 12% 32%, rgba(22, 140, 255, .12), transparent 18%),
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.09) 1px, transparent 1.5px),
    linear-gradient(155deg, #14080c 0%, #050506 36%, #08070a 100%);
  background-size: auto, auto, 9px 9px, auto;
}

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

.ambient {
  position: fixed;
  inset: -30vh -30vw auto;
  height: 55vh;
  pointer-events: none;
  background:
    repeating-radial-gradient(circle at 73% 36%, rgba(245, 10, 35, .23) 0 2px, transparent 3px 11px),
    conic-gradient(from 120deg at 50% 50%, transparent, rgba(242,13,39,.23), transparent 28%);
  filter: contrast(1.3);
}

.shell {
  width: min(760px, 100%);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  position: relative;
}

.topbar, .identity, .status-strip, .settings-head, .dialog-actions, .switch-row {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; padding: 4px 0 16px; }
.identity { gap: 13px; }
.eyebrow { margin: 0 0 3px; color: var(--ember-soft); font: 800 9px/1 monospace; letter-spacing: .2em; }
h1, h2 { margin: 0; font-weight: 900; letter-spacing: -.035em; }
h1 { font-size: 25px; text-transform: uppercase; text-shadow: -2px 0 rgba(20,130,255,.65), 2px 0 rgba(255,0,36,.6); }
h2 { font-size: 23px; }

.core {
  width: 47px; height: 47px; overflow: hidden;
  border: 1px solid rgba(255, 31, 63, .72); border-radius: 7px; padding: 1px;
  background: #070508; transform: rotate(-3deg);
  box-shadow: -3px 0 var(--blue), 3px 0 var(--ember), 0 0 28px rgba(242,13,39,.24);
}

.core img {
  display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated;
  animation: pulse 3.2s ease-in-out infinite;
}

@keyframes pulse { 50% { transform: scale(.88); opacity: .76; } }

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
}

.status-strip {
  gap: 9px;
  border-block: 1px solid var(--line);
  padding: 10px 2px;
  color: var(--muted);
  font-size: 12px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #58616a; }
.status-dot.online { background: #41dda0; box-shadow: 0 0 10px #41dda0; }
.status-dot.error { background: #ff625c; }
.status-model { margin-left: auto; color: #64717b; letter-spacing: .05em; }

.avatar-zone {
  position: relative; min-height: 112px; margin-top: 10px; overflow: hidden;
  border: 1px solid rgba(255,28,53,.45);
  clip-path: polygon(0 0, 100% 0, 97% 87%, 70% 87%, 67% 100%, 0 100%);
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.16) 1px, transparent 1.5px),
    linear-gradient(112deg, rgba(242,13,39,.45), transparent 42%), #0a080b;
  background-size: 8px 8px, auto, auto;
}
.avatar-zone::after { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(-17deg, transparent 0 15px, rgba(242,13,39,.09) 16px 18px); }
.avatar-zone::before { content: ""; position: absolute; z-index: 2; left: 0; bottom: -9px; width: 154px; height: 43px; border-radius: 50%; background: radial-gradient(ellipse,rgba(242,13,39,.34),rgba(22,140,255,.13) 48%,transparent 73%); transform: skewX(-11deg); }
.avatar-zone .dragon-art { position: absolute; z-index: 4; width: 138px; height: 138px; object-fit: contain; left: -1px; bottom: -23px; image-rendering: pixelated; filter: drop-shadow(-3px 0 var(--blue)) drop-shadow(3px 0 var(--ember)); transform-origin: 50% 100%; animation: mobile-combat-ready 1.8s steps(5,end) infinite; }
.avatar-zone .miles-art { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 67% 34%; opacity: .72; mix-blend-mode: screen; filter: saturate(1.45) contrast(1.35); }
.avatar-zone .spider-mark { position: absolute; z-index: 3; width: 54px; height: 68px; right: 13px; bottom: 7px; opacity: .82; filter: drop-shadow(-2px 0 var(--blue)); transform: rotate(8deg); }
.avatar-zone .evolution-hud { position: absolute; z-index: 7; right: 8px; bottom: 7px; min-width: 158px; padding: 6px 8px; backdrop-filter: blur(8px); }
.avatar-zone .evolution-next { display: none; }
.comic-burst { position: absolute; width: 180px; height: 180px; left: -21px; top: -40px; background: repeating-radial-gradient(circle, rgba(255,10,35,.37) 0 2px, transparent 3px 9px); transform: rotate(9deg); }
.avatar-copy { position: absolute; z-index: 5; top: 21px; left: 133px; display: grid; gap: 2px; font-family: monospace; transform: rotate(-2deg); }
.avatar-copy span, .avatar-copy small { color: #a99da4; font-size: 8px; letter-spacing: .12em; }
.avatar-copy strong { position: relative; font-size: clamp(22px,7vw,35px); font-style: italic; letter-spacing: -.08em; color: white; text-shadow: -3px 2px #127eea, 3px -2px #e20c29; }

.conversation {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 25px 0 20px;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}
.conversation::-webkit-scrollbar { display: none; }
.message { max-width: 88%; margin: 0 0 14px; animation: arrive .22s ease-out; }
.message p { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 16px; line-height: 1.48; }
.message.assistant { padding: 10px 12px; border-left: 3px solid var(--ember); background: linear-gradient(90deg, rgba(242,13,39,.09), transparent); }
.message.assistant::before { content: "DRACARYS"; display: block; margin-bottom: 7px; color: var(--ember-soft); font-size: 9px; font-weight: 800; letter-spacing: .17em; }
.message.assistant.chatgpt-response::before { content: none; }
.message.assistant.chatgpt-response { width: 100%; max-width: 100%; padding: 12px 13px 8px; border-width: 2px; border-radius: 4px 4px 14px 4px; }
.message.user { margin-left: auto; padding: 12px 15px; border: 1px solid rgba(24,132,255,.55); border-radius: 3px; background: linear-gradient(135deg, rgba(17,70,130,.26), rgba(242,13,39,.08)); clip-path: polygon(6px 0,100% 0,100% calc(100% - 7px),calc(100% - 7px) 100%,0 100%,0 6px); }
.message.pending { color: var(--muted); }
@keyframes arrive { from { opacity: 0; transform: translateY(7px); } }
@keyframes mobile-combat-ready { 0%,100% { transform: translateX(-3px) rotate(-2deg) scale(.97); } 50% { transform: translate(5px,-3px) rotate(1deg) scale(1.02); } }

.message.assistant {
  position: relative;
  overflow: visible;
  border: 1px solid rgba(255,255,255,.16);
  border-left: 3px solid var(--ember);
  border-radius: 4px;
  color: #f5eef1;
  background:
    linear-gradient(125deg, rgba(255,255,255,.11), rgba(242,13,39,.045) 48%, rgba(22,140,255,.075)),
    rgba(11,9,14,.52);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.16),
    -2px 0 rgba(22,140,255,.62),
    0 14px 34px rgba(0,0,0,.28);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
}

.composer { padding-top: 9px; border-top: 1px solid var(--line); }
.voice-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  margin-bottom: 9px;
  padding: 10px 11px;
  border: 1px solid rgba(255, 108, 55, .3);
  border-radius: 17px;
  background: linear-gradient(105deg, rgba(84, 25, 10, .72), rgba(18, 22, 28, .9));
}
.voice-panel[hidden] { display: none; }
.voice-orb { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; border: 1px solid rgba(255, 127, 76, .45); }
.voice-orb span { width: 13px; height: 13px; border-radius: 50%; background: var(--ember); box-shadow: 0 0 19px var(--ember); animation: voicePulse 1.25s ease-in-out infinite; }
.voice-panel.thinking .voice-orb span { animation-duration: .55s; }
.voice-panel.speaking .voice-orb span { animation: voiceSpeak .8s ease-in-out infinite alternate; }
.voice-panel.error { border-color: rgba(255, 98, 92, .55); }
.voice-state-copy { min-width: 0; display: grid; gap: 2px; }
.voice-state-copy strong { font-size: 13px; }
.voice-state-copy small { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.voice-stop-button { min-height: 34px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.05); }
@keyframes voicePulse { 50% { transform: scale(.58); opacity: .58; } }
@keyframes voiceSpeak { to { transform: scale(1.45); opacity: .65; } }
.input-wrap { display: flex; align-items: flex-end; gap: 8px; border: 1px solid rgba(242,13,39,.38); border-radius: 4px; background: var(--panel); padding: 6px 7px 6px 14px; backdrop-filter: blur(18px); box-shadow: -2px 0 var(--blue), 2px 0 rgba(242,13,39,.7); }
textarea { flex: 1; min-height: 39px; max-height: 130px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); padding: 9px 0 7px; line-height: 1.35; }
textarea::placeholder { color: #66727c; }
.mic-button { flex: 0 0 40px; height: 40px; border: 0; border-radius: 14px; background: rgba(255,255,255,.06); color: var(--ember-soft); }
.mic-button.listening { background: var(--ember); color: white; box-shadow: 0 0 24px rgba(255,90,36,.35); }
.send-button { width: 100%; height: 48px; margin-top: 9px; border: 0; border-radius: 2px; display: flex; justify-content: space-between; align-items: center; padding: 0 17px; background: linear-gradient(105deg, #a80019, #f20d27 62%, #ff3b50); font-weight: 900; font-family: monospace; letter-spacing: .08em; box-shadow: -3px 3px 0 #0d6bd1, 0 9px 28px rgba(220,0,28,.25); clip-path: polygon(8px 0,100% 0,100% calc(100% - 8px),calc(100% - 8px) 100%,0 100%,0 8px); }
.send-button:disabled { opacity: .45; }
.send-button.is-stop { background: linear-gradient(105deg,#242128,#3c3740); color: #ff7b72; box-shadow: -3px 3px 0 #6d1b29,0 9px 28px rgba(0,0,0,.25); }
.voice-mode-button {
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 7px 13px;
  text-align: left;
  background: rgba(255,255,255,.025);
}
.voice-mode-button > span:nth-child(2) { display: grid; gap: 1px; }
.voice-mode-button strong { font-size: 12px; }
.voice-mode-button small { color: var(--muted); font-size: 10px; }
.voice-mode-icon { color: var(--ember-soft); text-shadow: 0 0 12px var(--ember); }
.voice-mode-button[aria-pressed="true"] { border-color: rgba(255, 104, 49, .48); background: rgba(255,90,36,.09); }
.voice-mode-button[aria-pressed="true"] .voice-mode-icon { color: #48dda0; text-shadow: 0 0 12px #48dda0; }

dialog { width: min(520px, calc(100% - 24px)); border: 1px solid rgba(242,13,39,.42); border-radius: 5px; padding: 0; color: var(--text); background: rgba(8,7,9,.98); box-shadow: -5px 4px 0 rgba(19,110,219,.55), 5px -4px 0 rgba(242,13,39,.38), 0 30px 100px #000; }
dialog::backdrop { background: rgba(0,0,0,.7); backdrop-filter: blur(8px); }
.settings-card { padding: 21px; }
.settings-head { justify-content: space-between; margin-bottom: 24px; }
label { display: block; margin: 16px 0; color: #b6c0c7; font-size: 13px; }
label > input[type="text"], label > input[type="password"], label > select { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 13px; outline: 0; background: #151a20; color: var(--text); padding: 12px; }
.access-role { display: inline-flex; margin: 0 0 4px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--ember-soft); font-size: 11px; }
.guest-profile-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.guest-profile-settings[hidden] { display: none; }
.switch-row { justify-content: space-between; gap: 15px; }
.switch-row span { display: grid; gap: 3px; }
.switch-row small, .privacy { color: var(--muted); }
input[type="checkbox"] { width: 44px; height: 25px; accent-color: var(--ember); }
.privacy { font-size: 12px; line-height: 1.45; }
.dialog-actions { gap: 9px; margin-top: 22px; }
.dialog-actions button { flex: 1; min-height: 44px; border-radius: 13px; }
.secondary { border: 1px solid var(--line); background: transparent; }
.primary { border: 0; background: var(--ember); font-weight: 700; }

@media (min-width: 720px) {
  .shell { padding-inline: 30px; }
  .message { max-width: 78%; }
}

@media (max-width: 460px) {
  .guest-profile-settings { grid-template-columns: 1fr; }
  .avatar-zone .evolution-hud { min-width: 146px; }
  .shell { min-width: 0; padding-inline: 12px; }
  .message, .message.assistant.chatgpt-response, .response-body, .rich-response, .response-section { min-width: 0; max-width: 100%; }
  .rich-response p, .rich-response li, .rich-response code, .rich-response td, .rich-response th { overflow-wrap: anywhere; word-break: break-word; }
  .response-section { clip-path: none; }
  .conversation { scroll-padding-block: 12px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}
