:root {
  --bg: #0d0e14;
  --bg2: #13141c;
  --bg3: #1a1b26;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #f5f6ff;
  --text2: #c8c9e2;
  --text3: #a5a6c0;
  --accent: #7f77dd;
  --green: #1d9e75;
  --red: #e24b4a;
  --amber: #ba7517;
  --blue: #378add;
  --coral: #d85a30;
  --radius: 14px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
}

#app { width: 100vw; height: 100vh; position: relative; }

.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  opacity: 0; transition: opacity 0.5s ease;
}
.screen.active { display: flex; opacity: 1; }

/* ─── SELECT SCREEN ─── */
.select-bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(127,119,221,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(127,119,221,0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}

.select-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  height: 100%; padding: 2rem 2rem 1.5rem;
  gap: 0.9rem;
  overflow-y: auto;
}

.brand { text-align: center; }
.brand-icon {
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.brand-icon img {
  width: clamp(70px, 8vw, 100px);
  height: clamp(70px, 8vw, 100px);
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,.5));
}
.brand h1 {
  font-size: clamp(40px, 5.5vw, 78px);
  font-weight: 800; letter-spacing: -1.2px;
  color: #ffffff;
  text-shadow: 0 4px 24px rgba(127,119,221,0.45);
  line-height: 1.05;
}
.brand-sub {
  font-size: clamp(18px, 2.2vw, 28px);
  color: var(--text);
  font-weight: 500;
  margin-top: 10px;
  letter-spacing: 0.3px;
}

.lang-row { display: flex; gap: 10px; }
.lang-btn {
  padding: 8px 22px; font-size: 14px; font-weight: 500;
  border: 1px solid var(--border2); border-radius: 30px;
  background: transparent; color: var(--text2); cursor: pointer;
  transition: all .2s;
}
.lang-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.3); }
.lang-btn.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

.choose-label {
  font-size: clamp(16px, 1.9vw, 22px);
  font-weight: 600;
  color: var(--text2); letter-spacing: 1.5px; text-transform: uppercase;
}

.mission-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: 100%; max-width: 1280px;
}

.mission-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  cursor: pointer;
  transition: all .25s;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.mission-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--card-color, var(--accent));
  opacity: 0; transition: opacity .25s;
}
.mission-card:hover {
  border-color: var(--border2);
  background: var(--bg3);
  transform: translateY(-2px);
}
.mission-card:hover::before { opacity: 1; }

.mc-emoji { font-size: 40px; line-height: 1; }
.mc-name {
  font-size: clamp(17px, 1.9vw, 24px);
  font-weight: 700; color: var(--text);
  letter-spacing: 0.2px;
}
.mc-desc {
  font-size: clamp(14px, 1.4vw, 17px);
  color: var(--text2); line-height: 1.45;
}
.mc-agents {
  font-size: clamp(12px, 1.1vw, 14px);
  color: var(--text3);
  margin-top: 4px;
  font-weight: 500;
}

.auto-label {
  font-size: clamp(15px, 1.6vw, 19px);
  color: var(--text2);
  font-weight: 500;
  letter-spacing: 0.5px;
}

.btn-autoplay {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 40px; border-radius: 30px;
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--text); font-size: clamp(16px, 1.7vw, 20px);
  font-weight: 600;
  cursor: pointer; transition: all .25s;
}
.btn-autoplay:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ap-icon { font-size: 16px; }

/* ─── SIM SCREEN ─── */
.sim-topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}
.sim-logo {
  width: 36px; height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.back-btn {
  padding: 7px 16px; font-size: 14px;
  background: transparent; border: 1px solid var(--border2);
  border-radius: 8px; color: var(--text2); cursor: pointer;
  transition: all .2s; white-space: nowrap;
}
.back-btn:hover { color: var(--text); }

.btn-stop-autoplay {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; font-size: 14px; font-weight: 600;
  background: #c0392b; border: 1px solid #e74c3c;
  border-radius: 8px; color: #fff; cursor: pointer;
  transition: all .2s; white-space: nowrap;
  box-shadow: 0 0 0 0 rgba(231, 76, 60, .6);
  animation: stopPulse 1.6s infinite;
}
.btn-stop-autoplay:hover {
  background: #e74c3c;
}
.btn-stop-autoplay .stop-icon { font-size: 12px; }
@keyframes stopPulse {
  0%   { box-shadow: 0 0 0 0 rgba(231, 76, 60, .55); }
  70%  { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.sim-title {
  flex: 1; text-align: center;
  font-size: clamp(16px, 2vw, 22px); font-weight: 600;
}

.lang-mini { display: flex; gap: 6px; }
.lang-btn-mini {
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border2); border-radius: 6px;
  background: transparent; color: var(--text2); cursor: pointer;
  transition: all .2s;
}
.lang-btn-mini.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.stage-outer {
  flex: 1; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
}

#stage {
  display: block;
  width: 100%; height: 100%;
  position: absolute; top: 0; left: 0;
}

#step-caption {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 10px 20px;
  background: linear-gradient(transparent, rgba(13,14,20,0.9));
  font-size: clamp(13px, 1.4vw, 16px);
  color: var(--text2); text-align: center;
  min-height: 44px;
  display: flex; align-items: flex-end; justify-content: center;
}

#letter-overlay {
  position: absolute;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  width: min(720px, 84vw);
  max-height: 46vh;
  z-index: 5;
  padding: 22px 30px 26px;
  background: linear-gradient(170deg, #f8f2e3 0%, #ece3cd 100%);
  color: #29251c;
  border-left: 6px solid var(--letter-color, #7f77dd);
  border-radius: 6px 10px 10px 6px;
  box-shadow:
    0 22px 60px -10px rgba(0,0,0,0.65),
    0 0 0 1px rgba(0,0,0,0.12),
    inset 0 0 60px rgba(120,90,40,0.07);
  font-family: Georgia, 'Times New Roman', serif;
  animation: letterAppear 0.7s cubic-bezier(.22,.9,.31,1.07) both;
  transition: opacity 320ms ease, transform 320ms ease;
  opacity: 1;
}
#letter-overlay.fade-out {
  opacity: 0;
  transform: translate(-50%, -14px);
  animation: none;
}
@keyframes letterAppear {
  from { opacity: 0; transform: translate(-50%, 22px) rotate(-0.6deg); }
  to   { opacity: 1; transform: translate(-50%, 0) rotate(0); }
}
.letter-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 18px;
  border-bottom: 1px dashed rgba(0,0,0,0.22);
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.letter-meta { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-style: italic; color: #6a5a3b; }
.letter-label {
  display: inline-block;
  font-weight: 700; font-style: normal;
  color: #5a4d33;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1.4px;
  margin-right: 6px;
}
.letter-type {
  font-size: 30px; line-height: 1;
  padding: 4px 0;
}
.letter-body {
  font-size: clamp(16px, 1.6vw, 20px);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-y: auto;
  max-height: 32vh;
  font-weight: 400;
}

.progress-bar-wrap {
  height: 3px; background: var(--bg3);
  flex-shrink: 0;
}
#prog-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width 0.8s ease;
}

.bottom-panels {
  display: flex; gap: 0;
  flex-shrink: 0;
  max-height: 200px;
}

.comm-panel {
  flex: 1;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--text2);
  flex-shrink: 0;
}
.panel-header.success { color: #1d9e75; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text3);
}
.live-dot.on {
  background: var(--red);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1}50%{opacity:0} }

#msg-feed {
  flex: 1; overflow-y: auto;
  padding: 8px 14px;
  display: flex; flex-direction: column; gap: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

.msg-row {
  display: flex; gap: 10px; align-items: flex-start;
  animation: msgin .35s ease;
}
@keyframes msgin { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

.msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0;
}
.msg-from { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.msg-text { font-size: clamp(12px, 1.3vw, 14px); color: var(--text2); line-height: 1.5; }
.msg-text.hi { color: var(--text); }

.result-panel {
  width: 360px; flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  animation: msgin .4s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
#result-body {
  padding: 10px 14px;
  font-size: clamp(12px, 1.2vw, 14px);
  color: var(--text); line-height: 2;
}

.sim-controls {
  display: flex; gap: 12px; justify-content: center;
  padding: 10px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  padding: 10px 30px; font-size: clamp(13px, 1.4vw, 16px); font-weight: 600;
  border-radius: 10px; cursor: pointer; transition: all .2s;
}
.ctrl-btn.primary {
  background: var(--accent); color: #fff; border: none;
}
.ctrl-btn.primary:hover { opacity: .85; }
.ctrl-btn.primary:disabled { opacity: .35; cursor: not-allowed; }
.ctrl-btn.secondary {
  background: transparent; border: 1px solid var(--border2); color: var(--text2);
}
.ctrl-btn.secondary:disabled { opacity: .3; cursor: not-allowed; }

/* ─── FULL-SCREEN "AGENTS ONLY" VIEW ─────────────────────────── */
#app.agents-only .sim-topbar,
#app.agents-only .progress-bar-wrap,
#app.agents-only .bottom-panels,
#app.agents-only .sim-controls,
#app.agents-only #step-caption,
#app.agents-only #letter-overlay,
#app.agents-only #chatbot-overlay { display: none !important; }

#btn-exit-agents {
  display: none;
  position: fixed; top: 16px; right: 16px; z-index: 60;
  width: 46px; height: 46px; border-radius: 12px;
  background: rgba(20,22,32,0.5); color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  font-size: 20px; line-height: 1; cursor: pointer;
  opacity: 0.22; transition: opacity .2s;
}
#btn-exit-agents:hover { opacity: 1; }
#app.agents-only #btn-exit-agents { display: block; }

#btn-autoplay-fs {
  display: none;
  position: fixed; top: 16px; right: 74px; z-index: 60;
  height: 46px; padding: 0 18px; border-radius: 12px;
  background: rgba(20,22,32,0.5); color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  font-size: 15px; font-weight: 600; line-height: 46px; cursor: pointer;
  opacity: 0.22; transition: opacity .2s;
}
#btn-autoplay-fs:hover { opacity: 1; }
#app.agents-only #btn-autoplay-fs { display: block; }
.ctrl-btn.secondary:hover { color: var(--text); }

/* ─── AUTOPLAY OVERLAY ─── */
#autoplay-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 20px;
}
#autoplay-overlay h2 {
  font-size: clamp(20px, 3vw, 36px); color: #fff;
}
#autoplay-overlay p {
  font-size: clamp(14px, 1.8vw, 20px); color: var(--text2);
}
#autoplay-overlay button {
  padding: 12px 32px; font-size: 16px; font-weight: 600;
  background: var(--accent); color: #fff; border: none;
  border-radius: 10px; cursor: pointer;
}

/* ─── CHATBOT OVERLAY ─── */
#chatbot-overlay {
  position: absolute; right: 20px; bottom: 200px;
  width: 320px; z-index: 50;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  display: none;
  animation: msgin .4s ease;
}
.cb-header {
  background: var(--accent);
  padding: 10px 14px;
  font-size: 13px; font-weight: 600; color: #fff;
  display: flex; align-items: center; gap: 8px;
}
.cb-messages {
  height: 200px; overflow-y: auto;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.cb-msg {
  max-width: 80%; padding: 8px 12px;
  border-radius: 12px; font-size: 12px; line-height: 1.5;
  animation: msgin .3s ease;
}
.cb-msg.user {
  background: var(--accent); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.cb-msg.bot {
  background: var(--bg2); color: var(--text);
  align-self: flex-start; border-bottom-left-radius: 4px;
}
.cb-typing { color: var(--text3); font-size: 20px; letter-spacing: 4px; }
