@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

:root {
  --bg: #070a16;
  --panel: rgba(21, 26, 46, .68);
  --panel-strong: rgba(20, 25, 48, .9);
  --line: rgba(132, 144, 190, .18);
  --purple: #6e5bff;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --text: #fff;
  --muted: #c7cbe0;
  --dim: #8a90ae;
  --radius: 24px;
  font-family: "PingFang SC", "Inter", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--text); background: var(--bg); overflow-x: hidden; }
button, textarea { font: inherit; }
button { color: inherit; }

body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 14% 22%, rgba(110, 91, 255, .22), transparent 30%),
    radial-gradient(circle at 86% 78%, rgba(34, 211, 238, .12), transparent 34%),
    linear-gradient(140deg, #090b1a, #10142a 50%, #080b19);
}

.starfield { position: fixed; inset: 0; opacity: .58; pointer-events: none; }
.starfield::before, .starfield::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,.8) 0 1px, transparent 1.5px);
  background-size: 73px 73px;
}
.starfield::after { background-size: 121px 121px; transform: translate(31px, 11px); opacity: .45; }

.app-shell { position: relative; z-index: 1; width: min(1460px, calc(100% - 48px)); margin: 0 auto; padding: 24px 0; height: 100vh; display: flex; flex-direction: column; box-sizing: border-box; }
.glass-panel { border: 1px solid var(--line); background: var(--panel); box-shadow: 0 24px 80px rgba(0,0,0,.35), inset 0 1px rgba(255,255,255,.045); backdrop-filter: blur(24px); }

.topbar { min-height: 70px; border-radius: 20px; display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid rgba(34,211,238,.45); border-radius: 13px; font-weight: 700; color: var(--cyan); background: linear-gradient(145deg, rgba(34,211,238,.18), rgba(110,91,255,.2)); box-shadow: 0 0 28px rgba(34,211,238,.15); }
.eyebrow { margin: 0 0 3px; color: var(--dim); font-size: 10px; letter-spacing: .18em; font-weight: 600; }
h1 { margin: 0; font-size: 20px; font-weight: 600; }
h1 span { color: var(--muted); font-weight: 400; }
.service-status { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.service-chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; color: var(--dim); font-size: 11px; border-radius: 999px; border: 1px solid rgba(255,255,255,.07); background: rgba(255,255,255,.035); transition: .3s ease; }
.service-chip i { width: 6px; height: 6px; border-radius: 50%; background: #51576f; box-shadow: 0 0 0 3px rgba(81,87,111,.12); }
.service-chip.ready { color: #b8f8df; border-color: rgba(16,185,129,.22); }
.service-chip.ready i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.service-chip.unavailable { color: #fecaca; }
.service-chip.unavailable i { background: var(--red); box-shadow: 0 0 10px var(--red); }

.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(340px, .8fr) minmax(580px, 1.45fr); gap: 18px; padding-top: 18px; }
.npc-panel, .chat-panel { min-height: 0; border-radius: var(--radius); position: relative; overflow: hidden; }
.npc-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 28px; background: linear-gradient(165deg, rgba(23,28,55,.82), rgba(14,18,35,.7)); }
.npc-panel::after { content: ""; position: absolute; inset: auto 8% 5%; height: 1px; background: linear-gradient(90deg, transparent, rgba(34,211,238,.35), transparent); }
.npc-kicker { position: absolute; top: 26px; left: 28px; color: var(--dim); font-size: 11px; letter-spacing: .09em; }
.npc-kicker span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 12px var(--green); margin-right: 6px; }
.orbit { position: absolute; border: 1px solid rgba(34,211,238,.12); border-radius: 50%; animation: spin 20s linear infinite; }
.orbit::after { content: ""; position: absolute; top: 20%; left: 3%; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 14px var(--cyan); }
.orbit-one { width: 350px; height: 350px; }
.orbit-two { width: 430px; height: 430px; border-color: rgba(244,114,182,.09); animation-direction: reverse; animation-duration: 30s; }
.portrait-wrap { position: relative; z-index: 2; width: min(340px, 82%); height: 430px; display: grid; place-items: end center; animation: float 5s ease-in-out infinite; }
.portrait-wrap img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 22px 30px rgba(0,0,0,.38)); }
.portrait-glow { position: absolute; z-index: -1; left: 12%; right: 12%; bottom: 5%; height: 60%; border-radius: 50%; background: radial-gradient(circle, rgba(110,91,255,.34), rgba(34,211,238,.08) 45%, transparent 70%); filter: blur(20px); }
.portrait-fallback { margin: auto; font-size: 56px; color: var(--cyan); }
.npc-identity { position: relative; z-index: 3; text-align: center; margin-top: -35px; }
.npc-identity h2 { font-size: 36px; font-weight: 500; letter-spacing: .28em; margin: 4px 0 12px .28em; text-shadow: 0 0 30px rgba(110,91,255,.45); }
.mode-badge { display: inline-flex; align-items: center; gap: 8px; border: 1px solid rgba(34,211,238,.22); border-radius: 999px; padding: 7px 14px; color: #c7f6ff; background: rgba(34,211,238,.08); font-size: 12px; }
.mode-badge span { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.mode-badge.strategy { color: #ddd7ff; border-color: rgba(110,91,255,.35); background: rgba(110,91,255,.12); }
.mode-badge.strategy span { background: var(--purple); }
.mode-badge.ticket { color: #ffe0f0; border-color: rgba(244,114,182,.35); background: rgba(244,114,182,.1); }
.mode-badge.ticket span { background: var(--pink); }
.voice-wave { height: 28px; margin-top: 20px; display: flex; align-items: center; gap: 4px; opacity: .25; }
.voice-wave i { width: 3px; height: 7px; border-radius: 2px; background: var(--cyan); }
.voice-wave.playing { opacity: 1; }
.voice-wave.playing i { animation: wave .8s ease-in-out infinite alternate; box-shadow: 0 0 8px var(--cyan); }
.voice-wave i:nth-child(2), .voice-wave i:nth-child(6) { animation-delay: -.2s; }
.voice-wave i:nth-child(3), .voice-wave i:nth-child(5) { animation-delay: -.4s; }
.npc-panel blockquote { color: var(--dim); font-size: 12px; margin: 8px 0 0; }

.chat-panel { display: flex; flex-direction: column; background: rgba(12,16,33,.76); }
.chat-header { min-height: 84px; padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.chat-header h2 { margin: 0; font-size: 18px; font-weight: 500; }
.quick-actions { display: flex; gap: 8px; }
.quick-actions button, .clear-button { border: 1px solid rgba(255,255,255,.09); background: rgba(255,255,255,.045); border-radius: 10px; padding: 8px 11px; font-size: 11px; color: var(--muted); cursor: pointer; transition: .2s ease; }
.quick-actions button:hover, .clear-button:hover { transform: translateY(-1px); border-color: rgba(34,211,238,.35); color: white; background: rgba(34,211,238,.08); }
.notice { margin: 12px 20px 0; padding: 10px 13px; border: 1px solid rgba(245,158,11,.32); border-radius: 10px; background: rgba(245,158,11,.09); color: #fde7ae; font-size: 12px; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 26px 24px; scrollbar-width: thin; scrollbar-color: rgba(110,91,255,.35) transparent; }
.message { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 22px; animation: message-in .25s ease both; }
.message.user-message { justify-content: flex-end; }
.avatar { flex: 0 0 30px; height: 30px; border: 1px solid rgba(34,211,238,.3); border-radius: 9px; display: grid; place-items: center; color: var(--cyan); background: rgba(34,211,238,.08); font-size: 11px; }
.message-content { max-width: min(78%, 680px); }
.speaker { display: block; color: var(--dim); font-size: 10px; margin: 0 0 6px 3px; }
.user-message .speaker { text-align: right; margin-right: 3px; }
.bubble { border: 1px solid rgba(110,91,255,.2); border-radius: 5px 17px 17px 17px; background: linear-gradient(145deg, rgba(42,47,81,.92), rgba(27,31,57,.86)); color: var(--muted); padding: 12px 15px; font-size: 14px; line-height: 1.75; white-space: pre-wrap; box-shadow: 0 12px 30px rgba(0,0,0,.14); }
.user-message .bubble { border-radius: 17px 5px 17px 17px; border-color: rgba(244,114,182,.18); color: white; background: linear-gradient(135deg, rgba(110,91,255,.82), rgba(186,73,161,.7)); }
.npc-message .bubble { white-space: normal; }
.npc-message .bubble strong { color: #fff; font-weight: 600; }
.npc-message .bubble em { color: #d9d4ff; font-style: italic; }
.npc-message .bubble code { background: rgba(34,211,238,.12); color: #a5edf8; padding: 1px 6px; border-radius: 5px; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.npc-message .bubble pre { background: rgba(10,14,26,.7); border: 1px solid rgba(110,91,255,.18); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.npc-message .bubble pre code { background: none; padding: 0; color: #e6e1ff; }
.npc-message .bubble h3, .npc-message .bubble h4, .npc-message .bubble h5, .npc-message .bubble h6 { color: #fff; font-weight: 600; margin: 10px 0 6px; line-height: 1.4; }
.npc-message .bubble h3 { font-size: 16px; }
.npc-message .bubble h4 { font-size: 15px; }
.npc-message .bubble ul { margin: 6px 0; padding-left: 20px; }
.npc-message .bubble li { margin: 3px 0; list-style: disc; }
.source-list { margin-top: 8px; border: 1px solid rgba(34,211,238,.14); border-radius: 12px; background: rgba(34,211,238,.04); overflow: hidden; }
.source-list summary { padding: 9px 12px; color: #a5edf8; font-size: 11px; cursor: pointer; }
.source-item { padding: 9px 12px; border-top: 1px solid rgba(255,255,255,.06); color: var(--dim); font-size: 11px; line-height: 1.55; }
.source-item strong { display: block; color: var(--muted); margin-bottom: 3px; }
.tool-card { margin-top: 8px; padding: 10px 12px; display: flex; align-items: center; gap: 9px; border: 1px solid rgba(16,185,129,.22); border-radius: 11px; background: rgba(16,185,129,.07); color: var(--muted); font-size: 11px; }
.tool-card span { padding: 3px 7px; border-radius: 999px; background: rgba(16,185,129,.15); color: #9ff2d1; }
.tool-card strong { font-weight: 500; overflow-wrap: anywhere; }
.typing::after { content: ""; display: inline-block; width: 5px; height: 14px; margin-left: 4px; vertical-align: -2px; background: var(--cyan); animation: blink .8s steps(2) infinite; }

.composer { min-height: 94px; padding: 14px 18px; border-top: 1px solid var(--line); background: rgba(8,11,25,.65); display: flex; align-items: center; gap: 10px; }
.input-wrap { position: relative; flex: 1; }
textarea { width: 100%; min-height: 54px; max-height: 120px; resize: none; outline: none; color: white; border: 1px solid rgba(255,255,255,.1); border-radius: 15px; padding: 15px 72px 12px 15px; background: rgba(255,255,255,.045); transition: .2s ease; }
textarea:focus { border-color: rgba(34,211,238,.45); box-shadow: 0 0 0 3px rgba(34,211,238,.06); }
textarea::placeholder { color: #656b87; }
#char-count { position: absolute; right: 12px; bottom: 8px; color: #666d88; font-size: 9px; }
.icon-button, .send-button { border: 0; cursor: pointer; transition: .2s ease; }
.mic-button { flex: 0 0 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgba(34,211,238,.09); border: 1px solid rgba(34,211,238,.25); }
.mic-button svg { width: 19px; fill: var(--cyan); }
.mic-button:hover { box-shadow: 0 0 24px rgba(34,211,238,.2); }
.mic-button.recording { background: rgba(239,68,68,.18); border-color: rgba(239,68,68,.6); animation: pulse 1s infinite; }
.mic-button.recording svg { fill: #fca5a5; }
.send-button { height: 48px; padding: 0 18px; border-radius: 13px; background: linear-gradient(135deg, var(--purple), #8b5cf6); box-shadow: 0 10px 25px rgba(110,91,255,.25); }
.send-button:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(110,91,255,.38); }
.send-button:disabled, .mic-button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.tts-toggle { display: grid; place-items: center; gap: 3px; color: var(--dim); font-size: 9px; cursor: pointer; }
.tts-toggle input { position: absolute; opacity: 0; }
.toggle-track { width: 34px; height: 18px; padding: 2px; border-radius: 999px; background: #33384e; transition: .2s ease; }
.toggle-track i { display: block; width: 14px; height: 14px; border-radius: 50%; background: #8a90ae; transition: .2s ease; }
.tts-toggle input:checked + .toggle-track { background: rgba(34,211,238,.23); }
.tts-toggle input:checked + .toggle-track i { transform: translateX(16px); background: var(--cyan); box-shadow: 0 0 9px var(--cyan); }
.clear-button { padding: 8px; }

@keyframes float { 50% { transform: translateY(-10px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wave { from { height: 6px; } to { height: 25px; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); } }
@keyframes message-in { from { opacity: 0; transform: translateY(9px); } }

@media (max-width: 1050px) {
  .app-shell { width: min(100% - 24px, 920px); height: auto; min-height: 100vh; }
  .stage { grid-template-columns: 1fr; }
  .npc-panel { min-height: 330px; }
  .chat-panel { height: 78vh; }
  .portrait-wrap { position: absolute; left: 4%; bottom: 0; width: 250px; height: 310px; }
  .npc-identity { margin-left: 260px; margin-top: 0; }
  .orbit { display: none; }
  .chat-panel { height: 78vh; min-height: 480px; }
}

@media (max-width: 720px) {
  .app-shell { width: calc(100% - 16px); padding: 8px 0; }
  .topbar, .chat-header { align-items: flex-start; flex-direction: column; }
  .service-status { justify-content: flex-start; }
  .stage { padding-top: 8px; }
  .npc-panel { min-height: 230px; align-items: flex-end; }
  .portrait-wrap { width: 170px; height: 220px; left: 0; }
  .npc-identity { margin: 25px 5% 0 175px; }
  .npc-identity h2 { font-size: 27px; }
  .voice-wave, .npc-panel blockquote { display: none; }
  .chat-header { gap: 10px; }
  .composer { flex-wrap: wrap; }
  .input-wrap { flex-basis: 100%; }
  .message-content { max-width: 88%; }
  .clear-button { display: none; }
}
