/* ============================================================
   rust.quest — Terminal Emulator Stylesheet
   Colors: #1a1b26 #2a2b36 #ce422b #ff5555 #ffb347
           #f1fa8c #50fa7b #f8f8f2 #6272a4
   Fonts: Fira Code (body), JetBrains Mono (titlebar/progress),
          Space Grotesk (logo)
   ============================================================ */

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

body {
    background: #1a1b26;
    color: #ffb347;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 1rem;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 32px 20px 72px;
    /* CRT scanline overlay */
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.05) 2px,
            rgba(0, 0, 0, 0.05) 4px
        );
}

/* ============================================================
   Terminal Frame
   ============================================================ */

.terminal-frame {
    max-width: 1100px;
    width: 100%;
    border: 1px solid #6272a4;
    border-radius: 8px;
    overflow: hidden;
    box-shadow:
        0 0 40px rgba(206, 66, 43, 0.12),
        0 0 80px rgba(26, 27, 38, 0.9),
        inset 0 0 60px rgba(255, 179, 71, 0.02);
    position: relative;
}

/* CRT phosphor glow */
.terminal-frame::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    box-shadow: inset 0 0 120px rgba(255, 179, 71, 0.04);
    pointer-events: none;
    z-index: 10;
}

/* ============================================================
   Terminal Title Bar
   ============================================================ */

.terminal-titlebar {
    height: 36px;
    background: #2a2b36;
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-bottom: 1px solid #6272a4;
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 20;
}

.titlebar-dots {
    display: flex;
    gap: 8px;
    margin-right: 16px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-close {
    background: #ff5555;
    box-shadow: 0 0 6px rgba(255, 85, 85, 0.5);
}

.dot-minimize {
    background: #f1fa8c;
    box-shadow: 0 0 6px rgba(241, 250, 140, 0.4);
}

.dot-maximize {
    background: #50fa7b;
    box-shadow: 0 0 6px rgba(80, 250, 123, 0.4);
}

.titlebar-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #6272a4;
    font-weight: 400;
}

.titlebar-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    color: #ce422b;
}

/* ============================================================
   Terminal Content: Sidebar + Main
   ============================================================ */

.terminal-content {
    display: flex;
    min-height: calc(100vh - 36px - 72px);
}

/* ============================================================
   Sidebar File Tree
   ============================================================ */

.file-tree {
    width: 220px;
    flex-shrink: 0;
    background: #1a1b26;
    border-right: 1px solid #2a2b36;
    padding: 16px 0;
    position: sticky;
    top: 36px;
    height: calc(100vh - 36px - 72px);
    overflow-y: auto;
    font-size: 0.78rem;
    font-family: 'Fira Code', monospace;
    scrollbar-width: thin;
    scrollbar-color: #2a2b36 transparent;
}

.file-tree::-webkit-scrollbar {
    width: 4px;
}

.file-tree::-webkit-scrollbar-track {
    background: transparent;
}

.file-tree::-webkit-scrollbar-thumb {
    background: #2a2b36;
    border-radius: 2px;
}

.tree-header {
    color: #ffb347;
    font-weight: 700;
    padding: 0 16px 8px;
    border-bottom: 1px solid #2a2b36;
    margin-bottom: 8px;
}

.tree-list {
    list-style: none;
    padding: 0;
}

.tree-item {
    padding: 3px 16px;
    color: #6272a4;
    cursor: default;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.tree-dir {
    color: #6272a4;
    margin-top: 4px;
    font-weight: 700;
}

.tree-file {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
}

.tree-file:hover {
    color: #ffb347;
}

.tree-file.active {
    color: #ffb347;
    background: rgba(255, 179, 71, 0.08);
    border-left: 2px solid #ce422b;
    padding-left: 14px;
}

.tree-file.active .tree-name::before {
    content: '> ';
    color: #ce422b;
}

.tree-prefix {
    color: #2a2b36;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.tree-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-config {
    margin-top: 8px;
    color: #6272a4;
    font-style: italic;
}

/* ============================================================
   Terminal Body (Main Content)
   ============================================================ */

.terminal-body {
    flex: 1;
    background: #1a1b26;
    padding: 24px 28px;
    min-width: 0;
}

/* ============================================================
   Terminal Sections
   ============================================================ */

.terminal-section {
    margin-bottom: 36px;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.45s ease, transform 0.45s ease;
}

.terminal-section.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   Command Lines
   ============================================================ */

.command-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
    padding: 4px 0;
}

.prompt {
    color: #50fa7b;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.command-text {
    color: #f8f8f2;
    font-weight: 400;
    word-break: break-word;
}

.cursor {
    color: #f8f8f2;
    font-size: 1rem;
}

.cursor.blink {
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}

/* ============================================================
   Command Output
   ============================================================ */

.command-output {
    padding-left: 20px;
    border-left: 2px solid #2a2b36;
    margin-left: 4px;
}

.output-spacer {
    height: 12px;
}

/* ============================================================
   Logo / Hero
   ============================================================ */

.logo-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2.8rem;
    font-weight: 700;
    color: #ce422b;
    margin: 12px 0 8px;
    text-shadow:
        0 0 20px rgba(206, 66, 43, 0.6),
        0 0 40px rgba(206, 66, 43, 0.3);
    letter-spacing: -0.02em;
}

/* ============================================================
   Section Headings
   ============================================================ */

.section-heading {
    font-size: 1.15rem;
    font-weight: 700;
    color: #f1fa8c;
    margin-bottom: 16px;
    font-family: 'Fira Code', monospace;
}

/* ============================================================
   Output Text
   ============================================================ */

.output-line {
    color: #ffb347;
    margin-bottom: 4px;
    font-size: 0.95rem;
}

.output-line.dim {
    color: #6272a4;
}

.success-text {
    color: #50fa7b;
}

.error-text {
    color: #ff5555;
}

/* ============================================================
   Typewriter Lines
   ============================================================ */

.tw-line {
    overflow: hidden;
    white-space: nowrap;
    width: 0;
    display: block;
}

.tw-line.typed {
    width: 100%;
    transition: none;
}

/* Reduced motion: show text immediately */
@media (prefers-reduced-motion: reduce) {
    .tw-line {
        width: 100% !important;
        animation: none !important;
    }
    .cursor.blink {
        animation: none !important;
        opacity: 1 !important;
    }
    .terminal-section {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
}

/* ============================================================
   Compiler Error Boxes
   ============================================================ */

.compiler-box {
    background: #2a2b36;
    border: 1px solid #ff5555;
    border-left: 3px solid #ff5555;
    border-radius: 4px;
    margin: 12px 0;
    overflow: hidden;
}

.compiler-header {
    background: rgba(255, 85, 85, 0.12);
    padding: 8px 12px;
    font-weight: 700;
    font-size: 0.88rem;
    color: #f8f8f2;
    border-bottom: 1px solid rgba(255, 85, 85, 0.2);
}

.error-code {
    color: #ff5555;
}

.compiler-box-warn {
    border-color: #f1fa8c;
}

.compiler-header-warn {
    background: rgba(241, 250, 140, 0.08);
    border-bottom-color: rgba(241, 250, 140, 0.2);
}

.warn-code {
    color: #f1fa8c;
}

.compiler-body {
    padding: 10px 12px;
}

/* ============================================================
   Code Blocks
   ============================================================ */

.code-block {
    background: #2a2b36;
    border: 1px solid #6272a4;
    border-radius: 4px;
    padding: 10px 12px;
    margin: 12px 0;
    overflow-x: auto;
}

.code-block-header {
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(98, 114, 164, 0.3);
    font-size: 0.82rem;
}

/* ============================================================
   Code Syntax Colors
   ============================================================ */

.code-line {
    color: #f8f8f2;
    margin-bottom: 2px;
    font-size: 0.88rem;
    display: block;
    white-space: pre-wrap;
}

.line-num {
    color: #6272a4;
    margin-right: 14px;
    display: inline-block;
    min-width: 24px;
    text-align: right;
    user-select: none;
}

.keyword {
    color: #ff5555;
}

.string {
    color: #f1fa8c;
}

.number {
    color: #ffb347;
}

.type {
    color: #50fa7b;
}

.fn-name {
    color: #f1fa8c;
    font-weight: 700;
}

.lifetime {
    color: #ce422b;
}

.comment {
    color: #6272a4;
    font-style: italic;
}

.macro {
    color: #ffb347;
    font-weight: 700;
}

.highlight-line {
    background: rgba(255, 85, 85, 0.12);
    display: block;
    padding: 1px 4px;
    border-radius: 2px;
    margin: 1px 0;
}

.highlight-line-warn {
    background: rgba(241, 250, 140, 0.08);
    display: block;
    padding: 1px 4px;
    border-radius: 2px;
    margin: 1px 0;
}

.error-pointer {
    color: #ff5555;
    font-size: 0.88rem;
    margin: 2px 0;
    white-space: pre;
}

.error-caret {
    color: #ff5555;
    font-weight: 700;
}

.error-pointer-warn {
    color: #f1fa8c;
    font-size: 0.88rem;
    margin: 2px 0;
    white-space: pre;
}

.warn-caret {
    color: #f1fa8c;
    font-weight: 700;
}

.error-help {
    color: #6272a4;
    font-size: 0.85rem;
    margin-top: 2px;
}

/* ============================================================
   Inline Progress Bars (Chapter ASCII)
   ============================================================ */

.inline-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0 4px;
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
}

.progress-note {
    font-size: 0.8rem;
}

.progress-ascii {
    color: #50fa7b;
    letter-spacing: 0;
}

/* ============================================================
   Main Build Progress Bar
   ============================================================ */

.build-progress-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.build-step-label {
    color: #50fa7b;
    font-weight: 700;
    min-width: 90px;
    display: inline-block;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px 0;
}

.progress-label {
    color: #50fa7b;
    font-weight: 700;
    font-size: 0.9rem;
    min-width: 80px;
    font-family: 'JetBrains Mono', monospace;
}

.progress-bar {
    flex: 1;
    height: 14px;
    background: #2a2b36;
    border: 1px solid #6272a4;
    border-radius: 7px;
    overflow: hidden;
    max-width: 400px;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ce422b 0%, #ffb347 60%, #f1fa8c 100%);
    border-radius: 7px;
    transition: width 2.2s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 0 8px rgba(206, 66, 43, 0.4);
}

.progress-pct {
    color: #6272a4;
    font-size: 0.82rem;
    min-width: 36px;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   Terminal Footer
   ============================================================ */

.terminal-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid #2a2b36;
}

/* ============================================================
   Fixed Bottom Progress Bar
   ============================================================ */

.bottom-progress {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: #2a2b36;
    border-top: 1px solid #6272a4;
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    z-index: 100;
    overflow: hidden;
}

.bp-label {
    color: #50fa7b;
    font-weight: 700;
    flex-shrink: 0;
}

.bp-bar {
    color: #50fa7b;
    letter-spacing: -0.02em;
    flex-shrink: 0;
    font-size: 0.72rem;
}

#bp-fill {
    color: #50fa7b;
}

#bp-empty {
    color: #2a2b36;
    text-shadow: 0 0 0 #6272a4;
}

/* Trick: empty chars are dark but outline-visible */
#bp-empty {
    color: #6272a4;
}

.bp-pct {
    color: #f8f8f2;
    min-width: 36px;
    flex-shrink: 0;
}

.bp-sep {
    color: #6272a4;
    flex-shrink: 0;
}

.bp-chapter {
    color: #ffb347;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   Scrollbar
   ============================================================ */

html {
    scrollbar-width: thin;
    scrollbar-color: #2a2b36 #1a1b26;
}

html::-webkit-scrollbar {
    width: 6px;
}

html::-webkit-scrollbar-track {
    background: #1a1b26;
}

html::-webkit-scrollbar-thumb {
    background: #2a2b36;
    border-radius: 3px;
}

html::-webkit-scrollbar-thumb:hover {
    background: #6272a4;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
    .file-tree {
        display: none;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px 10px 68px;
    }

    .terminal-body {
        padding: 16px;
    }

    .logo-text {
        font-size: 1.9rem;
    }

    .code-line {
        font-size: 0.78rem;
    }

    .bottom-progress {
        font-size: 0.68rem;
        gap: 6px;
        padding: 0 10px;
    }

    .bp-bar {
        display: none;
    }
}
