/* =====================================================================
   debugger.css  —  Code Trace Engine  (v2 — animated, C + Pseudocode)
   ===================================================================== */

/* ================================================================
   Panel wrapper
================================================================ */
.dbg-panel {
  background: #080f1e;
  border-top: 3px solid var(--brand1, #7c3aed);
  margin: 0;
  padding: 0 0 36px;
}
.dbg-panel .container { max-width: 1240px; margin: 0 auto; padding: 0 20px; }

/* ================================================================
   Header
================================================================ */
.dbg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 8px;
  flex-wrap: wrap;
  gap: 10px;
}
.dbg-header-left  { display: flex; align-items: center; gap: 14px; }
.dbg-header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.dbg-badge {
  background: var(--brand1, #7c3aed);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.dbg-badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a78bfa;
  animation: dbg-dot-blink 1.2s ease-in-out infinite;
}
@keyframes dbg-dot-blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .4; transform: scale(.7); }
}

.dbg-step-counter {
  color: #64748b;
  font-size: 13px;
  font-family: monospace;
  letter-spacing: .04em;
}

.dbg-hint {
  color: #475569;
  font-size: 12px;
}
.dbg-hint kbd {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  color: #94a3b8;
  font-family: monospace;
}

#dbg-close {
  background: #1e293b;
  color: #64748b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
#dbg-close:hover { background: #334155; color: #e2e8f0; }

/* ================================================================
   Progress bar
================================================================ */
.dbg-progress-track {
  height: 3px;
  background: #1e293b;
  border-radius: 2px;
  margin-bottom: 14px;
  overflow: hidden;
}
.dbg-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand1,#7c3aed), #a78bfa);
  border-radius: 2px;
  transition: width .25s cubic-bezier(.4,0,.2,1);
}

/* ================================================================
   Controls bar
================================================================ */
.dbg-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 0 14px;
  flex-wrap: wrap;
}
.dbg-btn {
  background: #1a2540;
  border: 1px solid #293558;
  border-radius: 7px;
  color: #7c8db0;
  cursor: pointer;
  padding: 7px 12px;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s, color .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.dbg-btn:hover  { background: #243060; color: #c4ceee; border-color: #3b4d80; }
.dbg-btn:active { transform: scale(.95); }

.dbg-btn-main {
  background: var(--brand1, #7c3aed);
  border-color: var(--brand1, #7c3aed);
  color: #fff;
  padding: 7px 20px;
  font-weight: 600;
}
.dbg-btn-main:hover { filter: brightness(1.12); }

.dbg-divider { width: 1px; height: 24px; background: #293558; margin: 0 4px; flex-shrink: 0; }

.dbg-speed-ctrl {
  margin-left: 6px;
  display: flex;
  align-items: center;
}
.dbg-speed-ctrl label {
  color: #4b5e8a;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
#dbg-speed {
  background: #1a2540;
  border: 1px solid #293558;
  border-radius: 6px;
  color: #7c8db0;
  font-size: 12px;
  padding: 4px 8px;
}

/* ================================================================
   Main 2-column grid
================================================================ */
.dbg-main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 800px) {
  .dbg-main-grid { grid-template-columns: 1fr; }
}

/* ================================================================
   Code viewer (left column) — dark IDE feel
================================================================ */
.dbg-code-section {
  background: #060c1a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

/* code tab bar  */
.dbg-code-tab-bar {
  display: flex;
  background: #0d1629;
  border-bottom: 1px solid #1e293b;
  padding: 0 12px;
}
.dbg-code-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #4b5e8a;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 9px 12px;
  text-transform: uppercase;
  transition: color .15s;
  white-space: nowrap;
}
.dbg-code-tab:hover { color: #94a3b8; }
.dbg-code-tab.active { color: #a78bfa; border-bottom-color: var(--brand1,#7c3aed); }

.dbg-code-scroll {
  overflow-y: auto;
  max-height: 440px;
  position: relative;
}

/* gutter + lines */
.dbg-code-viewer {
  padding: 6px 0 12px;
  font-family: 'Cascadia Code','Fira Code','Consolas',monospace;
  font-size: 13px;
  line-height: 1.75;
  counter-reset: dbg-line;
  position: relative;
}

.dbg-line {
  display: flex;
  align-items: stretch;
  position: relative;
  transition: background .1s;
  cursor: default;
}
.dbg-ln-num {
  min-width: 44px;
  padding: 0 10px;
  color: #2d3f5e;
  font-size: 11px;
  text-align: right;
  user-select: none;
  flex-shrink: 0;
  border-right: 1px solid #131d30;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transition: color .15s;
}
.dbg-ln-text {
  padding: 0 16px;
  color: #4b6080;
  white-space: pre;
  flex: 1;
  transition: color .15s;
}

/* execution arrow in gutter */
.dbg-ln-num::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-style: solid;
  border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent transparent;
  margin-right: 4px;
  flex-shrink: 0;
  transition: border-color .1s;
}

/* ---- line states ---- */
/* done (executed) */
.dbg-ln-done .dbg-ln-num  { color: #1e3250; }
.dbg-ln-done .dbg-ln-text { color: #253350; }

/* current executing line — ANIMATED */
@keyframes dbg-execute {
  0% {
    background: rgba(124,58,237,.55);
    box-shadow: 0 0 20px rgba(124,58,237,.35);
  }
  100% {
    background: rgba(124,58,237,.18);
    box-shadow: none;
  }
}
.dbg-ln-cur {
  animation: dbg-execute .55s ease forwards;
}
.dbg-ln-cur .dbg-ln-num {
  color: #a78bfa;
  border-right-color: var(--brand1,#7c3aed);
}
.dbg-ln-cur .dbg-ln-num::before {
  border-color: transparent transparent transparent #a78bfa;
}
.dbg-ln-cur .dbg-ln-text { color: #f1f5f9; }

/* condition true */
@keyframes dbg-true-flash {
  0%   { background: rgba(22,163,74,.45); }
  100% { background: rgba(22,163,74,.14); }
}
.dbg-ln-true { animation: dbg-true-flash .5s ease forwards; }
.dbg-ln-true .dbg-ln-num  { color: #4ade80; border-right-color: #16a34a; }
.dbg-ln-true .dbg-ln-num::before { border-color: transparent transparent transparent #4ade80; }
.dbg-ln-true .dbg-ln-text { color: #bbf7d0; }

/* condition false */
@keyframes dbg-false-flash {
  0%   { background: rgba(220,38,38,.4); }
  100% { background: rgba(220,38,38,.1); }
}
.dbg-ln-false { animation: dbg-false-flash .5s ease forwards; }
.dbg-ln-false .dbg-ln-num  { color: #f87171; border-right-color: #dc2626; }
.dbg-ln-false .dbg-ln-num::before { border-color: transparent transparent transparent #f87171; }
.dbg-ln-false .dbg-ln-text { color: #fecaca; }

/* loop */
@keyframes dbg-loop-flash {
  0%   { background: rgba(59,130,246,.4); }
  100% { background: rgba(59,130,246,.12); }
}
.dbg-ln-loop { animation: dbg-loop-flash .5s ease forwards; }
.dbg-ln-loop .dbg-ln-num  { color: #60a5fa; border-right-color: #3b82f6; }
.dbg-ln-loop .dbg-ln-num::before { border-color: transparent transparent transparent #60a5fa; }
.dbg-ln-loop .dbg-ln-text { color: #bfdbfe; }

/* swap / update special */
@keyframes dbg-swap-flash {
  0%   { background: rgba(234,179,8,.4); }
  100% { background: rgba(234,179,8,.1); }
}
.dbg-ln-swap { animation: dbg-swap-flash .5s ease forwards; }
.dbg-ln-swap .dbg-ln-num  { color: #fde047; border-right-color: #ca8a04; }
.dbg-ln-swap .dbg-ln-num::before { border-color: transparent transparent transparent #fde047; }
.dbg-ln-swap .dbg-ln-text { color: #fef08a; }

.dbg-no-code, .dbg-not-supported {
  color: #334155;
  font-size: 13px;
  padding: 28px 20px;
  line-height: 1.7;
}
.dbg-not-supported strong { color: #64748b; }

/* ================================================================
   Info section (right column)
================================================================ */
.dbg-info-section {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  min-height: 320px;
}

.dbg-tab-bar {
  display: flex;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  overflow-x: auto;
}
.dbg-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #6b7280;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 10px 14px;
  white-space: nowrap;
  text-transform: uppercase;
  transition: color .15s;
}
.dbg-tab:hover { color: #1f2937; }
.dbg-tab.active { color: var(--brand1,#7c3aed); border-bottom-color: var(--brand1,#7c3aed); }

.dbg-tab-pane { display: none; padding: 16px; }
.dbg-tab-active { display: block; }
.dbg-info-section .muted { color: #9ca3af; font-size: 13px; }

/* ================================================================
   Explanation tab
================================================================ */
@keyframes dbg-explain-in {
  from { transform: translateX(14px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
.dbg-explain-card {
  background: #f9fafb;
  border-radius: 8px;
  padding: 14px;
  animation: dbg-explain-in .22s ease;
}
.dbg-explain-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.dbg-explain-ln  { color: #9ca3af; font-size: 12px; margin-left: auto; }
.dbg-explain-code {
  background: #111827;
  border-radius: 6px;
  padding: 9px 13px;
  margin-bottom: 10px;
}
.dbg-explain-code code { color: #e2e8f0; font-family: monospace; font-size: 13px; }
.dbg-explain-text { color: #374151; font-size: 13px; line-height: 1.65; }

/* The site-wide inline-code chip (.sim-wrap code, sim-future.css) bleeds a
   light lavender background onto the debugger's <code> elements — on the dark
   explanation box that left near-white text on a pale chip (unreadable).
   Neutralise it there, and re-assert the intentional condition chips that the
   same global rule was overriding. */
#dbg-panel .dbg-explain-code code {
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  color: #e6edf7 !important;
}
#dbg-panel .dbg-cond-expr {
  background: #1e293b !important; color: #fde68a !important;
  border: 0 !important; padding: 3px 9px !important; border-radius: 4px !important;
}
#dbg-panel .dbg-cond-sub {
  background: #fffbeb !important; color: #78350f !important;
  border: 1px solid #fde68a !important; padding: 3px 9px !important; border-radius: 4px !important;
}

/* step type badges */
.dbg-type-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 5px;
}
.dbg-type-init      { background:#ede9fe; color:#7c3aed; }
.dbg-type-assign    { background:#dbeafe; color:#1d4ed8; }
.dbg-type-loop      { background:#e0f2fe; color:#0369a1; }
.dbg-type-condition { background:#fef9c3; color:#92400e; }
.dbg-type-output    { background:#dcfce7; color:#15803d; }
.dbg-type-idle      { background:#f1f5f9; color:#64748b; }
.dbg-type-select    { background:#fce7f3; color:#9d174d; }
.dbg-type-end       { background:#f0fdf4; color:#166534; }
.dbg-type-step      { background:#f1f5f9; color:#475569; }
.dbg-type-miss      { background:#fee2e2; color:#991b1b; }
.dbg-type-hit       { background:#dcfce7; color:#166534; }
.dbg-type-swap      { background:#fef3c7; color:#92400e; }
.dbg-type-compare   { background:#ede9fe; color:#6d28d9; }
.dbg-type-seek      { background:#fce7f3; color:#9d174d; }
.dbg-type-push      { background:#dcfce7; color:#166534; }
.dbg-type-pop       { background:#fee2e2; color:#991b1b; }
.dbg-type-found     { background:#d1fae5; color:#065f46; }
.dbg-type-not-found { background:#fee2e2; color:#991b1b; }

/* ================================================================
   Variable Watch tab
================================================================ */
.dbg-var-grid { display: flex; flex-direction: column; gap: 5px; }

@keyframes dbg-var-change {
  0%   { background: #fef08a; transform: scale(1.02); }
  60%  { background: #fefce8; transform: scale(1); }
  100% { background: #f8fafc; }
}
.dbg-var-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid #e5e7eb;
}
.dbg-var-changed {
  animation: dbg-var-change .45s ease forwards;
  border-color: #fde047 !important;
}

.dbg-var-name { font-family: monospace; color: #1d4ed8; font-weight: 600; min-width: 80px; }
.dbg-var-val  { display: flex; align-items: center; gap: 5px; }

/* old → new flip */
@keyframes dbg-old-out {
  to { transform: translateY(-8px); opacity: 0; }
}
@keyframes dbg-new-in {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}
.dbg-var-old {
  color: #9ca3af;
  text-decoration: line-through;
  font-family: monospace;
  font-size: 12px;
  animation: dbg-old-out .2s ease forwards;
}
.dbg-var-arrow { color: #f59e0b; font-weight: 700; font-size: 11px; }
.dbg-var-new {
  color: #15803d;
  font-family: monospace;
  font-weight: 600;
  animation: dbg-new-in .25s ease .15s both;
}

/* array value cells (for arr[] variables) */
.dbg-arr-row {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px 0;
}
.dbg-arr-cell {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  min-width: 34px;
  height: 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: 12px;
  position: relative;
}
.dbg-arr-cell.cmp  { background:#ede9fe; border-color:#a78bfa; color:#6d28d9; }
.dbg-arr-cell.swap { background:#fef3c7; border-color:#f59e0b; color:#92400e; }
.dbg-arr-cell.done { background:#dcfce7; border-color:#86efac; color:#15803d; }
.dbg-arr-idx {
  font-size: 9px;
  color: #94a3b8;
  position: absolute;
  bottom: 1px;
  font-family: monospace;
}

/* ================================================================
   Loop Trace tab
================================================================ */
.dbg-loop-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 14px;
}
.dbg-loop-name  { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.dbg-loop-badge { background: #3b82f6; color: #fff; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 4px; }
.dbg-loop-rows  { display: flex; flex-direction: column; gap: 5px; }
.dbg-loop-row   { display: flex; gap: 10px; font-size: 13px; }
.dbg-lr-lbl     { color: #6b7280; min-width: 90px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.dbg-lr-val code { background: #dbeafe; border-radius: 4px; padding: 1px 6px; font-size: 12px; }

/* ================================================================
   Condition tab
================================================================ */
.dbg-cond-card {
  background: #fefce8;
  border: 1px solid #fde047;
  border-radius: 8px;
  padding: 14px;
}
.dbg-cond-row  { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.dbg-cl        { color: #92400e; min-width: 80px; font-size: 11px; font-weight: 700; text-transform: uppercase; margin-top: 2px; }
.dbg-cond-expr { background: #1e293b; color: #fde68a; border-radius: 4px; padding: 3px 9px; font-size: 13px; display: inline-block; }
.dbg-cond-sub  { background: #fffbeb; color: #78350f; border-radius: 4px; padding: 3px 9px; font-size: 13px; border: 1px solid #fde68a; display: inline-block; }
.dbg-cond-result {
  font-size: 14px;
  font-weight: 700;
  padding: 9px 13px;
  border-radius: 6px;
  margin: 8px 0 6px;
}
.dbg-cond-next { font-size: 12px; color: #6b7280; margin-top: 4px; }
.dbg-cond-else { margin-top: 2px; }

.dbg-bool-true  { background:#dcfce7; color:#15803d; border:1px solid #86efac; }
.dbg-bool-false { background:#fee2e2; color:#991b1b; border:1px solid #fca5a5; }

/* ================================================================
   Console / Output tab  — terminal look
================================================================ */
.dbg-console {
  background: #0a0f1a;
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 360px;
  overflow-y: auto;
  min-height: 80px;
  font-family: 'Cascadia Code','Fira Code','Consolas',monospace;
}
.dbg-console-empty { color: #334155; font-size: 13px; font-style: italic; }
.dbg-console-pre   { color: #a3e635; font-size: 13px; white-space: pre-wrap; margin: 0; line-height: 1.8; }

@keyframes dbg-output-line {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dbg-console-line { animation: dbg-output-line .18s ease; }

/* ================================================================
   Debug Mode button on simulator page
================================================================ */
#btnDebugMode {
  margin-top: 6px;
  transition: all .2s;
}
#btnDebugMode.active {
  background: var(--brand1, #7c3aed) !important;
  color: #fff !important;
  border-color: var(--brand1, #7c3aed) !important;
}

/* ================================================================
   Responsive
================================================================ */
@media (max-width: 600px) {
  .dbg-hint { display: none; }
  .dbg-code-scroll { max-height: 300px; }
  .dbg-info-section { min-height: 0; }
  .dbg-step-counter { font-size: 12px; }
}

/* ================================================================
   Header mini buttons (All Steps / Print)
================================================================ */
.dbg-mini-btn {
  background: #ede9fe;
  color: #6d28d9;
  border: 1px solid #ddd6fe;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.dbg-mini-btn:hover { background: #ddd6fe; color: #5b21b6; }
.dbg-mini-btn.active { background: var(--brand1,#7c3aed); color: #fff; border-color: var(--brand1,#7c3aed); }

/* ================================================================
   All-Steps view  — full line-by-line listing
================================================================ */
.dbg-allsteps {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px 16px 8px;
  margin-top: 16px;
}
.dbg-as-title {
  font-size: 14px; font-weight: 700; color: #1e293b;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid #eef2f7;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.dbg-as-langtag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: #6d28d9; background: #ede9fe; border-radius: 4px; padding: 2px 8px;
}
.dbg-as-list { list-style: none; margin: 0; padding: 0; counter-reset: none; }
.dbg-as-item {
  border: 1px solid #eef2f7; border-left: 3px solid #c7d2fe;
  border-radius: 8px; padding: 10px 12px; margin-bottom: 8px;
  break-inside: avoid;
}
.dbg-as-head { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; flex-wrap: wrap; }
.dbg-as-step { font-size: 12px; font-weight: 700; color: #334155; }
.dbg-as-line { font-size: 11px; color: #94a3b8; margin-left: auto; }
#dbg-panel .dbg-as-code {
  background: #0b1220 !important; color: #e6edf7 !important;
  font-family: Consolas, "Cascadia Code", monospace; font-size: 12.5px;
  border: 0; border-radius: 6px; padding: 8px 12px; margin: 0 0 6px;
  white-space: pre-wrap; word-break: break-word;
}
.dbg-as-explain { font-size: 12.5px; color: #374151; line-height: 1.55; }
.dbg-as-vars {
  margin-top: 5px; font-family: Consolas, monospace; font-size: 11.5px;
  color: #b45309; background: #fffbeb; border: 1px solid #fde68a;
  border-radius: 5px; padding: 4px 8px;
}

/* On-screen print fallback: if the browser prints the page directly,
   show only the all-steps list and hide the interactive chrome. */
@media print {
  .sim-input-col, .dbg-controls, .dbg-progress-bar, .dbg-header-right,
  .dbg-main-grid, .sim-nav-bar, .navbar, footer, .no-print { display: none !important; }
  #dbg-panel, .dbg-allsteps { display: block !important; }
  .dbg-allsteps { border: 0; padding: 0; }
}
