@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700;900&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --text-primary: #e8e6e3;
  --text-secondary: #9a9a9a;
  --accent: #c9a227;
  --accent-glow: #d4af3780;
  --danger: #8b0000;
  --success: #2e7d32;
  --border: #2a2a3e;
  --font-heading: 'Playfair Display', serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

html, body {
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  padding-top: 52px;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(201, 162, 39, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139, 0, 0, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(26, 26, 46, 0.5) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* CRT scanline overlay */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.03) 2px,
      rgba(0, 0, 0, 0.03) 4px
    );
  pointer-events: none;
  z-index: 9990;
  animation: scanlineDrift 8s linear infinite;
}

@keyframes scanlineDrift {
  from { transform: translateY(0); }
  to { transform: translateY(4px); }
}

/* ========================
   CHANNEL STATUS BAR
   ======================== */

.channel-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 36px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  z-index: 9999;
  gap: 16px;
}

.channel-bar .channel-id {
  color: var(--accent);
  white-space: nowrap;
}

.channel-bar .channel-status {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.channel-bar .status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 0.4; box-shadow: none; }
  50% { opacity: 1; box-shadow: 0 0 6px var(--accent); }
}

/* ========================
   CONTAINER
   ======================== */

.container {
  position: relative;
  z-index: 1;
  max-width: 700px;
  width: 100%;
}

/* ========================
   HQ MESSAGES
   ======================== */

.hq-message {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 2px 12px 12px 12px;
  padding: 0;
  margin-bottom: 0;
  position: relative;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.5s ease, max-height 0.01s ease, padding 0.01s ease, margin-bottom 0.01s ease;
}

.hq-message.revealed {
  opacity: 1;
  max-height: none;
  overflow: visible;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.hq-message .msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.hq-message .msg-sender {
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
}

.hq-message .msg-time {
  color: var(--text-secondary);
  opacity: 0.6;
}

.hq-message .msg-body {
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text-primary);
}

.hq-message .msg-body p + p {
  margin-top: 12px;
}

/* Analyst variant */
.hq-message.analyst {
  border-left: 3px solid var(--accent);
}

.hq-message.analyst .msg-sender {
  color: var(--accent);
}

/* Alert / warning variant */
.hq-message.alert {
  border-left: 3px solid var(--danger);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(139, 0, 0, 0.05) 100%);
}

.hq-message.alert .msg-sender {
  color: #cc4444;
}

/* System message (short, centered) */
.hq-message.system {
  background: transparent;
  border: none;
  text-align: center;
  padding: 12px 20px;
}

.hq-message.system .msg-body {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  letter-spacing: 1px;
}

/* Task/directive variant */
.hq-message.directive {
  background: linear-gradient(135deg, var(--bg-card) 0%, #1f1f35 100%);
  border: 1px solid rgba(201, 162, 39, 0.2);
  position: relative;
  overflow: hidden;
}

.hq-message.directive::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* ========================
   AGENT INPUT (detective reply)
   ======================== */

.agent-input {
  margin-top: 20px;
  margin-bottom: 16px;
}

.agent-input .input-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  text-transform: uppercase;
}

.agent-input .input-label .label-accent {
  color: var(--accent);
}

.agent-input .input-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.agent-input .input-row input {
  flex: 1;
  min-width: 200px;
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  transition: border-color 0.3s, box-shadow 0.3s;
  outline: none;
  caret-color: var(--accent);
}

.agent-input .input-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.agent-input .input-row input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ========================
   BUTTONS
   ======================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--accent) 0%, #b8941f 100%);
  color: var(--bg-primary);
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.3s;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.btn:active {
  transform: translateY(0);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}

.btn-secondary:hover {
  background: rgba(201, 162, 39, 0.1);
}

.btn-large {
  padding: 18px 40px;
  font-size: 1.1rem;
}

/* ========================
   ERROR / STATUS MESSAGES
   ======================== */

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.3s;
  font-family: var(--font-mono);
}

.error-msg.visible {
  opacity: 1;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ========================
   TYPING BUBBLE (before messages)
   ======================== */

.hq-typing-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  margin-bottom: 16px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hq-typing-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

.hq-typing-bubble .typing-sender {
  opacity: 0.7;
}

.hq-typing-bubble .typing-dots {
  display: inline-flex;
  gap: 3px;
}

.hq-typing-bubble .typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.hq-typing-bubble .typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.hq-typing-bubble .typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ========================
   "HQ ANALYZING" INDICATOR (multi-step)
   ======================== */

.hq-typing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  margin-bottom: 16px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.hq-typing .typing-dots {
  display: inline-flex;
  gap: 3px;
}

.hq-typing .typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.hq-typing .typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.hq-typing .typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

/* ========================
   FIELD DATA WAITING (QR levels)
   ======================== */

.field-waiting {
  margin-top: 28px;
  text-align: center;
}

.field-waiting .waiting-card {
  background: var(--bg-card);
  border: 1px dashed rgba(201, 162, 39, 0.3);
  border-radius: 12px;
  padding: 28px 32px;
  display: inline-block;
}

.field-waiting .waiting-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 1px;
  margin-bottom: 16px;
  text-transform: uppercase;
}

.field-waiting .waiting-icon {
  width: 72px;
  height: 72px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  animation: pulseGlow 2s ease-in-out infinite;
}

.field-waiting .waiting-note {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-top: 8px;
}

/* ========================
   HINT (details/summary)
   ======================== */

.hint-block {
  margin-bottom: 16px;
  cursor: pointer;
}

.hint-block summary {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 1px;
  transition: color 0.2s;
}

.hint-block summary:hover {
  color: var(--accent);
}

.hint-block .hint-content {
  margin-top: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-left: 2px solid var(--accent);
}

.hint-block .hint-loading {
  margin-top: 10px;
  padding: 12px 16px;
  display: none;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.hint-block .hint-loading.active {
  display: flex;
}

.hint-block .hint-loading .typing-dots {
  display: inline-flex;
  gap: 3px;
}

.hint-block .hint-loading .typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.hint-block .hint-loading .typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.hint-block .hint-loading .typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.hint-block .hint-content {
  display: none;
}

.hint-block .hint-content.loaded {
  display: block;
  animation: fadeIn 0.4s ease;
}

/* ========================
   STEP MESSAGES (multi-step levels)
   ======================== */

.step-message {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding: 16px 20px;
  border-radius: 0 8px 8px 0;
  margin-top: 20px;
  font-size: 0.95rem;
  line-height: 1.7;
  animation: fadeIn 0.5s ease;
  display: none;
}

.step-message.visible {
  display: block;
}

.step-message .msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
}

.step-message .msg-sender {
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
}

/* ========================
   SCENE DIVIDER
   ======================== */

.scene-divider {
  width: 60px;
  height: 2px;
  background: var(--accent);
  margin: 20px 0;
  opacity: 0.4;
}

/* ========================
   STAMP (case closed etc.)
   ======================== */

.stamp {
  display: inline-block;
  border: 3px solid var(--danger);
  color: var(--danger);
  padding: 8px 20px;
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 900;
  transform: rotate(-5deg);
  opacity: 0.9;
  margin: 20px 0;
  text-transform: uppercase;
  letter-spacing: 2px;
}

/* ========================
   CHARGES LIST (finale)
   ======================== */

.charges-list {
  list-style: none;
  margin: 20px 0;
}

.charges-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
}

.charges-list li::before {
  content: '\00A7';
  color: var(--accent);
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
}

/* ========================
   VERDICT
   ======================== */

.verdict {
  text-align: center;
  margin: 40px 0;
  padding: 32px;
  background: linear-gradient(135deg, rgba(201, 162, 39, 0.1) 0%, rgba(201, 162, 39, 0.05) 100%);
  border: 2px solid var(--accent);
  border-radius: 16px;
}

.verdict h2 {
  font-family: var(--font-heading);
  color: var(--accent);
  font-size: 1.6rem;
  margin-bottom: 16px;
}

.verdict p {
  font-size: 1.3rem;
  line-height: 1.6;
}

/* ========================
   CONFETTI & HEARTS
   ======================== */

.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.heart-float {
  position: fixed;
  font-size: 2rem;
  animation: floatUp 4s ease-out forwards;
  pointer-events: none;
  z-index: 9998;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-100vh) scale(0.5); }
}

/* ========================
   LOCKED BUTTON
   ======================== */

.btn-locked {
  opacity: 0.4;
  pointer-events: none;
  filter: grayscale(0.5);
  transition: opacity 0.3s, filter 0.3s;
}

.btn-locked.unlocked {
  opacity: 1;
  pointer-events: auto;
  filter: none;
}

/* ========================
   CONNECTION ANIMATION (index)
   ======================== */

.connect-sequence {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 2.2;
  letter-spacing: 0.5px;
}

.connect-line {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.connect-line.visible {
  opacity: 1;
}

.connect-line.done {
  color: var(--accent);
}

.connect-line .ok {
  color: var(--accent);
}

.connect-line .spin {
  display: inline-block;
  animation: spinChar 0.6s linear infinite;
}

@keyframes spinChar {
  0% { content: '|'; }
  25% { content: '/'; }
  50% { content: '-'; }
  75% { content: '\\'; }
}

/* ========================
   UTILITY
   ======================== */

.hidden {
  display: none;
}

.deferred {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  pointer-events: none;
}

.deferred.revealed {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

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

.pulse-glow {
  animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 5px var(--accent-glow); }
  50% { box-shadow: 0 0 25px var(--accent-glow), 0 0 50px var(--accent-glow); }
}

/* ========================
   RESPONSIVE
   ======================== */

@media (max-width: 600px) {
  body {
    padding: 16px;
    padding-top: 44px;
  }

  .channel-bar {
    height: 30px;
    font-size: 0.55rem;
    padding: 0 10px;
  }

  .agent-input .input-row {
    flex-direction: column;
  }

  .agent-input .input-row input {
    min-width: unset;
  }

  .btn-large {
    width: 100%;
    justify-content: center;
  }

  .hq-message {
    padding: 14px 16px;
  }

  .field-waiting .waiting-card {
    padding: 20px 16px;
  }
}

/* ========================
   HQ RESPONSE (dynamic after code check)
   ======================== */

.hq-response {
  animation: fadeIn 0.5s ease;
}

/* ========================
   NEXT BUTTON (step levels)
   ======================== */

.next-btn {
  display: none;
  margin-top: 24px;
}

.next-btn.visible {
  display: inline-flex;
}

/* ========================
   LEGACY SUPPORT (kept for compatibility)
   ======================== */

.input-group {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.input-group input {
  flex: 1;
  min-width: 200px;
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1rem;
  transition: border-color 0.3s, box-shadow 0.3s;
  outline: none;
  caret-color: var(--accent);
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.input-group input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

@media (max-width: 600px) {
  .input-group {
    flex-direction: column;
  }

  .input-group input {
    min-width: unset;
  }
}
