:root{--navy:#071d31;--navy2:#0b2843;--ink:#09213d;--cyan:#43ddff;--line:#2b4c68;--gold:#f0bf22;--paper:#eef5fb;--muted:#83baf0;--white:#fff}
*{box-sizing:border-box}body{margin:0;background:linear-gradient(180deg,#f3f8fc,#eaf2f9);color:var(--ink);font-family:Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}.page-shell{max-width:1760px;margin:auto;padding:28px}.hero{display:flex;align-items:flex-start;justify-content:space-between;gap:24px;margin-bottom:22px}.eyebrow{margin:0 0 8px;font-size:14px;font-weight:900;letter-spacing:.14em;color:#2b74b8}.hero h1{font-size:clamp(30px,4vw,52px);margin:0 0 8px;line-height:1.05}.intro{max-width:850px;font-size:18px;color:#45617c;margin:0}.back-link{background:#fff;border:1px solid #c7d8e8;border-radius:12px;padding:12px 16px;text-decoration:none;color:#31516f;font-weight:800}.workspace{display:grid;gap:22px}.editor-card,.trace-lab{background:#fff;border:1px solid #c9d9e7;border-radius:22px;box-shadow:0 18px 45px rgba(27,68,104,.1);overflow:hidden}.editor-card{padding:20px}.section-head,.run-row{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.section-head{margin-bottom:12px;font-size:18px}.step-badge{display:inline-grid;place-items:center;width:28px;height:28px;border-radius:50%;background:var(--gold);color:#071d31;margin-right:8px;font-weight:900}textarea{width:100%;resize:vertical;border:1px solid #bdd2e4;border-radius:14px;background:#061a2b;color:#edf8ff;font:600 15px/1.55 "Cascadia Code","SFMono-Regular",Consolas,monospace;padding:16px;outline:none}#codeInput{min-height:330px}#stdinInput{min-height:78px;margin-top:8px}.input-row{margin-top:16px}.input-row label{font-weight:850}.input-row small{font-weight:600;color:#7189a0}.run-row{justify-content:flex-start;margin-top:16px}.run-row button,.controls button,.section-head button{border:1px solid #2f5676;border-radius:12px;padding:11px 18px;font-weight:900;cursor:pointer}.primary,.gold{background:var(--gold)!important;color:#06182a!important;border-color:var(--gold)!important}.secondary,.controls button{background:#103553;color:#fff}.step-limit{margin-left:auto;font-weight:750;color:#45617c}.step-limit input{width:90px;margin-left:8px;padding:9px;border:1px solid #bdd2e4;border-radius:9px}.support-note{color:#607b94;margin:14px 0 0;font-size:14px}.error-box{margin-top:14px;padding:14px 16px;border-radius:12px;background:#fff0f0;border:1px solid #f2b5b5;color:#992828;font-weight:700}.trace-lab{background:var(--navy);color:white}.trace-toolbar{display:flex;justify-content:space-between;gap:20px;align-items:center;padding:20px 22px;border-bottom:1px solid var(--line)}.trace-toolbar .eyebrow{color:#90c7ff}.trace-toolbar h2{margin:0;font:800 20px Georgia,serif}.trace-toolbar p{margin:5px 0 0;color:#8ecbff}.controls{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}.controls button:disabled{opacity:.35;cursor:not-allowed}.trace-grid{display:grid;grid-template-columns:minmax(0,2fr) minmax(360px,1fr);min-height:520px}.source-pane{background:#031526;border-right:1px solid var(--line);padding:18px 0;max-height:62vh;min-height:480px;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;font:700 16px/1.75 "Cascadia Code",Consolas,monospace}.code-line{display:grid;grid-template-columns:58px 1fr;min-width:max-content;padding-right:24px}.line-no{color:#6b9bc8;text-align:right;padding-right:18px;user-select:none}.line-text{white-space:pre}.code-line.active{background:#154566;border-left:4px solid var(--gold)}.code-line.active .line-no{color:var(--gold);font-weight:900}.state-pane{background:#082238;max-height:62vh;overflow:auto}.state-pane section{padding:18px 20px;border-bottom:1px solid var(--line)}.state-pane h3{margin:0 0 12px;color:var(--cyan);font-size:15px;letter-spacing:.06em}.state-pane p{margin:0;line-height:1.55}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse;font-size:14px}th,td{border:1px solid #31536d;padding:10px;text-align:left}th{color:#85bdf0;background:#0c2d48}.stack-list{display:flex;gap:8px;flex-wrap:wrap}.stack-chip{border:1px solid #3e7198;border-radius:9px;padding:7px 10px;background:#103b5b;font:700 13px Consolas,monospace}.stack-arrow{align-self:center;color:#a8d5f8}pre{margin:0;min-height:100px;background:#031526;padding:16px;border-radius:4px;color:#eeffd8;white-space:pre-wrap;font:700 14px/1.6 Consolas,monospace}.trace-footer{display:flex;align-items:center;gap:16px;padding:12px 18px;background:#0a2a46}.trace-footer progress{flex:1;accent-color:var(--gold)}.trace-footer span{font-weight:800;white-space:nowrap}.flash{animation:flash .6s ease}@keyframes flash{50%{box-shadow:inset 0 0 0 2px var(--gold)}}
@media(max-width:980px){.page-shell{padding:12px}.hero,.trace-toolbar{flex-direction:column;align-items:stretch}.trace-grid{grid-template-columns:1fr}.source-pane{border-right:0;border-bottom:1px solid var(--line);max-height:50vh;min-height:360px}.state-pane{max-height:none}.controls{justify-content:flex-start}.step-limit{margin-left:0}.back-link{align-self:flex-start}}
/* Phase 5: command-line argument field uses the same CodeBhavya tracer treatment. */
.input-row input[type="text"]{width:100%;box-sizing:border-box;background:#061d2d;color:#fff;border:1px solid #37627d;border-radius:10px;padding:12px 14px;font:inherit;outline:none}.input-row input[type="text"]:focus{border-color:#f5c322;box-shadow:0 0 0 2px rgba(245,195,34,.12)}

/* Phase 7: live memory + DSA visualization. */
.visual-title-row{display:flex;align-items:center;justify-content:space-between;gap:10px}.visual-title-row h3{margin-bottom:0}.visual-mode{font-size:11px;font-weight:900;letter-spacing:.08em;border:1px solid #3f7198;background:#103b5b;color:#9ddcff;border-radius:999px;padding:4px 8px}.dsa-visualizer{margin-top:12px;display:grid;gap:14px}.visual-empty{color:#91b9d8!important;font-size:13px}.viz-block{background:#041a2c;border:1px solid #294f6d;border-radius:12px;padding:12px}.viz-block-title{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:10px;color:#d7f5ff;font-size:12px;font-weight:900;letter-spacing:.05em}.viz-subtle{color:#82aeca;font-size:11px;font-weight:700}.pointer-row,.array-row{display:flex;flex-wrap:wrap;gap:7px;align-items:center}.pointer-chip,.array-cell{border:1px solid #3d7198;background:#0d3553;border-radius:8px;padding:7px 9px;font:700 12px "Cascadia Code",Consolas,monospace}.pointer-chip strong{color:#ffd23f}.array-cell{min-width:44px;text-align:center;position:relative}.array-cell .idx{display:block;color:#6ea9d6;font-size:9px;margin-bottom:2px}.heap-grid{display:flex;flex-wrap:wrap;gap:10px}.heap-card{min-width:150px;max-width:260px;border:1px solid #3b6e94;background:#0a304c;border-radius:11px;padding:10px;font:700 11px/1.5 "Cascadia Code",Consolas,monospace}.heap-card.freed{opacity:.55;border-style:dashed}.heap-address{color:#ffd23f;font-weight:900;margin-bottom:5px}.heap-field{display:flex;gap:6px;justify-content:space-between;border-top:1px solid rgba(137,196,235,.14);padding-top:4px;margin-top:4px}.heap-field .field-name{color:#8ddfff}.heap-ref{color:#b8ff9e}.chain{display:flex;align-items:center;gap:8px;overflow:auto;padding-bottom:4px}.chain-node{flex:0 0 auto;min-width:110px;border:2px solid #3f82ad;background:#0b3a59;border-radius:12px;padding:9px;text-align:center}.chain-node .addr{font:800 10px Consolas,monospace;color:#80c8f5}.chain-node .data{font:900 15px Consolas,monospace;color:#fff;margin-top:4px}.chain-arrow{flex:0 0 auto;color:#ffd23f;font-size:22px;font-weight:900}.null-node{flex:0 0 auto;border:1px dashed #6388a2;color:#91aebe;border-radius:8px;padding:7px 10px;font:800 11px Consolas,monospace}.tree-wrap{overflow:auto;padding:4px}.tree-level{display:flex;justify-content:center;gap:20px;margin:10px 0}.tree-node{min-width:88px;background:#0c3b59;border:2px solid #3d84ae;border-radius:50px;padding:9px 12px;text-align:center;font:800 11px Consolas,monospace}.tree-node .tree-data{font-size:14px;color:#fff}.tree-node .tree-addr{font-size:9px;color:#80c8f5}.queue-strip{display:flex;gap:6px;overflow:auto;padding:4px 0}.queue-cell{min-width:54px;border:1px solid #3d7198;background:#0d3553;border-radius:8px;text-align:center;padding:8px 6px;position:relative;font:800 12px Consolas,monospace}.queue-mark{position:absolute;top:-11px;left:50%;transform:translateX(-50%);font-size:8px;color:#ffd23f;font-weight:900;white-space:nowrap}.visual-section{min-height:140px}
@media(max-width:980px){.heap-card{max-width:100%;}.chain-node{min-width:100px}.visual-section{min-height:auto}}


/* Phase 3: arrays and strings visualizer */
.data-visual{display:grid;gap:12px;max-height:330px;overflow:auto;padding-right:4px}
.visual-empty{margin:0;color:var(--muted,#667085);font-size:.9rem}
.visual-card{border:1px solid rgba(98,84,204,.18);border-radius:14px;padding:12px;background:rgba(98,84,204,.035)}
.visual-title{font-weight:800;margin-bottom:9px;font-size:.88rem}
.array-visual,.string-visual{display:flex;gap:7px;overflow-x:auto;padding:2px 1px 7px}
.matrix-visual{display:grid;gap:7px;overflow:auto;padding-bottom:5px}
.matrix-row{display:flex;gap:7px;min-width:max-content}
.array-cell,.char-cell{min-width:52px;border:1px solid rgba(98,84,204,.25);border-radius:10px;background:#fff;text-align:center;overflow:hidden}
.array-cell small,.char-cell small{display:block;font-size:.66rem;padding:3px 5px;background:rgba(98,84,204,.08);color:#6558b7}
.array-cell strong,.char-cell strong{display:block;padding:8px 7px;font-size:.88rem;white-space:nowrap}
.char-cell{min-width:38px}
@media(max-width:760px){.data-visual{max-height:260px}.array-cell{min-width:46px}}


/* Phase 3.1: compact, readable data visualization + shared right-pane space */
/* Use the state-pane as the single vertical scroller; avoid a nested vertical scrollbar. */
.data-visual{
  display:grid;
  gap:8px;
  max-height:none;
  overflow:visible;
  padding-right:0;
}

/* Make the variable table and visualizer compact enough to stay visible together. */
.state-pane section{padding:13px 16px}
.state-pane h3{margin-bottom:8px;font-size:14px}
.state-pane table{font-size:12.5px}
.state-pane th,.state-pane td{padding:7px 8px}

.visual-card{
  border:1px solid #2e5877;
  border-radius:10px;
  padding:9px;
  background:#0a2d49;
  overflow:hidden;
}
.visual-title{
  color:#e9f7ff;
  font-weight:850;
  margin-bottom:7px;
  font-size:.8rem;
}
.array-visual,.string-visual{
  display:flex;
  gap:5px;
  overflow-x:auto;
  overflow-y:hidden;
  padding:1px 1px 5px;
  scrollbar-width:thin;
}
.matrix-visual{
  display:grid;
  gap:5px;
  overflow-x:auto;
  overflow-y:hidden;
  padding-bottom:4px;
}
.matrix-row{gap:5px}

/* Important: Phase 7's generic .array-cell styling was being inherited here.
   Give Java Phase 3 cells explicit readable foreground/background colours. */
.data-visual .array-cell,
.data-visual .char-cell{
  flex:0 0 auto;
  min-width:42px;
  border:1px solid #3e7198;
  border-radius:8px;
  background:#f7fbff;
  color:#102b45;
  text-align:center;
  overflow:hidden;
}
.data-visual .array-cell small,
.data-visual .char-cell small{
  display:block;
  font-size:.60rem;
  line-height:1.1;
  padding:3px 4px;
  background:#eaf2ff;
  color:#6558b7;
}
.data-visual .array-cell strong,
.data-visual .char-cell strong{
  display:block;
  padding:6px 6px;
  min-height:29px;
  font-size:.82rem;
  line-height:1.25;
  color:#102b45;
  white-space:nowrap;
}
.data-visual .char-cell{min-width:34px}

/* Variables first, visualization immediately underneath, so students can compare them. */
.state-pane .table-wrap{max-height:150px;overflow:auto;scrollbar-width:thin}

@media(min-width:1250px){
  .state-pane .table-wrap{max-height:165px}
}
@media(max-width:760px){
  .data-visual{max-height:none}
  .data-visual .array-cell{min-width:40px}
  .state-pane .table-wrap{max-height:180px}
}


/* Phase 3.2: smart focus + change highlighting.
   The right pane follows the variables/visualizer automatically, while each compact
   scroller follows the exact changed row/cell. */
.var-changed td{
  background:#4b3f12 !important;
  color:#fff7c7;
  border-color:#f0bf22 !important;
  animation:statePulse .75s ease;
}
.var-changed td:last-child{
  color:#ffe45c;
  font-weight:900;
}
.visual-card.visual-changed{
  border-color:#f0bf22;
  box-shadow:0 0 0 2px rgba(240,191,34,.18), 0 0 18px rgba(240,191,34,.08);
  animation:statePulse .75s ease;
}
.data-visual .cell-changed{
  border-color:#f0bf22 !important;
  background:#fff4b8 !important;
  box-shadow:0 0 0 2px rgba(240,191,34,.22);
  animation:cellPulse .8s ease;
}
.data-visual .cell-changed small{background:#ffe98e;color:#5f4a00}
.data-visual .cell-changed strong{color:#2f2600;font-weight:950}
@keyframes statePulse{0%{filter:brightness(1.55)}100%{filter:brightness(1)}}
@keyframes cellPulse{0%{transform:scale(1.07)}100%{transform:scale(1)}}

/* Keep enough vertical room for Variables + Visualizer to coexist, without forcing
   the student to manually chase the current state. */
.state-pane .table-wrap{scroll-behavior:smooth}
.data-visual,.array-visual,.string-visual,.matrix-visual{scroll-behavior:smooth}

/* Phase 3.3: keep nested state scrollers from dragging the outer state pane. */
.state-pane .table-wrap,
.data-visual,
.array-visual,
.string-visual,
.matrix-visual{
  overscroll-behavior:contain;
}


/* Phase 3.4: deterministic outer-pane focus.
   Disable browser scroll anchoring so rerendering Variables/Data Visualization cannot
   keep the pane parked near Call Stack/Program Output after Next/Previous/Auto. */
.state-pane,
.state-pane section,
.state-pane .table-wrap,
.data-visual{
  overflow-anchor:none;
}


/* Phase 3.5: adaptive outer-pane following. The pane is allowed to move to the
   currently changed visualization instead of being pinned permanently at top. */
.state-pane{scroll-behavior:smooth}
.visual-card.visual-changed{scroll-margin-block:12px}

/* Phase 4: Java object/heap visualization */
.object-card{background:#082b45;border-color:#3b7196}
.object-title{display:flex;align-items:center;gap:7px;color:#dff6ff}
.object-fields{display:grid;grid-template-columns:repeat(auto-fit,minmax(155px,1fr));gap:7px}
.object-field{display:flex;align-items:center;justify-content:space-between;gap:12px;border:1px solid #315d7d;background:#0a3655;border-radius:8px;padding:8px 10px;font:700 12px/1.35 "Cascadia Code",Consolas,monospace;min-width:0}
.object-field-name{color:#8edfff;white-space:nowrap}
.object-field-value{color:#fff;text-align:right;overflow-wrap:anywhere}
.object-field.field-changed{border-color:#f0bf22;background:#4b3f12;box-shadow:0 0 0 2px rgba(240,191,34,.18);animation:statePulse .75s ease}
.object-field.field-changed .object-field-name{color:#ffe47a}
.object-field.field-changed .object-field-value{color:#fff3a8}
.object-empty{color:#91b9d8;font-size:12px}
@media(min-width:1180px){.trace-grid{grid-template-columns:minmax(0,1.65fr) minmax(500px,1.05fr)}}

/* Phase 5: collections and maps visualization */
.collection-visual{display:flex;gap:8px;align-items:stretch;overflow-x:auto;padding:5px 2px 8px;scroll-behavior:smooth}
.collection-cell{min-width:64px;border:1px solid #4a7da0;background:#0d3653;border-radius:10px;padding:8px 10px;text-align:center;font:800 12px/1.3 "Cascadia Code",Consolas,monospace}
.collection-cell small{display:block;color:#86b9e6;font-size:9px;margin-bottom:4px}.collection-cell strong{color:#fff;font-size:14px}
.map-visual{display:flex;flex-wrap:wrap;gap:8px}.map-entry{display:flex;align-items:center;gap:7px;border:1px solid #4a7da0;background:#0d3653;border-radius:10px;padding:9px 11px;font:800 12px "Cascadia Code",Consolas,monospace}.map-key{color:#8be9fd}.map-arrow{color:#ffd85c}.map-entry strong{color:#fff}
.collection-cell.cell-changed,.map-entry.cell-changed{background:#f7df7c!important;color:#2f2600!important;border-color:#f0bf22!important;box-shadow:0 0 0 2px rgba(240,191,34,.18)}
.collection-cell.cell-changed small,.map-entry.cell-changed .map-key,.map-entry.cell-changed strong{color:#2f2600!important}

/* Phase 6: DSA-aware visualization — linked lists, stacks/queues, trees, graphs and array index markers. */
.dsa-card{background:#061f34;border-color:#376b8f}
.dsa-strip,.linked-chain{display:flex;align-items:center;gap:9px;overflow-x:auto;padding:22px 3px 8px;scroll-behavior:smooth;overscroll-behavior:contain}
.dsa-cell,.linked-node{position:relative;flex:0 0 auto;min-width:72px;border:2px solid #3e82ac;background:#0c3b5a;border-radius:10px;padding:9px 10px;text-align:center;font:800 12px/1.3 "Cascadia Code",Consolas,monospace}
.dsa-cell small,.linked-node small{display:block;color:#82c9f4;font-size:9px;margin-bottom:4px}.dsa-cell strong,.linked-node strong{color:#fff;font-size:14px}
.dsa-cell[data-badge]::before{content:attr(data-badge);position:absolute;left:50%;bottom:calc(100% + 5px);transform:translateX(-50%);padding:3px 7px;border-radius:999px;background:#ffd85c;color:#2c2200;border:1px solid #fff0ae;font:900 8px/1 Arial,sans-serif;white-space:nowrap}
.dsa-arrow{flex:0 0 auto;color:#ffd85c;font-size:20px;font-weight:950}
.null-node{flex:0 0 auto;border:1px dashed #6d99b7;color:#9cc6df;border-radius:9px;padding:8px 11px;font:800 11px Consolas,monospace}
.tree-levels{overflow:auto;padding:5px 2px}.tree-level{display:flex;justify-content:center;gap:20px;margin:10px 0;min-width:max-content}.tree-node{min-width:92px;background:#0c3b59;border:2px solid #3d84ae;border-radius:50px;padding:9px 12px;text-align:center;font:800 11px Consolas,monospace}.tree-node small{display:block;color:#80c8f5;font-size:8px}.tree-node strong{color:#fff;font-size:14px}.tree-node.ghost{opacity:.28;border-style:dashed}
.adjacency-list{display:grid;gap:7px}.adj-row{display:grid;grid-template-columns:minmax(52px,auto) 28px 1fr;gap:8px;align-items:center;border:1px solid #315d7d;background:#0a3655;border-radius:9px;padding:8px 10px;font:800 12px Consolas,monospace}.adj-row strong{color:#8be9fd}.adj-row span:nth-child(2){color:#ffd85c;text-align:center}.adj-row span:last-child{color:#fff;overflow-wrap:anywhere}
.algorithm-note{display:inline-flex;margin:0 0 8px;padding:5px 8px;border-radius:8px;border:1px solid rgba(91,169,219,.28);background:rgba(65,146,196,.11);color:#a9e2ff;font:800 10px/1.2 Consolas,monospace}
.array-visual{padding-top:29px!important;overflow-y:visible!important}
.array-cell{position:relative;overflow:visible!important;border-width:2px!important}
.array-cell.range-active{border-color:#49bdf1!important;background:#e7f7ff!important;box-shadow:0 0 0 2px rgba(73,189,241,.18)}
.array-cell.marker-target{border-color:#58ccff!important;box-shadow:0 0 0 2px rgba(88,204,255,.24)}
.index-markers{position:absolute;left:50%;bottom:calc(100% + 5px);transform:translateX(-50%);display:flex;gap:3px;justify-content:center;white-space:nowrap;z-index:3}
.index-marker{display:inline-flex;align-items:center;justify-content:center;min-width:22px;padding:3px 6px;border-radius:999px;background:#8be9fd;color:#072336;border:1px solid #c7fbff;font:900 8px/1 Arial,sans-serif;box-shadow:0 2px 6px rgba(0,0,0,.22)}
.index-marker.marker-low,.index-marker.marker-high,.index-marker.marker-mid,.index-marker.marker-pi,.index-marker.marker-pivotindex,.index-marker.marker-smallest,.index-marker.marker-largest{background:#ffd761;color:#312400;border-color:#fff0b4}
.index-marker.marker-front,.index-marker.marker-rear,.index-marker.marker-top{background:#98f5a5;color:#0f2e17;border-color:#d1ffd6}
@media(min-width:1180px){.trace-grid{grid-template-columns:minmax(0,1.55fr) minmax(540px,1.1fr)}}


/* CodeBhavya numbered source editor: line numbers remain aligned while students type/scroll. */
.code-editor-numbered{
  display:flex;
  align-items:stretch;
  width:100%;
  overflow:hidden;
  border:1px solid #bdd2e4;
  border-radius:14px;
  background:#061a2b;
}
.code-editor-numbered:focus-within{
  border-color:#5aa7df;
  box-shadow:0 0 0 2px rgba(90,167,223,.12);
}
.code-editor-numbered #codeInput{
  flex:1 1 auto;
  min-width:0;
  width:auto;
  margin:0;
  border:0!important;
  border-radius:0!important;
  outline:0!important;
  box-shadow:none!important;
  background:#061a2b!important;
  overflow:auto;
  white-space:pre;
}
.code-line-numbers{
  flex:0 0 auto;
  min-width:54px;
  height:auto;
  overflow:hidden;
  padding:16px 10px 16px 6px;
  border-right:1px solid #284964;
  background:#071d31;
  color:#6fa8d7;
  text-align:right;
  user-select:none;
  pointer-events:none;
  font:700 15px/1.55 "Cascadia Code","SFMono-Regular",Consolas,monospace;
}
.code-line-number{
  display:block;
  height:1.55em;
  line-height:1.55em;
  padding:0 5px;
  border-radius:5px;
}
.code-line-number.error-line{
  background:#7b2630;
  color:#fff4f4;
  font-weight:950;
  box-shadow:inset 3px 0 0 #ff5b69;
}
@media(max-width:700px){
  .code-line-numbers{min-width:44px;padding-left:3px;padding-right:7px;font-size:13px}
  .code-editor-numbered #codeInput{font-size:13px}
}
