/* ── Design tokens — cyberpunk neon on deep slate ── */
:root {
  --bg: #0F172A;
  --bg-2: #131b30;
  --muted: #1F1829;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.16);
  --text: #FFFFFF;
  --text-muted: #949cb4;
  --primary: #DC2626;
  --secondary: #2563EB;
  --accent: #22C55E;
  --violet: #8B5CF6;
  --warning: #F59E0B;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.6);
  --glow-green: 0 0 24px rgba(34, 197, 94, 0.35);
  --glow-blue: 0 0 24px rgba(37, 99, 235, 0.35);
  font-family: 'Tajawal', ui-sans-serif, system-ui, sans-serif;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }

.bg-glow {
  position: fixed; inset: -30% -10% auto -10%; height: 80vh; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 50% 45% at 30% 0%, rgba(37, 99, 235, 0.28), transparent 65%),
    radial-gradient(ellipse 45% 40% at 72% 5%, rgba(139, 92, 246, 0.22), transparent 65%),
    radial-gradient(ellipse 40% 35% at 50% 60%, rgba(34, 197, 94, 0.10), transparent 70%);
}

/* ── App frame ── */
.app {
  position: relative; z-index: 1; height: 100dvh;
  display: grid; grid-template-rows: auto 1fr auto;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem 1.1rem;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.02rem; }
.brand b { font-family: 'Orbitron', sans-serif; color: var(--accent); letter-spacing: 0.04em; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 3px;
  background: linear-gradient(135deg, var(--accent), var(--secondary));
  box-shadow: 0 0 14px rgba(34, 197, 94, 0.7);
}
.topbar-mid { display: flex; align-items: center; gap: 0.5rem; }
.topbar-actions { display: flex; gap: 0.4rem; }

.pill {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.32rem 0.8rem; border-radius: 99px;
  background: rgba(34, 197, 94, 0.12); color: var(--accent);
  border: 1px solid rgba(34, 197, 94, 0.25);
  font-size: 0.78rem; font-weight: 700; white-space: nowrap;
}
.pill.ghost { background: rgba(255, 255, 255, 0.05); color: var(--text-muted); border-color: var(--border); }
.pill.busy { background: rgba(37, 99, 235, 0.14); color: #8fb4ff; border-color: rgba(37, 99, 235, 0.3); }
.pill.rec { background: rgba(220, 38, 38, 0.16); color: #ff9a9a; border-color: rgba(220, 38, 38, 0.35); }
.pulse {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.35; transform: scale(0.7); } }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: transform 0.16s ease, background 0.2s, color 0.2s, box-shadow 0.2s;
}
.icon-btn:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.1); color: #fff; }
.icon-btn.active { color: var(--accent); border-color: rgba(34, 197, 94, 0.4); box-shadow: var(--glow-green); }
.icon-btn.big { width: 44px; height: 44px; }
.icon-btn svg { width: 19px; height: 19px; }

/* ── Layout ── */
.layout {
  display: grid; grid-template-columns: 1fr 352px;
  gap: 0.85rem; padding: 0.85rem; min-height: 0;
}
.stage {
  position: relative; border-radius: var(--radius-lg); overflow: hidden;
  background: radial-gradient(ellipse 70% 60% at 50% 105%, rgba(37, 99, 235, 0.22), transparent 70%), #0b1120;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 0;
}
#scene { display: block; width: 100%; height: 100%; touch-action: none; }
.stage-top { position: absolute; top: 0.8rem; inset-inline-start: 0.8rem; }
.stage-btns { display: flex; gap: 0.4rem; }
.stage-top .icon-btn.big {
  background: rgba(11, 17, 32, 0.6); backdrop-filter: blur(10px);
}
.hint {
  position: absolute; bottom: 0.7rem; inset-inline-start: 0.9rem;
  font-size: 0.72rem; color: var(--text-muted); pointer-events: none;
  transition: opacity 0.6s ease;
}
.hint.gone { opacity: 0; }

.bubble {
  position: absolute; top: 0.9rem; inset-inline-end: 0.9rem; max-width: min(58%, 420px);
  padding: 0.75rem 1rem; border-radius: 16px 16px 16px 4px;
  background: rgba(11, 17, 32, 0.82); backdrop-filter: blur(14px);
  border: 1px solid var(--border-2);
  font-size: 0.95rem; line-height: 1.7;
  box-shadow: var(--shadow);
  animation: fadeUp 0.35s ease both;
}
.bubble.think { color: var(--text-muted); font-style: italic; }

.meters {
  position: absolute; bottom: 0.8rem; inset-inline-end: 0.9rem;
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.65rem 0.8rem; border-radius: var(--radius-sm);
  background: rgba(11, 17, 32, 0.62); backdrop-filter: blur(12px);
  border: 1px solid var(--border); min-width: 168px;
}
.meter { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 0.5rem; }
.meter span { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
.meter .bar { height: 5px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter .bar i { display: block; height: 100%; border-radius: 99px; transition: width 0.7s cubic-bezier(0.2, 0.9, 0.3, 1); }
.meter .bar.green i { background: linear-gradient(90deg, #16a34a, #22c55e); }
.meter .bar.blue i { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.meter .bar.violet i { background: linear-gradient(90deg, #7c3aed, #a78bfa); }
.meter .bar.amber i { background: linear-gradient(90deg, #d97706, #fbbf24); }

.cam-preview {
  position: absolute; top: 0.85rem; inset-inline-end: 0.9rem;
  width: 148px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--border-2); background: #000;
  box-shadow: var(--shadow);
}
.cam-preview video { width: 100%; display: block; transform: scaleX(-1); }
.cam-tag {
  position: absolute; bottom: 0; inset-inline: 0; padding: 0.25rem 0.5rem;
  font-size: 0.65rem; background: rgba(11, 17, 32, 0.85); color: var(--accent); text-align: center;
}

/* ── Side panel ── */
.panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); backdrop-filter: blur(14px);
  box-shadow: var(--shadow); overflow: hidden;
}
.tabs {
  display: flex; gap: 0.2rem; padding: 0.45rem;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; padding: 0.42rem 0.7rem; border-radius: 99px;
  font-size: 0.8rem; font-weight: 700; color: var(--text-muted); white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}
.tab:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.tab.active { background: linear-gradient(135deg, var(--accent), #16a34a); color: #04140a; }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0.95rem; }

.group { margin-bottom: 1.15rem; }
.group-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.74rem; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.6rem;
}
.group-head::after { content: ''; flex: 1; height: 1px; background: var(--border); margin-inline-start: 0.6rem; }

.slider { margin-bottom: 0.72rem; }
.slider-top { display: flex; justify-content: space-between; font-size: 0.82rem; margin-bottom: 0.22rem; }
.slider-top b { font-family: 'Orbitron', sans-serif; font-size: 0.74rem; color: var(--accent); font-weight: 700; }
input[type='range'] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  border-radius: 99px; background: rgba(255, 255, 255, 0.14); outline: none;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: grab;
  transition: transform 0.15s ease; box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
}
input[type='range']::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type='range']::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent);
}

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  padding: 0.36rem 0.72rem; border-radius: 99px; font-size: 0.78rem; font-weight: 600;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); color: var(--text-muted);
  transition: all 0.18s ease;
}
.chip:hover { background: rgba(255, 255, 255, 0.1); color: #fff; transform: translateY(-1px); }
.chip.active { background: rgba(34, 197, 94, 0.16); border-color: rgba(34, 197, 94, 0.45); color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.swatch {
  width: 30px; height: 30px; border-radius: 9px; border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35); transition: transform 0.16s ease;
}
.swatch:hover { transform: translateY(-2px) scale(1.06); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 14px rgba(34, 197, 94, 0.55); }

/* ── Cards & buttons ── */
.card {
  padding: 0.8rem 0.9rem; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.045); border: 1px solid var(--border);
  margin-bottom: 0.6rem; font-size: 0.85rem; color: var(--text-muted);
}
.card b { color: var(--text); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  padding: 0.6rem 1.1rem; border-radius: 99px; font-size: 0.86rem; font-weight: 700;
  transition: transform 0.16s ease, box-shadow 0.2s, background 0.2s, opacity 0.2s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #16a34a); color: #04140a; box-shadow: var(--glow-green); }
.btn.primary:hover:not(:disabled) { transform: translateY(-2px); }
.btn.blue { background: linear-gradient(135deg, var(--secondary), #60a5fa); color: #06101f; box-shadow: var(--glow-blue); }
.btn.blue:hover:not(:disabled) { transform: translateY(-2px); }
.btn.ghost { border: 1px solid var(--border-2); color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); transform: translateY(-2px); }
.btn.danger { background: rgba(220, 38, 38, 0.9); color: #fff; }
.btn.row { width: 100%; margin-top: 0.3rem; }
.btn svg { width: 17px; height: 17px; }

/* ── Composer ── */
.composer {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.65rem 1.1rem 0.85rem;
  background: rgba(15, 23, 42, 0.8); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1; padding: 0.72rem 1.05rem; border-radius: 99px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border);
  font-size: 0.94rem; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.composer input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16); }
.composer .send {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #16a34a); color: #04140a;
  box-shadow: var(--glow-green); transition: transform 0.16s ease;
}
.composer .send:hover { transform: translateY(-2px) scale(1.04); }
.composer .send svg { width: 20px; height: 20px; }
#btnMic.rec { color: var(--primary); border-color: rgba(220, 38, 38, 0.45); box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); animation: recPulse 1.6s infinite; }
@keyframes recPulse { 0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); } 70% { box-shadow: 0 0 0 16px rgba(220, 38, 38, 0); } 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); } }

/* ── Overlay / intro ── */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1rem;
  background: rgba(8, 13, 26, 0.82); backdrop-filter: blur(10px);
  animation: fadeIn 0.3s ease both;
}
.overlay[hidden] { display: none; }
.intro-card {
  width: min(520px, 100%); padding: 2rem; border-radius: var(--radius-lg);
  background: linear-gradient(160deg, #16213c, #0d1424);
  border: 1px solid var(--border-2); box-shadow: var(--shadow-lg);
  animation: fadeUp 0.45s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.intro-badge {
  display: inline-block; font-size: 0.7rem; font-weight: 800; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 0.7rem;
}
.intro-card h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); font-weight: 800; letter-spacing: -0.02em; margin-bottom: 0.6rem; }
.intro-card p { color: var(--text-muted); font-size: 0.93rem; margin-bottom: 1.1rem; }
.intro-card .field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.1rem; }
.intro-card .field span { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }
.intro-card .field input {
  padding: 0.7rem 1rem; border-radius: var(--radius-sm); font-size: 1rem;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); outline: none;
}
.intro-card .field input:focus { border-color: var(--accent); }
.intro-actions { display: flex; gap: 0.6rem; margin-bottom: 1rem; }
.fine { font-size: 0.72rem !important; color: #6f7891 !important; margin: 0 !important; line-height: 1.7; }

/* ── Toasts ── */
.toasts { position: fixed; bottom: 5.4rem; inset-inline-start: 1.2rem; z-index: 90; display: flex; flex-direction: column; gap: 0.45rem; }
.toast {
  padding: 0.6rem 1rem; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
  background: rgba(11, 17, 32, 0.94); border: 1px solid var(--border-2);
  box-shadow: var(--shadow); animation: fadeUp 0.3s ease both;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.4); color: #86efac; }
.toast.warn { border-color: rgba(245, 158, 11, 0.4); color: #fcd34d; }
.toast.err { border-color: rgba(220, 38, 38, 0.4); color: #fca5a5; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 44% 1fr; padding: 0.6rem; gap: 0.6rem; }
  .panel { border-radius: var(--radius); }
  .topbar-mid .pill.ghost { display: none; }
  .bubble { max-width: 74%; font-size: 0.88rem; }
  .meters { min-width: 0; padding: 0.5rem 0.6rem; }
  .meter { grid-template-columns: 46px 1fr; }
  .stage-top .icon-btn.big { width: 38px; height: 38px; }
  .stage-top .icon-btn.big svg { width: 17px; height: 17px; }
}
@media (max-width: 560px) {
  .brand { font-size: 0.92rem; }
  .composer { padding: 0.55rem 0.7rem 0.7rem; }
  .composer input { font-size: 0.88rem; padding: 0.62rem 0.9rem; }
  .hint { display: none; }
  .cam-preview { width: 104px; }
  .intro-card { padding: 1.4rem; }
  .intro-actions { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Boot / error banner ── */
.boot {
  position: fixed; bottom: 1rem; inset-inline-start: 50%; transform: translateX(50%);
  z-index: 80; padding: 0.6rem 1.1rem; border-radius: 99px;
  background: rgba(11, 17, 32, 0.92); border: 1px solid var(--border-2);
  color: var(--text-muted); font-size: 0.82rem; font-weight: 600;
  box-shadow: var(--shadow); transition: opacity 0.4s ease;
}
.boot.err { color: #fca5a5; border-color: rgba(220, 38, 38, 0.5); background: rgba(42, 12, 18, 0.95); }
.boot.gone { opacity: 0; pointer-events: none; }

/* ══ ANIME THEME ══ */
:root {
  --bg: #140F22;
  --bg-2: #1B1430;
  --primary: #EC4899;
  --secondary: #8B5CF6;
  --accent: #F472B6;
  --glow-green: 0 0 24px rgba(244, 114, 182, 0.35);
  --glow-blue: 0 0 24px rgba(139, 92, 246, 0.35);
}
body { background: var(--bg); }
.bg-glow {
  background:
    radial-gradient(ellipse 50% 45% at 28% 0%, rgba(139, 92, 246, 0.30), transparent 65%),
    radial-gradient(ellipse 45% 40% at 74% 4%, rgba(236, 72, 153, 0.24), transparent 65%),
    radial-gradient(ellipse 40% 35% at 50% 62%, rgba(87, 214, 234, 0.12), transparent 70%);
}
.topbar { background: rgba(20, 15, 34, 0.74); }
.stage {
  background:
    radial-gradient(ellipse 70% 60% at 50% 104%, rgba(236, 72, 153, 0.22), transparent 70%),
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(139, 92, 246, 0.22), transparent 72%),
    #150f24;
}
/* manga speed-lines radiating behind the character */
.stage::after {
  content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 50% 44%,
    rgba(255, 255, 255, 0.05) 0deg 0.9deg, transparent 0.9deg 3.2deg);
  -webkit-mask-image: radial-gradient(circle at 50% 44%, transparent 24%, #000 76%);
  mask-image: radial-gradient(circle at 50% 44%, transparent 24%, #000 76%);
}
#scene { position: relative; z-index: 1; }
.stage-top, .bubble, .meters, .hint, .cam-preview { z-index: 4; }
.brand-mark { background: linear-gradient(135deg, var(--accent), var(--secondary)); box-shadow: 0 0 14px rgba(236, 72, 153, 0.7); }
.brand b { color: var(--accent); }

.tab.active { background: linear-gradient(135deg, var(--accent), var(--secondary)); color: #1b0d24; font-weight: 700; }
.chip.active { background: rgba(244, 114, 182, 0.18); border-color: rgba(244, 114, 182, 0.5); color: #FFD9EC; }
.swatch.active { box-shadow: 0 0 0 2px #140F22, 0 0 0 4px var(--accent); }
/* manga speech bubble with a tail */
.bubble {
  border-radius: 16px 16px 16px 4px;
  border: 1px solid rgba(244, 114, 182, 0.35);
  background: rgba(27, 20, 48, 0.88);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.bubble::after {
  content: ''; position: absolute; inset-inline-end: 18px; bottom: -9px;
  width: 0; height: 0; border: 8px solid transparent;
  border-top-color: rgba(244, 114, 182, 0.35);
  border-bottom: 0;
}
.send { background: linear-gradient(135deg, var(--accent), var(--secondary)); color: #1b0d24; }
.send:hover { transform: translateY(-2px); box-shadow: 0 0 22px rgba(244, 114, 182, 0.5); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--secondary)); color: #1b0d24; }
.btn.primary:hover { transform: translateY(-2px); box-shadow: var(--glow-green); }
.pill.busy { border-color: rgba(244, 114, 182, 0.5); color: #FFD9EC; }
.icon-btn.big:hover { transform: translateY(-2px); background: rgba(236, 72, 153, 0.22); }
.intro-card { border: 1px solid rgba(244, 114, 182, 0.28); box-shadow: var(--shadow-lg); }
.intro-badge { background: rgba(236, 72, 153, 0.18); color: #FFD9EC; border-color: rgba(244, 114, 182, 0.4); }
.group-head { color: #FFD9EC; }
.slider input[type="range"] { accent-color: var(--accent); }
