/* ========================================
   Code Kitchen — Kitchen-Themed Styles
   ======================================== */

:root {
    --bg-warm:       #fff6e5;
    --card-white:    #fffaf0;
    --accent-red:    #c0392b;
    --accent-yellow: #f1c40f;
    --text-dark:     #3b2414;
    --text-mid:      #6b4c30;
    --success-green: #3c8d40;
    --error-red:     #8e1b13;
    --debug-brown:   #e8cfa3;
    --border-light:  #d4b483;
    --shadow:        rgba(59, 36, 20, 0.12);
    --radius:        18px;
    --radius-sm:     12px;
    --accent-blue:   #2980b9;
    --accent-purple: #8e44ad;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--bg-warm);
    color: var(--text-dark);
    font-family: 'Inter', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.hidden {
    display: none !important;
}

/* ---- App Shell ---- */

.app-shell {
    max-width: 1360px;
    margin: 0 auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---- Header ---- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 20px;
    border-bottom: 2px dashed var(--debug-brown);
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chef-hat-icon {
    flex-shrink: 0;
}

.app-header h1 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 2rem;
    margin: 0;
    color: var(--accent-red);
    letter-spacing: -0.5px;
}

.tagline {
    margin: 2px 0 0;
    font-size: 0.95rem;
    color: var(--text-mid);
    font-style: italic;
}

.example-select {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.9rem;
    padding: 10px 16px;
    border: 2px solid var(--debug-brown);
    border-radius: 999px;
    background: var(--card-white);
    color: var(--text-dark);
    cursor: pointer;
    transition: border-color 0.2s;
}

.example-select:hover,
.example-select:focus {
    border-color: var(--accent-red);
    outline: none;
}

/* ---- Kitchen Layout ---- */

.kitchen-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    flex: 1;
}

/* ---- Panels ---- */

.panel {
    background: var(--card-white);
    border: 2px solid var(--debug-brown);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: 0 8px 24px var(--shadow);
    transition: box-shadow 0.2s, border-color 0.3s, transform 0.3s;
}

.panel:hover {
    box-shadow: 0 10px 30px rgba(59, 36, 20, 0.16);
}

.panel-highlight {
    border-color: var(--accent-red) !important;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15), 0 8px 24px var(--shadow) !important;
    transform: scale(1.01);
}

.panel-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 600;
    font-size: 1.15rem;
    margin: 0 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-dark);
}

.panel-title.small {
    font-size: 1rem;
    margin-bottom: 10px;
}

.panel-title svg {
    color: var(--accent-red);
    flex-shrink: 0;
}

/* ---- Recipe Editor ---- */

.recipe-card {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.recipe-editor {
    font-family: 'JetBrains Mono', Consolas, Monaco, monospace;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-dark);
    background: var(--card-white);
    border: 2px solid var(--debug-brown);
    border-radius: var(--radius-sm);
    padding: 18px;
    resize: vertical;
    min-height: 350px;
    flex: 1;
    width: 100%;
    transition: border-color 0.2s;
}

.recipe-editor:focus {
    outline: none;
    border-color: var(--accent-red);
    box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}

.recipe-editor::placeholder {
    color: #b89f7a;
    font-style: italic;
}

/* ---- Buttons ---- */

.button-bar {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn {
    font-family: 'Inter', Arial, sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 11px 22px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn:focus-visible {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 2px;
}

.btn.primary {
    background: var(--accent-red);
    color: #fff;
    box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3);
}

.btn.primary:hover {
    background: var(--error-red);
    box-shadow: 0 6px 18px rgba(142, 27, 19, 0.35);
}

.btn.primary.cooking {
    background: var(--accent-yellow);
    color: var(--text-dark);
    pointer-events: none;
}

.btn.secondary {
    background: var(--debug-brown);
    color: var(--text-dark);
}

.btn.secondary:hover {
    background: #d4b483;
}

.btn.ghost {
    background: transparent;
    color: var(--text-mid);
    border: 2px solid var(--debug-brown);
}

.btn.ghost:hover {
    background: var(--debug-brown);
    color: var(--text-dark);
}

/* ==================================
   Step Player
   ================================== */

.step-player {
    background: var(--card-white);
    border: 2px solid var(--accent-red);
    border-radius: var(--radius);
    padding: 16px 20px;
    box-shadow: 0 8px 24px var(--shadow);
    animation: fadeIn 0.3s ease both;
}

.step-player-header {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.step-label {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-red);
    min-width: 110px;
}

.step-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}

.btn-step {
    background: var(--bg-warm);
    border: 2px solid var(--debug-brown);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-dark);
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
}

.btn-step:hover {
    background: var(--debug-brown);
    border-color: var(--border-light);
}

.btn-step:active {
    transform: scale(0.93);
}

.btn-step:focus-visible {
    outline: 3px solid var(--accent-yellow);
    outline-offset: 1px;
}

.btn-play {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-red);
    border-color: var(--accent-red);
    color: #fff;
}

.btn-play:hover {
    background: var(--error-red);
    border-color: var(--error-red);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.speed-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-mid);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.speed-slider {
    width: 80px;
    accent-color: var(--accent-red);
    cursor: pointer;
}

.speed-value {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dark);
    min-width: 32px;
}

/* Progress track */

.step-progress-track {
    height: 4px;
    background: var(--debug-brown);
    border-radius: 2px;
    margin: 12px 0;
    overflow: hidden;
}

.step-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-red), var(--accent-yellow));
    border-radius: 2px;
    width: 0%;
    transition: width 0.4s ease;
}

/* Current command display */

.step-command {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.85rem;
    padding: 10px 14px;
    background: var(--bg-warm);
    border-radius: 8px;
    border: 1px solid var(--debug-brown);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    min-height: 40px;
}

.step-command-text {
    color: var(--text-dark);
}

.step-type-badge {
    display: inline-block;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 10px;
    border-radius: 999px;
    flex-shrink: 0;
}

.step-type-push        { background: #d4efdf; color: #1e7e34; }
.step-type-pop         { background: #fadbd8; color: #922b21; }
.step-type-modify_top  { background: #fef9e7; color: #9a7d0a; }
.step-type-liquefy     { background: #d6eaf8; color: #1b4f72; }
.step-type-liquefy_single { background: #d6eaf8; color: #1b4f72; }
.step-type-stir        { background: #f5eef8; color: #6c3483; }
.step-type-pour        { background: #fdebd0; color: #935116; }
.step-type-clean       { background: #f2f3f4; color: #566573; }
.step-type-halt        { background: #d5f5e3; color: #196f3d; }
.step-type-load_ingredients { background: #e8daef; color: #6c3483; }

/* ---- Output Panel ---- */

.output-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.output-panel {
    background: linear-gradient(135deg, var(--card-white) 0%, #fef9ed 100%);
}

.output-content {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 1.1rem;
    min-height: 60px;
    padding: 16px;
    background: var(--bg-warm);
    border-radius: var(--radius-sm);
    border: 2px dashed var(--debug-brown);
    word-break: break-word;
    white-space: pre-wrap;
}

.output-content.has-output {
    border-style: solid;
    border-color: var(--success-green);
    background: #f0f9f0;
}

.output-content .served-text {
    color: var(--text-dark);
    font-weight: 500;
}

.output-content .success-label {
    display: block;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--success-green);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

/* ---- Debug Grid ---- */

.debug-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.debug-panel {
    background: linear-gradient(180deg, var(--card-white) 0%, #faf3e4 100%);
    padding: 16px;
    border-radius: var(--radius-sm);
}

.debug-content {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    max-height: 260px;
    overflow-y: auto;
    padding: 10px;
    background: rgba(232, 207, 163, 0.2);
    border-radius: 8px;
    word-break: break-word;
}

.debug-content.log-content {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.8rem;
}

.empty-state {
    color: #b89f7a;
    font-style: italic;
    margin: 0;
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.85rem;
}

/* ---- Debug Tables ---- */

.debug-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.debug-table th,
.debug-table td {
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid var(--debug-brown);
}

.debug-table th {
    font-weight: 600;
    color: var(--text-mid);
    font-family: 'Inter', Arial, sans-serif;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.5px;
}

/* ---- Stack List ---- */

.stack-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column-reverse;
}

.stack-list li {
    padding: 5px 8px;
    border-bottom: 1px solid rgba(232, 207, 163, 0.5);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.3s, transform 0.3s;
    border-radius: 4px;
}

.stack-list li:last-child {
    border-bottom: none;
}

.stack-index {
    color: var(--text-mid);
    font-size: 0.72rem;
    min-width: 24px;
    opacity: 0.7;
}

.stack-value {
    font-weight: 600;
    font-size: 0.9rem;
}

.stack-top-label {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fff;
    background: var(--accent-red);
    padding: 1px 6px;
    border-radius: 999px;
    margin-left: auto;
}

/* ---- Log List ---- */

.log-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.log-list li {
    padding: 3px 0;
    border-bottom: 1px solid rgba(232, 207, 163, 0.3);
    color: var(--text-mid);
    transition: background 0.3s, color 0.3s;
}

.log-list li:last-child {
    border-bottom: none;
}

.log-list li.log-current {
    background: rgba(192, 57, 43, 0.08);
    color: var(--text-dark);
    font-weight: 500;
    border-radius: 4px;
    padding: 4px 6px;
}

.log-step {
    color: var(--accent-red);
    font-weight: 600;
    margin-right: 6px;
    font-size: 0.75rem;
}

/* ==================================
   Toast Notifications
   ================================== */

.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    gap: 10px;
    max-width: 560px;
    width: calc(100% - 48px);
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: var(--card-white);
    border: 2px solid var(--debug-brown);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    box-shadow: 0 12px 36px rgba(59, 36, 20, 0.2);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.35s ease;
}

.toast-enter {
    opacity: 0;
    transform: translateY(24px) scale(0.95);
}

.toast-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.toast-exit {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
}

.toast-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.toast-badge {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 10px;
    border-radius: 999px;
}

.toast-badge-info      { background: var(--debug-brown); color: var(--text-dark); }
.toast-badge-stack     { background: #d4efdf; color: #1e7e34; }
.toast-badge-arithmetic { background: #fef9e7; color: #9a7d0a; }
.toast-badge-liquefy   { background: #d6eaf8; color: #1b4f72; }
.toast-badge-pour      { background: #fdebd0; color: #935116; }
.toast-badge-clean     { background: #f2f3f4; color: #566573; }
.toast-badge-success   { background: #d5f5e3; color: #196f3d; }

.toast-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-mid);
    padding: 0 4px;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

.toast-body {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-dark);
}

/* Toast type borders */
.toast-stack     { border-left: 4px solid var(--success-green); }
.toast-arithmetic { border-left: 4px solid var(--accent-yellow); }
.toast-liquefy   { border-left: 4px solid var(--accent-blue); }
.toast-pour      { border-left: 4px solid #e67e22; }
.toast-clean     { border-left: 4px solid #95a5a6; }
.toast-success   { border-left: 4px solid var(--success-green); }
.toast-info      { border-left: 4px solid var(--debug-brown); }

/* ==================================
   Stack Item Animations
   ================================== */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.92);
        background: rgba(60, 141, 64, 0.2);
    }
    60% {
        opacity: 1;
        transform: translateY(2px) scale(1.03);
        background: rgba(60, 141, 64, 0.2);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        background: transparent;
    }
}

.anim-slide-in {
    animation: slideIn 0.6s ease both;
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

.anim-slide-out {
    animation: slideOut 0.4s ease both;
}

@keyframes flash {
    0%   { background: transparent; }
    20%  { background: rgba(241, 196, 15, 0.35); transform: scale(1.04); }
    50%  { background: rgba(241, 196, 15, 0.2); }
    100% { background: transparent; transform: scale(1); }
}

.anim-flash {
    animation: flash 0.7s ease both;
}

@keyframes liquefy {
    0%   { background: transparent; }
    15%  { background: rgba(41, 128, 185, 0.2); transform: scale(1.02); }
    30%  { background: rgba(41, 128, 185, 0.3); }
    50%  { background: rgba(41, 128, 185, 0.15); transform: scale(0.98); }
    70%  { background: rgba(41, 128, 185, 0.25); transform: scale(1.01); }
    100% { background: transparent; transform: scale(1); }
}

.anim-liquefy {
    animation: liquefy 0.9s ease both;
}

@keyframes shuffle {
    0%   { background: transparent; transform: translateX(0); }
    25%  { background: rgba(142, 68, 173, 0.15); transform: translateX(-6px); }
    50%  { background: rgba(142, 68, 173, 0.2); transform: translateX(6px); }
    75%  { background: rgba(142, 68, 173, 0.1); transform: translateX(-3px); }
    100% { background: transparent; transform: translateX(0); }
}

.anim-shuffle {
    animation: shuffle 0.6s ease both;
}

/* Table row animation */
.debug-table tr.anim-flash {
    animation: flash 0.7s ease both;
}

/* ---- Error Bar ---- */

.error-bar {
    margin-top: 20px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: opacity 0.3s;
}

.error-bar.hidden {
    display: none;
}

.error-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: #fdf0ef;
    border: 2px solid rgba(142, 27, 19, 0.2);
    border-radius: var(--radius-sm);
    color: var(--error-red);
    font-size: 0.9rem;
    line-height: 1.5;
}

.error-bar.calm .error-bar-inner {
    background: rgba(232, 207, 163, 0.25);
    border-color: var(--debug-brown);
    color: var(--text-mid);
}

.error-icon {
    flex-shrink: 0;
    display: flex;
}

.error-bar.calm .error-icon {
    display: none;
}

#error-text {
    flex: 1;
}

.btn-dismiss {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: inherit;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-dismiss:hover {
    opacity: 1;
}

.error-bar.calm .btn-dismiss {
    display: none;
}

/* ---- Scrollbar Styling ---- */

.debug-content::-webkit-scrollbar {
    width: 6px;
}

.debug-content::-webkit-scrollbar-track {
    background: transparent;
}

.debug-content::-webkit-scrollbar-thumb {
    background: var(--debug-brown);
    border-radius: 3px;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .kitchen-layout {
        grid-template-columns: 1fr;
    }

    .debug-grid {
        grid-template-columns: 1fr;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .app-shell {
        padding: 16px;
    }

    .recipe-editor {
        min-height: 250px;
    }

    .step-player-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .speed-control {
        margin-left: 0;
    }

    .toast-container {
        bottom: 12px;
        max-width: calc(100% - 24px);
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.5rem;
    }

    .button-bar {
        flex-direction: column;
    }

    .btn {
        justify-content: center;
    }

    .step-controls {
        flex-wrap: wrap;
    }
}

/* ---- Page Load Animations ---- */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.panel {
    animation: fadeIn 0.4s ease both;
}

.editor-column .panel  { animation-delay: 0.05s; }
.output-panel          { animation-delay: 0.1s; }
.debug-grid .panel:nth-child(1) { animation-delay: 0.15s; }
.debug-grid .panel:nth-child(2) { animation-delay: 0.2s; }
.debug-grid .panel:nth-child(3) { animation-delay: 0.25s; }
.debug-grid .panel:nth-child(4) { animation-delay: 0.3s; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.6; }
}

.btn.primary.cooking {
    animation: pulse 1s ease-in-out infinite;
}

/* ==================================
   Cookbook Modal
   ================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(59, 36, 20, 0.55);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 1;
    transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal {
    background: var(--card-white);
    border-radius: var(--radius);
    box-shadow: 0 24px 64px rgba(59, 36, 20, 0.3);
    width: 100%;
    max-width: 740px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease both;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 2px solid var(--debug-brown);
    flex-shrink: 0;
}

.modal-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 1.4rem;
    margin: 0;
    color: var(--accent-red);
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-title svg {
    color: var(--accent-red);
}

.modal-close {
    background: none;
    border: 2px solid var(--debug-brown);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-mid);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    padding: 0;
}

.modal-close:hover {
    background: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--debug-brown);
    border-radius: 3px;
}

/* ---- Cookbook Sections ---- */

.cb-section {
    margin-bottom: 28px;
}

.cb-section:last-child {
    margin-bottom: 0;
}

.cb-heading {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-dark);
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 2px dashed var(--debug-brown);
}

.cb-section p {
    margin: 0 0 8px;
    font-size: 0.9rem;
    line-height: 1.65;
}

.cb-dim {
    color: var(--text-mid);
    font-size: 0.85rem;
}

.cb-section code {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.82rem;
    background: rgba(232, 207, 163, 0.35);
    padding: 1px 6px;
    border-radius: 4px;
    color: var(--text-dark);
}

/* Structure list */

.cb-structure {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cb-structure-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 0.9rem;
}

.cb-num {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-red);
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
    border-radius: 50%;
}

/* Concept cards */

.cb-concepts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.cb-concept {
    background: var(--bg-warm);
    border: 1px solid var(--debug-brown);
    border-radius: var(--radius-sm);
    padding: 14px;
}

.cb-concept-icon {
    font-size: 1.6rem;
    margin-bottom: 4px;
}

.cb-concept h4 {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--text-dark);
}

.cb-concept p {
    font-size: 0.82rem;
    margin: 0;
    color: var(--text-mid);
    line-height: 1.55;
}

/* Command table */

.cb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.cb-table th {
    text-align: left;
    font-family: 'Inter', Arial, sans-serif;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-mid);
    padding: 8px 10px;
    border-bottom: 2px solid var(--debug-brown);
}

.cb-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(232, 207, 163, 0.5);
    vertical-align: top;
    line-height: 1.5;
}

.cb-table tr:last-child td {
    border-bottom: none;
}

.cb-table code {
    font-size: 0.78rem;
    white-space: nowrap;
}

.cb-op {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.cb-op-push  { background: #d4efdf; color: #1e7e34; }
.cb-op-pop   { background: #fadbd8; color: #922b21; }
.cb-op-arith { background: #fef9e7; color: #9a7d0a; }
.cb-op-liq   { background: #d6eaf8; color: #1b4f72; }
.cb-op-stir  { background: #f5eef8; color: #6c3483; }
.cb-op-pour  { background: #fdebd0; color: #935116; }
.cb-op-clean { background: #f2f3f4; color: #566573; }
.cb-op-halt  { background: #d5f5e3; color: #196f3d; }

/* Ordered steps */

.cb-steps {
    margin: 0;
    padding-left: 22px;
    font-size: 0.9rem;
    line-height: 1.8;
}

.cb-tip {
    background: rgba(241, 196, 15, 0.15);
    border-left: 4px solid var(--accent-yellow);
    padding: 10px 14px;
    border-radius: 0 8px 8px 0;
    font-size: 0.85rem;
    margin-top: 10px;
}

/* Code block */

.cb-code {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    background: var(--bg-warm);
    border: 1px solid var(--debug-brown);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    margin: 10px 0;
    overflow-x: auto;
    white-space: pre;
}

/* Walkthrough */

.cb-walkthrough {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
}

.cb-walk-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    padding: 6px 10px;
    background: var(--bg-warm);
    border-radius: 8px;
    border: 1px solid rgba(232, 207, 163, 0.5);
}

.cb-walk-num {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-red);
    color: #fff;
    font-weight: 700;
    font-size: 0.7rem;
    border-radius: 50%;
}

/* ASCII grid */

.cb-ascii-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 6px;
    font-size: 0.82rem;
}

.cb-ascii-grid span {
    padding: 4px 8px;
    background: var(--bg-warm);
    border-radius: 6px;
    border: 1px solid rgba(232, 207, 163, 0.5);
    text-align: center;
}

/* ---- Responsive modal ---- */

@media (max-width: 600px) {
    .modal {
        max-width: 100%;
        border-radius: var(--radius-sm);
    }

    .modal-body {
        padding: 16px;
    }

    .cb-concepts {
        grid-template-columns: 1fr;
    }

    .cb-table code {
        white-space: normal;
    }
}

/* ==================================
   Challenge System
   ================================== */

/* Header button */

.btn.primary-outline {
    background: transparent;
    color: var(--accent-red);
    border: 2px solid var(--accent-red);
    box-shadow: none;
}

.btn.primary-outline:hover {
    background: var(--accent-red);
    color: #fff;
    box-shadow: 0 4px 12px rgba(192, 57, 43, 0.3);
}

/* ---- Challenge List Modal ---- */

.modal-challenges .modal-body {
    padding: 20px 24px;
}

.challenges-intro {
    font-size: 0.9rem;
    color: var(--text-mid);
    margin: 0 0 14px;
}

.challenge-progress-bar-wrap {
    height: 8px;
    background: var(--debug-brown);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.challenge-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--success-green), #2ecc71);
    border-radius: 4px;
    width: 0%;
    transition: width 0.5s ease;
}

.challenge-progress-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-mid);
    display: block;
    margin-bottom: 18px;
}

.challenge-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.challenge-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--bg-warm);
    border: 2px solid var(--debug-brown);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.challenge-card:hover {
    border-color: var(--accent-red);
    transform: translateX(4px);
    box-shadow: 0 4px 12px var(--shadow);
}

.challenge-card.completed {
    border-color: var(--success-green);
    background: #f0f9f0;
}

.challenge-card.completed:hover {
    border-color: #2ecc71;
}

.challenge-card-num {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--debug-brown);
    color: var(--text-dark);
}

.challenge-card.completed .challenge-card-num {
    background: var(--success-green);
    color: #fff;
}

.challenge-card-body {
    flex: 1;
    min-width: 0;
}

.challenge-card-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-dark);
    margin: 0;
}

.challenge-card-skill {
    font-size: 0.78rem;
    color: var(--text-mid);
    margin-top: 2px;
}

.challenge-card-status {
    flex-shrink: 0;
    font-size: 1.1rem;
}

/* ---- Challenge Banner (above editor) ---- */

.challenge-banner {
    background: linear-gradient(135deg, #fef9ed 0%, var(--card-white) 100%);
    border: 2px solid var(--accent-yellow);
    border-radius: var(--radius-sm);
    padding: 16px 18px;
    margin-bottom: 14px;
    animation: fadeIn 0.3s ease both;
}

.challenge-banner-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.challenge-badge {
    font-family: 'Inter', Arial, sans-serif;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent-yellow);
    color: var(--text-dark);
}

.btn-exit-challenge {
    background: none;
    border: 1px solid var(--debug-brown);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-mid);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-exit-challenge:hover {
    background: var(--accent-red);
    color: #fff;
    border-color: var(--accent-red);
}

.challenge-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0 0 4px;
    color: var(--text-dark);
}

.challenge-desc {
    font-size: 0.9rem;
    color: var(--text-dark);
    margin: 0 0 10px;
    line-height: 1.5;
}

.challenge-meta {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.challenge-meta-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-mid);
    margin-right: 4px;
}

.challenge-expect code {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.9rem;
    font-weight: 700;
    background: rgba(60, 141, 64, 0.12);
    color: var(--success-green);
    padding: 2px 8px;
    border-radius: 4px;
}

.challenge-skill-tag {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-dark);
}

/* Hint */

.challenge-hint-area {
    margin-bottom: 12px;
}

.hint-btn {
    font-size: 0.82rem;
    padding: 6px 14px;
    background: transparent;
    border: 1px dashed var(--debug-brown);
    border-radius: 999px;
    color: var(--text-mid);
}

.hint-btn:hover {
    background: var(--debug-brown);
    color: var(--text-dark);
    border-style: solid;
}

.challenge-hint {
    font-size: 0.85rem;
    color: var(--text-mid);
    font-style: italic;
    margin: 8px 0 0;
    padding: 10px 14px;
    background: rgba(241, 196, 15, 0.1);
    border-left: 3px solid var(--accent-yellow);
    border-radius: 0 8px 8px 0;
    line-height: 1.55;
}

/* Actions */

.challenge-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* Feedback */

.challenge-feedback {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.5;
    animation: fadeIn 0.3s ease both;
}

.challenge-feedback.success {
    background: #d5f5e3;
    border: 2px solid var(--success-green);
    color: #196f3d;
}

.challenge-feedback.fail {
    background: #fadbd8;
    border: 2px solid var(--error-red);
    color: var(--error-red);
}

@media (max-width: 600px) {
    .challenge-meta {
        flex-direction: column;
        gap: 6px;
    }
}
