/* ─── Variables ──────────────────────────────────────── */
:root {
  --bg:        #07080d;
  --bg2:       #0d0f18;
  --bg3:       #13162200;
  --border:    #1e2340;
  --border-hi: #2e3560;
  --green:     #00f5a0;
  --cyan:      #00d4ff;
  --red:       #ff4060;
  --yellow:    #ffd060;
  --text:      #c8cfe8;
  --text-dim:  #4a5278;
  --text-mid:  #7b85b0;
  --font-mono: 'Space Mono', monospace;
  --font-head: 'Syne', sans-serif;
  --radius:    6px;
}

/* ─── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Body ───────────────────────────────────────────── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  overflow-x: hidden;
}

/* ─── Background Grid ────────────────────────────────── */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ─── App Shell ──────────────────────────────────────── */
.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Header ─────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 4px;
}
.logo-bracket { color: var(--text-dim); }
.logo-text    { color: var(--cyan); }
.logo-accent  { color: var(--green); }

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.12em;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse 2.5s ease-in-out infinite;
}
.status-dot.running { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.status-dot.error   { background: var(--red);    box-shadow: 0 0 8px var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ─── Toolbar ────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.lang-selector {
  display: flex;
  align-items: center;
  gap: 12px;
}
.lang-selector label {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}

.lang-pills {
  display: flex;
  gap: 6px;
}

.lang-pill {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.18s;
  letter-spacing: 0.04em;
}
.lang-pill:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}
.lang-pill.active {
  background: rgba(0, 212, 255, 0.1);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px rgba(0, 212, 255, 0.15);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-reset {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.18s;
  letter-spacing: 0.06em;
}
.btn-reset:hover {
  border-color: var(--border-hi);
  color: var(--text-mid);
}

.btn-run {
  background: var(--green);
  border: none;
  color: #07080d;
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 800;
  padding: 9px 28px;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.18s;
  box-shadow: 0 0 20px rgba(0, 245, 160, 0.25);
}
.btn-run:hover {
  background: #00ffc0;
  box-shadow: 0 0 30px rgba(0, 245, 160, 0.45);
  transform: translateY(-1px);
}
.btn-run:active { transform: translateY(0); }
.btn-run:disabled {
  background: var(--border);
  color: var(--text-dim);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.run-icon { font-size: 11px; }

/* ─── Editor Wrapper ─────────────────────────────────── */
.editor-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.editor-label {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}
#editor {
  height: 380px;
  background: #0b0d15 !important;
}

/* ─── Output Panels ──────────────────────────────────── */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .panels { grid-template-columns: 1fr; }
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg2);
  transition: border-color 0.3s;
}
.panel.has-error  { border-color: rgba(255, 64, 96, 0.4); }
.panel.has-output { border-color: rgba(0, 245, 160, 0.25); }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
.panel-title {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}
.panel-badge {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--border);
}
.panel-badge.success { color: var(--green);  border-color: rgba(0,245,160,0.3);  background: rgba(0,245,160,0.06); }
.panel-badge.error   { color: var(--red);    border-color: rgba(255,64,96,0.3);  background: rgba(255,64,96,0.06); }
.panel-badge.ai-thinking { color: var(--cyan); border-color: rgba(0,212,255,0.3); background: rgba(0,212,255,0.06); animation: blink 1s step-start infinite; }
.ai-badge { color: var(--cyan); border-color: rgba(0,212,255,0.2); }

@keyframes blink { 50% { opacity: 0.3; } }

.panel-content {
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text);
  min-height: 120px;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.panel-content.error-text { color: var(--red); }
.panel-content.success-text { color: var(--green); }

/* ─── AI Content ─────────────────────────────────────── */
.ai-content {
  white-space: normal !important;
}

.ai-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
  min-height: 120px;
}
.ai-icon {
  font-size: 28px;
  color: var(--border-hi);
  animation: spin-hex 8s linear infinite;
}
@keyframes spin-hex {
  0%   { transform: rotate(0deg);   opacity: 0.4; }
  50%  { transform: rotate(180deg); opacity: 0.8; }
  100% { transform: rotate(360deg); opacity: 0.4; }
}

.ai-thinking-anim {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--cyan);
  font-size: 12px;
}
.ai-thinking-dots {
  display: flex;
  gap: 5px;
}
.ai-thinking-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.ai-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking-dots span:nth-child(3) { animation-delay: 0.30s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.4; }
  40%           { transform: translateY(-8px); opacity: 1; }
}

/* ─── AI Response Blocks ─────────────────────────────── */
.ai-response { display: flex; flex-direction: column; gap: 12px; }

.ai-block {
  border-radius: var(--radius);
  overflow: hidden;
}

.ai-block-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  padding: 5px 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.ai-block-body {
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-block.reason   { background: rgba(255,64,96,0.05);  border: 1px solid rgba(255,64,96,0.15); }
.ai-block.reason   .ai-block-label { background: rgba(255,64,96,0.1);  color: var(--red); }
.ai-block.reason   .ai-block-body  { color: #ffb0bb; }

.ai-block.fix      { background: rgba(0,245,160,0.04); border: 1px solid rgba(0,245,160,0.12); }
.ai-block.fix      .ai-block-label { background: rgba(0,245,160,0.08); color: var(--green); }
.ai-block.fix      .ai-block-body  { color: #a0ffda; font-family: var(--font-mono); }

.ai-block.explain  { background: rgba(0,212,255,0.04); border: 1px solid rgba(0,212,255,0.12); }
.ai-block.explain  .ai-block-label { background: rgba(0,212,255,0.08); color: var(--cyan); }
.ai-block.explain  .ai-block-body  { color: var(--text); }

/* ─── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border); border-radius: 10px; }

/* ══════════════════════════════════════════════════════
   BHAI, OUTPUT GALAT HAI — Logic Debugger
══════════════════════════════════════════════════════ */
.bhai-section {
  border: 1px solid #2a1f4a;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0c0a14;
  /* subtle purple-tinted bg to visually separate from syntax debugger */
}

/* ── Header ─────────────────────────────────────────── */
.bhai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #2a1f4a;
  background: linear-gradient(90deg, rgba(160,100,255,0.07), rgba(255,140,66,0.04));
}

.bhai-header-left {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.bhai-emoji {
  font-size: 24px;
  flex-shrink: 0;
  margin-top: 2px;
}

.bhai-title {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 800;
  color: #c084fc;
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.bhai-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 3px;
}
.bhai-subtitle em { color: #a78bfa; font-style: normal; }

/* ── Cooldown badge ─────────────────────────────────── */
.bhai-cooldown-wrap {
  display: none;                    /* hidden by default */
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--yellow);
  background: rgba(255,208,96,0.08);
  border: 1px solid rgba(255,208,96,0.25);
  padding: 5px 12px;
  border-radius: 100px;
  flex-shrink: 0;
}
.bhai-cooldown-wrap.visible { display: flex; }

.bhai-cooldown-timer {
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 800;
  color: var(--yellow);
  min-width: 22px;
  text-align: center;
}

.bhai-cooldown-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  color: #9a8850;
}

/* ── Body: input row ────────────────────────────────── */
.bhai-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bhai-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.bhai-input-wrap {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.bhai-input-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.bhai-goal-input {
  width: 100%;
  background: #0f0c1a;
  border: 1px solid #2a1f4a;
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 9px 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  caret-color: #c084fc;
}
.bhai-goal-input:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 2px rgba(124,58,237,0.12);
}
.bhai-goal-input::placeholder { color: #3a2f55; }
.bhai-goal-input:disabled     { opacity: 0.5; cursor: not-allowed; }

/* ── Debug Logic button ─────────────────────────────── */
.btn-bhai {
  background: linear-gradient(135deg, rgba(160,100,255,0.18), rgba(255,140,66,0.1));
  border: 1px solid rgba(160,100,255,0.4);
  color: #c084fc;
  font-family: var(--font-head);
  font-size: 13px;
  font-weight: 800;
  padding: 9px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.07em;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-bhai:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(160,100,255,0.3), rgba(255,140,66,0.18));
  box-shadow: 0 0 20px rgba(160,100,255,0.25);
  transform: translateY(-1px);
}
.btn-bhai:active:not(:disabled) { transform: translateY(0); }
.btn-bhai:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.bhai-btn-icon { font-size: 14px; }

/* ── Result area ────────────────────────────────────── */
.bhai-result {
  border: 1px solid #2a1f4a;
  border-radius: var(--radius);
  background: #09070f;
  min-height: 80px;
  overflow: hidden;
}

.bhai-result-idle {
  padding: 16px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}
.bhai-result-idle strong { color: #a78bfa; }

/* ── Thinking animation (reuses existing dots) ──────── */
.bhai-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  color: #a78bfa;
  font-size: 12px;
}

/* ── Structured response blocks ─────────────────────── */
.bhai-blocks {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.bhai-block {
  border-bottom: 1px solid #1c1428;
  overflow: hidden;
}
.bhai-block:last-child { border-bottom: none; }

.bhai-block-label {
  font-size: 9px;
  letter-spacing: 0.18em;
  padding: 5px 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.bhai-block-body {
  padding: 10px 14px 12px;
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

/* SAMAJH — red-tinted (what went wrong) */
.bhai-samajh .bhai-block-label  { background: rgba(255,64,96,0.08);   color: #ff7090; }
.bhai-samajh .bhai-block-body   { color: #ffb0c0; background: rgba(255,64,96,0.03); }

/* HINT — purple-tinted (the nudge) */
.bhai-hint .bhai-block-label    { background: rgba(160,100,255,0.1);  color: #c084fc; }
.bhai-hint .bhai-block-body     { color: #d4aaff; background: rgba(160,100,255,0.04); }

/* SOCHO — cyan-tinted (the question) */
.bhai-socho .bhai-block-label   { background: rgba(0,212,255,0.08);   color: var(--cyan); }
.bhai-socho .bhai-block-body    { color: var(--text); background: rgba(0,212,255,0.03); font-style: italic; }
/* ─── Terminal ───────────────────────────────────────── */
.terminal-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #080a12;
}
.terminal-wrap.has-error  { border-color: rgba(255, 64, 96, 0.4); }
.terminal-wrap.has-output { border-color: rgba(0, 245, 160, 0.25); }

.terminal-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.terminal-dots {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.tdot {
  width: 11px; height: 11px;
  border-radius: 50%;
}
.tdot-red    { background: #ff5f57; }
.tdot-yellow { background: #febc2e; }
.tdot-green  { background: #28c840; }

.terminal-title {
  flex: 1;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-align: center;
}

.terminal-body {
  padding: 14px 18px 18px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.75;
  min-height: 140px;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.terminal-idle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.terminal-prompt { color: var(--green); }
.terminal-idle-text strong { color: var(--text-mid); }

/* individual output lines */
.t-line {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 1px 0;
}

.t-gutter {
  flex-shrink: 0;
  width: 18px;
  text-align: right;
  font-size: 11px;
  line-height: 1.75;
  color: var(--text-dim);
  user-select: none;
}

.t-text {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

.t-line.t-stdout .t-gutter { color: rgba(0, 245, 160, 0.35); }
.t-line.t-stdout .t-text   { color: var(--text); }

.t-line.t-stderr .t-gutter { color: rgba(255, 64, 96, 0.5); }
.t-line.t-stderr .t-text   { color: var(--red); }

.t-line.t-info  .t-gutter  { color: rgba(0, 212, 255, 0.35); }
.t-line.t-info  .t-text    { color: var(--text-mid); font-style: italic; }

/* blinking cursor at end */
.t-cursor {
  display: inline-block;
  width: 8px; height: 14px;
  background: var(--green);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink-cur 1.1s step-start infinite;
}
@keyframes blink-cur { 50% { opacity: 0; } }

.t-exit-line {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.t-exit-ok   { color: var(--green); }
.t-exit-err  { color: var(--red); }