:root {
  --bg: #eef7fb;
  --panel: #fff;
  --accent: #1d4ed8;
  --danger: #dc2626;
  --primary: #0b5ed7;
  --merge: #10b981;
  --split: #3b82f6
}

html,
body {
  height: 100%;
  margin: 0
}

body {
  font-family: Arial, sans-serif;
  font-size: 13px;
  background: #c4e1f7
}



header {
  padding: 10px;
  text-align: center
}

header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700
}

.hidden {
  display: none !important
}

/* === LAYOUT === */
.layout {
  display: grid;
  grid-template-columns: 250px 1fr 280px;
  gap: 12px;
  padding: 4px 24px;
  box-sizing: border-box;
  height: calc(100vh - 60px)
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(15, 23, 42, .06);
  box-shadow: 0 6px 12px rgba(15, 23, 42, .04);
  padding: 12px;
  border-radius: 10px;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column
}

.panel h2 {
  font-size: 15px;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e5e7eb;
  flex-shrink: 0
}

/* LEFT */
.left label,
.left select {
  display: block;
  margin: 6px 0
}

.left select,
#nRange,
#arrayType,
#algoSelect,
#customArrayInput {
  width: 96%;
  padding: 5px;
  border-radius: 4px;
  border: 1px solid #ccc
}

.bottom-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px
}

.run-btn {
  flex: 1;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 10px;
  text-align: center
}

/* BUTTONS */
.btn {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #c0c0ed;
  cursor: pointer;
  font-weight: 600;
  transition: transform .2s, box-shadow .2s, filter .2s
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .15);
  filter: brightness(1.05)
}

.btn:active {
  transform: translateY(0)
}

.btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary)
}

.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger)
}

/* CENTER */
.center {
  min-height: 0
}

.originalArrayBox {
  background: #f8fafc;
  border: 2px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  flex-shrink: 0
}

.originalArrayBox h3 {
  margin: 0 0 3px;
  font-size: 13px;
  color: #475569
}

.arrayDisplay {
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
  font-family: 'Courier New', monospace
}

/* Tree heading (inside tree-container) */
.tree-heading {
  font-size: 16px;
  font-weight: 800;
  color: #1e293b;
  text-align: center;
  padding: 4px 0;
  /* Tightened */
  letter-spacing: 0.3px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 4px
    /* Tightened */
}

/* Button row - centered, equal width */
.btn-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-shrink: 0
}

.step-btn {
  min-width: 100px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700
}

.stepInfo {
  font-weight: 700;
  font-size: 13px;
  color: #475569;
  white-space: nowrap;
  margin-left: 6px
}

.autoRun-wrapper {
  position: relative;
  display: inline-block
}

.speed-menu {
  position: absolute;
  top: 40px;
  left: 0;
  width: 100px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
  display: flex;
  flex-direction: column;
  z-index: 100
}

.speed-menu button {
  padding: 8px;
  font-size: 13px;
  background: none;
  border: none;
  cursor: pointer;
  font-weight: 600;
  text-align: center
}

.speed-menu button:hover {
  background: #f1f5f9
}

.speed-menu button:first-child {
  border-radius: 8px 8px 0 0
}

.speed-menu button:last-child {
  border-radius: 0 0 8px 8px
}

/* OP DETAIL - yellow/gold prominent */
.op-detail {
  background: #fffbeb;
  border: 3px solid #f59e0b;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 6px;
  flex-shrink: 0;
  min-height: 50px;
  box-shadow: 0 2px 8px rgba(245, 158, 11, .15)
}

.op-label {
  font-size: 14px;
  font-weight: 800;
  color: #92400e;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px
}

.op-cells {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 6px;
  font-family: 'Courier New', monospace
}

.op-cell-wrapper {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px
}

.op-cell-top-label {
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  min-height: 14px;
  white-space: nowrap;
  color: #64748b;
  text-shadow: 0 0 1px currentColor;
}

.op-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  border: 2px solid #cbd5e1;
  border-radius: 5px;
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  background: #fff
}

.op-cell.hl-pivot {
  border-color: #d97706;
  background: #fef3c7;
  color: #92400e;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, .3)
}

.op-cell.hl-left {
  border-color: #2563eb;
  background: #dbeafe;
  color: #1e40af
}

.op-cell.hl-right {
  border-color: #059669;
  background: #d1fae5;
  color: #065f46
}

.op-cell.hl-swap {
  border-color: #dc2626;
  background: #fee2e2;
  color: #991b1b;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, .3)
}

.op-cell.hl-compare {
  border-color: #f97316;
  background: #ffedd5;
  color: #9a3412
}

.op-cell.hl-placed {
  border-color: #059669;
  background: #d1fae5;
  color: #065f46
}

.op-cell.hl-dim {
  opacity: 0.4;
  border-style: dashed;
}

.op-separator {
  color: #64748b;
  font-size: 20px;
  font-weight: 800;
  margin: 0 6px;
  align-self: flex-end;
  padding-bottom: 6px
}

/* TREE */
.tree-container {
  flex: 1;
  overflow: auto;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  min-height: 0
}

.tree-canvas {
  min-width: 100%;
  position: relative;
  padding: 8px 10px 16px;
  /* Tightened */
  box-sizing: border-box
}

.tree-level {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 4px;
  position: relative;
  padding-right: 80px
}

.tree-node {
  display: inline-flex;
  border: 2px solid #94a3b8;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
  transition: all .3s
}

.tree-node.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, .25)
}

.tree-node.merged {
  border-color: var(--merge);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .2)
}

.tree-cell {
  min-width: 32px;
  padding: 6px 4px;
  text-align: center;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 14px;
  color: #1e293b;
  border-right: 1px solid #e2e8f0
}

.tree-cell:last-child {
  border-right: none
}

/* Arrows row - each pair wraps under its parent */
.tree-arrows-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 2px 0;
  padding-right: 80px
}

.tree-arrow-pair {
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  color: #94a3b8;
  font-size: 20px;
  font-weight: 400
}

/* Phase tags */
.phase-tag {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 4px 6px;
  border-radius: 5px;
  min-width: 72px;
  text-align: center;
  white-space: nowrap
}

.phase-tag.ph-split {
  color: #2563eb;
  background: #dbeafe
}

.phase-tag.ph-partition {
  color: #7c3aed;
  background: #ede9fe
}

.phase-tag.ph-compare {
  color: #ea580c;
  background: #fff7ed
}

.phase-tag.ph-swap {
  color: #dc2626;
  background: #fef2f2
}

.phase-tag.ph-merge {
  color: #0d9488;
  background: #ccfbf1
}

.phase-tag.ph-sorted {
  color: #059669;
  background: #d1fae5
}

.phase-tag.ph-final {
  color: #047857;
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  font-size: 11px;
  padding: 5px 10px;
  box-shadow: 0 2px 6px rgba(5, 150, 105, .2)
}

.tree-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: #94a3b8;
  font-size: 14px;
  font-style: italic
}

/* RIGHT: PSEUDOCODE */
.right {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pseudo-box {
  flex: 2;
  /* Take more space */
  max-height: 420px;
  overflow-y: auto;
  overflow-x: auto;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  background: #fdfdfd;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  /* Slightly larger for clarity */
  line-height: 1.5;
  color: #1e293b;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

/* Custom scrollbar for pseudo-box */
.pseudo-box::-webkit-scrollbar {
  width: 6px;
  height: 6px;
  /* For horizontal */
}

.pseudo-box::-webkit-scrollbar-track {
  background: #f1f5f9;
}

.pseudo-box::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.pseudo-line {
  display: flex;
  align-items: flex-start;
  position: relative;
  min-height: 1.4em;
  /* Fix for overlapping line numbers */
  padding: 1px 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.pseudo-line span.ln {
  min-width: 20px;
  text-align: right;
  padding-right: 12px;
  color: #94a3b8;
  font-size: 11px;
  font-weight: normal;
  flex-shrink: 0;
  user-select: none;
}

.pseudo-content {
  white-space: pre;
  /* Keep spaces exactly */
  font-size: 13px;
  color: #334155;
}

.pseudo-line.highlight {
  background: #fef9c3;
  /* Soft yellow highlight */
  color: #000;
  font-weight: 700;
  box-shadow: 3px 0 0 #f59e0b inset;
}

.pseudo-arrow {
  position: absolute;
  left: -8px;
  top: 1px;
  color: #f59e0b;
  font-size: 14px;
  display: none;
}

.pseudo-line.highlight .pseudo-arrow {
  display: inline;
}

/* Facts & Analysis - reduced and moved to bottom */
.facts {
  flex: 0 1 180px;
  /* Reduced fixed height */
  margin-top: 0;
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid #e2e8f0;
  overflow-y: auto;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.facts h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: #475569;
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 4px;
}



@media(max-width:1000px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto
  }

  .panel {
    height: auto;
    max-height: 80vh
  }

  .graph-modal {
    width: 95%
  }
}