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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 15px 20px;
    color: #333;
}

h2 {
    text-align: center;
    color: white;
    margin-bottom: 20px;
    font-size: 28px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.container {
    display: flex;
    gap: 20px;
    max-width: 1300px;
    margin: 0 auto;
    align-items: flex-start;
    justify-content: center;
}

.controls {
    flex: 0 0 280px;
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.canvas-container {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
}

.right-panel {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.info-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.control-group {
    margin-bottom: 18px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e5e7eb;
}

.control-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.control-group h3 {
    color: #6b21a8;
    margin-bottom: 12px;
    font-size: 16px;
}

label {
    color: #4b5563;
    margin-right: 10px;
    font-weight: 500;
    display: block;
    margin-bottom: 8px;
}

input[type="number"] {
    padding: 6px 10px;
    border: 2px solid #a78bfa;
    border-radius: 6px;
    background: white;
    width: 80px;
    font-size: 14px;
    transition: border-color 0.3s;
}

input[type="number"]:focus {
    outline: none;
    border-color: #60a5fa;
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #60a5fa;
    margin-right: 8px;
    vertical-align: middle;
}

button {
    padding: 10px 18px;
    margin: 4px 4px 4px 0;
    border: none;
    border-radius: 6px;
    background: #8b5cf6;
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    width: 100%;
}

button:hover:not(:disabled) {
    background: #7c3aed;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.algo-btn {
    background: #3b82f6;
}

.algo-btn:hover:not(:disabled) {
    background: #2563eb;
}

.algo-btn.selected {
    background: #1e40af;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#cpBtn {
    background: #06b6d4;
}

#cpBtn:hover:not(:disabled) {
    background: #0891b2;
}

#cpBtn.selected {
    background: #0e7490;
}

#generateBtn {
    background: #8b5cf6;
}

#generateBtn:hover {
    background: #7c3aed;
}

#resetBtn {
    background: #a78bfa;
}

#resetBtn:hover {
    background: #8b5cf6;
}

#clearBtn {
    background: #6366f1;
}

#clearBtn:hover {
    background: #4f46e5;
}

#distanceLabel {
    display: block;
    background: #ede9fe;
    padding: 10px 12px;
    border-radius: 6px;
    color: #6b21a8;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 13px;
}

#stepControls {
    margin-top: 10px;
    display: flex;
    gap: 8px;
}

#stepControls button {
    flex: 1;
    padding: 8px 8px;
    font-size: 13px;
}

canvas {
    background: white;
    border: 3px solid #a78bfa;
    border-radius: 10px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    display: block;
    cursor: crosshair;
}

.canvas-info {
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.canvas-info p {
    text-align: center;
    color: #4b5563;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 6px;
}

.canvas-info p:last-child {
    margin-bottom: 0;
}

.canvas-info strong {
    color: #6b21a8;
}

.info {
    background: #f3f4f6;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
}

.info p {
    text-align: left;
    color: #4b5563;
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 6px;
}

.info p:last-child {
    margin-bottom: 0;
}

.info strong {
    color: #6b21a8;
}

#coordDisplay {
    background: #ede9fe;
    padding: 10px;
    border-radius: 6px;
    color: #6b21a8;
    font-weight: 500;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 13px;
}

.info-box p {
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 60px 24px 80px;
}

header {
    text-align: center;
    margin-bottom: 56px;
}

header h1 {
    font-size: clamp(24px, 5vw, 42px);
    color: white;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    margin-bottom: 10px;
}

header p {
    color: rgba(255, 255, 255, 0.75);
    font-size: 14px;
}

.section-label {
    width: 100%;
    max-width: 860px;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    margin: 28px 0 12px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 860px;
}

.card {
    display: block;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 24px 24px 20px;
    text-decoration: none;
    color: #333;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.card::after {
    content: '→';
    position: absolute;
    bottom: 18px;
    right: 20px;
    font-size: 18px;
    color: #8b5cf6;
    opacity: 0;
    transform: translateX(-6px);
    transition: opacity 0.2s, transform 0.2s;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 14px 24px rgba(0, 0, 0, 0.3);
}

.card:hover::after {
    opacity: 1;
    transform: translateX(0);
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: #6b21a8;
    margin-bottom: 4px;
}

.card-sub {
    font-size: 12px;
    color: #9ca3af;
}

footer {
    margin-top: 72px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
}

body {
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      padding: 20px;
      gap: 16px;
    }

    h2 { margin-bottom: 4px; }

    .layout {
      display: flex;
      gap: 20px;
      flex: 1;
      align-items: stretch;
      min-height: 0;
    }

    /* ── sidebar ── */
    .controls {
      flex: 0 0 240px;
      display: flex;
      flex-direction: column;
      gap: 0;
      /* inherits .controls styles from style.css */
    }

    .controls .control-group {
      margin-bottom: 16px;
      padding-bottom: 14px;
    }

    .controls label {
      font-size: 13px;
      margin-bottom: 6px;
    }

    input[type="range"] {
      width: 100%;
      accent-color: #8b5cf6;
      cursor: pointer;
    }

    .checkbox-group label {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 0;
    }

    .buttons {
      display: flex;
      flex-direction: column;
      gap: 8px;
      border-bottom: none !important;
      margin-bottom: 0 !important;
      padding-bottom: 0 !important;
    }

    .buttons button { margin: 0; width: 100%; }

    #btn-solve { background: #3b82f6; }
    #btn-solve:hover:not(:disabled) { background: #2563eb; }

    /* ── visualizer panel ── */
    #visualizer {
      flex: 1;
      background: white;
      border: 3px solid #a78bfa;
      border-radius: 10px;
      box-shadow: 0 8px 16px rgba(0,0,0,0.3);
      display: flex;
      align-items: flex-end;
      gap: 1px;
      padding: 8px 8px 0;
      overflow: hidden;
      min-height: 400px;
      position: relative;
    }

    /* DOM bar mode */
    .bar {
      flex: 1;
      min-width: 2px;
      background: #8b5cf6;
      border-radius: 2px 2px 0 0;
      transition: background 0.05s;
    }

    .bar[data-state="comparing"] { background: #f59e0b; }
    .bar[data-state="minimum"]   { background: #ef4444; }
    .bar[data-state="pivot"]     { background: #a855f7; }
    .bar[data-state="sorted"]    { background: #22c55e; }

    /* canvas mode fills the container */
    #visualizer canvas {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      border: none;
      border-radius: 0;
      box-shadow: none;
      cursor: default;
    }

    /* legend */
    .legend {
      display: flex;
      gap: 14px;
      flex-wrap: wrap;
      font-size: 12px;
      color: rgba(255,255,255,0.8);
    }

    .legend-item {
      display: flex;
      align-items: center;
      gap: 5px;
    }

    .legend-dot {
      width: 10px;
      height: 10px;
      border-radius: 2px;
    }