/* ============================================================
   LegalDebug.com — Styles
   Palette: #0a0e14, #1c2333, #e6c07b, #c93c37, #62aeef, #89ca78, #abb2bf, #d19a66
   Fonts: Space Grotesk, Source Serif 4, JetBrains Mono, Crimson Pro
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scrollbar-color: #1c2333 #0a0e14;
}

body {
    background: #0a0e14;
    color: #abb2bf;
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 18px;
    line-height: 1.75;
    overflow-x: hidden;
    position: relative;
}

::selection {
    background: #e6c07b;
    color: #0a0e14;
}

/* --- Circuit Board Background Canvas --- */
#circuit-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.15;
}

/* --- SVG Connection Lines --- */
.connection-svg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    pointer-events: none;
}

.connection-svg path {
    fill: none;
    stroke: #c93c37;
    stroke-width: 1.5;
    filter: url(#red-glow);
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    transition: stroke-dashoffset 800ms ease-out;
}

.connection-svg path.drawn {
    stroke-dashoffset: 0;
}

/* ============================================================
   Terminal Viewport
   ============================================================ */
#terminal-viewport {
    position: relative;
    z-index: 10;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.terminal-screen {
    width: 100%;
    max-width: 900px;
    background: #0a0e14;
    border: 1px solid #1c2333;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 60px rgba(10, 14, 20, 0.8), 0 0 120px rgba(98, 174, 239, 0.05);
}

.terminal-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #1c2333;
    border-bottom: 1px solid rgba(171, 178, 191, 0.1);
}

.terminal-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.terminal-dot.red { background: #c93c37; }
.terminal-dot.yellow { background: #e6c07b; }
.terminal-dot.green { background: #89ca78; }

.terminal-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: #abb2bf;
    margin-left: 12px;
    opacity: 0.6;
}

.terminal-body {
    padding: 24px 28px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    line-height: 1.8;
}

.prompt-line {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.prompt {
    color: #89ca78;
    font-weight: 700;
}

.command-text {
    color: #e6c07b;
}

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

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

.terminal-output {
    color: #abb2bf;
}

.output-line {
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.output-line.visible {
    opacity: 1;
    transform: translateY(0);
}

.text-red { color: #c93c37; }
.text-amber { color: #e6c07b; }
.text-green { color: #89ca78; }
.text-orange { color: #d19a66; }

.scroll-indicator {
    text-align: center;
    margin-top: 24px;
    color: #62aeef;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.scroll-indicator.visible {
    opacity: 1;
    transform: translateY(0);
    animation: bounce-down 2s ease-in-out infinite;
}

@keyframes bounce-down {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
}

.arrow-down {
    display: inline-block;
    animation: bounce-down 2s ease-in-out infinite;
}

/* ============================================================
   Gutter Spine
   ============================================================ */
#gutter-spine {
    position: fixed;
    left: 0;
    top: 0;
    width: 60px;
    height: 100vh;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 100px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#gutter-spine.visible {
    opacity: 1;
}

.spine-line {
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: linear-gradient(to bottom, transparent 5%, #62aeef 15%, #62aeef 85%, transparent 95%);
    opacity: 0.3;
    transform: translateX(-50%);
}

.gutter-line-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: #62aeef;
    opacity: 0.4;
    padding: 4px 0;
    position: relative;
    z-index: 2;
    transition: opacity 0.3s ease, color 0.3s ease;
}

.gutter-line-number.active {
    opacity: 1;
    color: #e6c07b;
}

/* ============================================================
   Frame Counter
   ============================================================ */
#frame-counter {
    position: fixed;
    top: 20px;
    left: 80px;
    z-index: 25;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: #abb2bf;
    background: rgba(28, 35, 51, 0.9);
    padding: 6px 14px;
    border-radius: 4px;
    border: 1px solid rgba(98, 174, 239, 0.2);
    opacity: 0;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(8px);
}

#frame-counter.visible {
    opacity: 1;
}

.frame-label {
    color: #abb2bf;
    opacity: 0.6;
    margin-right: 4px;
}

#frame-number {
    color: #e6c07b;
    font-weight: 700;
    display: inline-block;
    transition: transform 0.3s ease;
}

#frame-number.rolling {
    animation: roll-number 0.3s ease;
}

@keyframes roll-number {
    0% { transform: translateY(100%); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* ============================================================
   Stack Frames
   ============================================================ */
.stack-frame {
    position: relative;
    z-index: 10;
    padding: 80px 100px 80px 100px;
    min-height: 100vh;
    margin-left: 60px;
}

.frame-separator {
    position: absolute;
    top: 0;
    left: -60px;
    right: 0;
    height: 60px;
    background: linear-gradient(to bottom, #0a0e14, transparent);
    clip-path: polygon(0 0, 100% 8px, 100% 100%, 0 100%);
    pointer-events: none;
}

.frame-separator::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(to right, #62aeef 0%, rgba(98, 174, 239, 0.3) 30%, rgba(98, 174, 239, 0.1) 70%, transparent);
    transform: rotate(-0.5deg);
}

/* Frame Header */
.frame-header {
    margin-bottom: 40px;
}

.frame-signature {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.frame-number-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: #0a0e14;
    background: #62aeef;
    padding: 2px 10px;
    border-radius: 3px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.frame-function {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: #abb2bf;
}

/* Typewriter Prompt */
.typewriter-prompt {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    color: #abb2bf;
    opacity: 0.7;
    padding: 8px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.typewriter-prompt .prompt {
    color: #89ca78;
}

.typewriter-prompt .typed-text {
    color: #e6c07b;
}

.mini-cursor {
    color: #e6c07b;
    animation: blink 1s step-end infinite;
    font-size: 14px;
}

/* Section Title */
.section-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 3.5rem);
    color: #e6c07b;
    margin-bottom: 16px;
    line-height: 1.2;
}

/* Z-Pattern Layout */
.z-pattern-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 48px;
    align-items: start;
}

.issue-statement p {
    color: #abb2bf;
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 18px;
    line-height: 1.75;
}

/* Code Representation */
.syntax-block {
    background: #1c2333;
    border: 1px solid rgba(171, 178, 191, 0.1);
    border-radius: 6px;
    padding: 20px 24px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: #abb2bf;
}

.syntax-block code {
    font-family: inherit;
}

.syn-keyword { color: #c678dd; font-weight: 700; }
.syn-func { color: #62aeef; }
.syn-param { color: #d19a66; }
.syn-string { color: #89ca78; }
.syn-comment { color: #5c6370; font-style: italic; }
.syn-red { color: #c93c37; }
.syn-number { color: #d19a66; }

/* Z-Pattern Mid */
.z-pattern-mid {
    margin-bottom: 48px;
    padding-left: 40px;
    position: relative;
}

/* Breakpoint Row */
.breakpoint-row {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    position: relative;
}

.breakpoint-dot {
    width: 16px;
    height: 16px;
    min-width: 16px;
    background: #c93c37;
    border-radius: 50%;
    margin-top: 6px;
    cursor: pointer;
    position: relative;
    box-shadow: 0 0 6px rgba(201, 60, 55, 0.4);
    animation: pulse-breakpoint 3s ease-in-out infinite;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.breakpoint-dot:hover {
    box-shadow: 0 0 16px rgba(201, 60, 55, 0.8);
    transform: scale(1.2);
}

.breakpoint-dot::after {
    content: attr(data-annotation);
    position: absolute;
    left: calc(100% + 16px);
    top: -8px;
    width: 360px;
    background: #1c2333;
    border-left: 3px solid #c93c37;
    color: #abb2bf;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.6;
    padding: 16px 20px;
    border-radius: 0 6px 6px 0;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 30;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.breakpoint-dot:hover::after {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

@keyframes pulse-breakpoint {
    0%, 100% { box-shadow: 0 0 6px rgba(201, 60, 55, 0.4); }
    50% { box-shadow: 0 0 14px rgba(201, 60, 55, 0.7); }
}

.analysis-text p {
    color: #abb2bf;
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 18px;
    line-height: 1.75;
    margin-bottom: 16px;
}

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

/* Legal Citations */
.legal-cite {
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 14px;
    font-style: italic;
    color: #62aeef;
}

.inline-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    background: rgba(28, 35, 51, 0.8);
    padding: 2px 6px;
    border-radius: 3px;
    color: #e6c07b;
}

/* Z-Pattern Bottom */
.z-pattern-bottom {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 40px;
    align-items: end;
}

.conclusion-block {
    min-width: 0;
}

/* Diff Display */
.diff-display {
    background: #1c2333;
    border: 1px solid rgba(171, 178, 191, 0.1);
    border-radius: 6px;
    overflow: hidden;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.7;
}

.diff-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(10, 14, 20, 0.5);
    border-bottom: 1px solid rgba(171, 178, 191, 0.1);
}

.diff-file {
    color: #abb2bf;
    font-weight: 700;
}

.diff-stats {
    font-size: 12px;
}

.diff-line {
    padding: 2px 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-line.removed {
    background: rgba(201, 60, 55, 0.1);
    color: #c93c37;
    border-left: 3px solid #c93c37;
}

.diff-line.added {
    background: rgba(137, 202, 120, 0.08);
    color: #89ca78;
    border-left: 3px solid #89ca78;
}

.diff-highlight {
    background: rgba(137, 202, 120, 0.15);
    padding: 0 2px;
    border-radius: 2px;
}

/* Variable Watch */
.variable-watch {
    background: #1c2333;
    border: 1px solid rgba(171, 178, 191, 0.1);
    border-radius: 6px;
    overflow: hidden;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}

.watch-header {
    padding: 8px 16px;
    background: rgba(10, 14, 20, 0.5);
    border-bottom: 1px solid rgba(171, 178, 191, 0.1);
    color: #abb2bf;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.watch-row {
    padding: 6px 16px;
    display: flex;
    gap: 8px;
    align-items: baseline;
    border-bottom: 1px solid rgba(171, 178, 191, 0.05);
}

.watch-row:last-child {
    border-bottom: none;
}

.watch-var {
    color: #62aeef;
}

.watch-eq {
    color: #abb2bf;
    opacity: 0.4;
}

.watch-val {
    color: #89ca78;
}

/* Frame Navigation */
.frame-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-self: end;
}

.step-btn {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    padding: 8px 20px;
    border: 1px solid rgba(98, 174, 239, 0.3);
    border-radius: 4px;
    background: rgba(28, 35, 51, 0.6);
    color: #62aeef;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.step-btn:hover {
    background: rgba(98, 174, 239, 0.15);
    border-color: #62aeef;
    box-shadow: 0 0 12px rgba(98, 174, 239, 0.15);
}

.step-btn.step-into {
    border-color: rgba(230, 192, 123, 0.3);
    color: #e6c07b;
}

.step-btn.step-into:hover {
    background: rgba(230, 192, 123, 0.15);
    border-color: #e6c07b;
    box-shadow: 0 0 12px rgba(230, 192, 123, 0.15);
}

.step-btn.disabled {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* ============================================================
   Variable Inspector Sidebar
   ============================================================ */
#variable-inspector {
    position: fixed;
    right: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: #1c2333;
    border-left: 1px solid rgba(171, 178, 191, 0.1);
    z-index: 30;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.4s ease;
    opacity: 0;
    pointer-events: none;
}

#variable-inspector.visible {
    opacity: 1;
    pointer-events: auto;
}

#variable-inspector.collapsed {
    transform: translateX(240px);
}

.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid rgba(171, 178, 191, 0.1);
    background: rgba(10, 14, 20, 0.5);
}

.inspector-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 700;
    color: #abb2bf;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.inspector-toggle-btn {
    background: none;
    border: none;
    color: #abb2bf;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 8px;
    transition: color 0.2s ease, transform 0.4s ease;
}

.inspector-toggle-btn:hover {
    color: #e6c07b;
}

#variable-inspector.collapsed .inspector-toggle-btn {
    transform: rotate(180deg);
}

.inspector-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.var-group {
    display: none;
}

.var-group.active {
    display: block;
    animation: fade-in 0.3s ease;
}

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

.var-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 0;
    border-bottom: 1px solid rgba(171, 178, 191, 0.05);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.var-row:last-child {
    border-bottom: none;
}

.var-name {
    color: #62aeef;
}

.var-value {
    color: #89ca78;
    text-align: right;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.var-row .var-value.flash {
    animation: var-flash 0.4s ease;
}

@keyframes var-flash {
    0% { background: rgba(230, 192, 123, 0.2); }
    100% { background: transparent; }
}

/* ============================================================
   Session Footer
   ============================================================ */
#session-footer {
    position: relative;
    z-index: 10;
    padding: 60px 100px 40px;
    margin-left: 60px;
    border-top: 1px solid rgba(171, 178, 191, 0.08);
}

.terminal-footer {
    max-width: 800px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    line-height: 1.8;
}

.footer-line {
    color: #abb2bf;
    margin-bottom: 16px;
}

.footer-line .prompt {
    color: #89ca78;
    font-weight: 700;
    margin-right: 8px;
}

.footer-output {
    margin-bottom: 24px;
}

.footer-output p {
    color: #abb2bf;
    margin-bottom: 8px;
}

.footer-comment .syn-comment {
    color: #5c6370;
    font-style: italic;
}

.footer-cursor {
    margin-bottom: 40px;
}

.footer-cursor .prompt {
    color: #89ca78;
    font-weight: 700;
    margin-right: 8px;
}

.footer-cursor .cursor.blink {
    color: #e6c07b;
    animation: blink 1s step-end infinite;
}

.footer-meta {
    display: flex;
    justify-content: space-between;
    color: #abb2bf;
    opacity: 0.3;
    font-size: 12px;
    padding-top: 16px;
    border-top: 1px solid rgba(171, 178, 191, 0.08);
}

/* ============================================================
   Custom Cursor (desktop)
   ============================================================ */
.debug-cursor {
    position: fixed;
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: screen;
}

.debug-cursor::before,
.debug-cursor::after {
    content: '';
    position: absolute;
    background: #62aeef;
}

.debug-cursor::before {
    width: 1px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
}

.debug-cursor::after {
    width: 100%;
    height: 1px;
    top: 50%;
    transform: translateY(-50%);
}

.cursor-trail {
    position: fixed;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(98, 174, 239, 0.3);
    pointer-events: none;
    z-index: 9998;
    transition: opacity 0.5s ease;
}

/* ============================================================
   Scroll-driven Animations
   ============================================================ */
.stack-frame {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.stack-frame.in-view {
    opacity: 1;
    transform: translateY(0);
}

.frame-header {
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 0.5s ease 0.2s, transform 0.5s ease 0.2s;
}

.stack-frame.in-view .frame-header {
    opacity: 1;
    transform: translateX(0);
}

.z-pattern-top {
    opacity: 0;
    transition: opacity 0.5s ease 0.4s;
}

.stack-frame.in-view .z-pattern-top {
    opacity: 1;
}

.z-pattern-mid {
    opacity: 0;
    transition: opacity 0.5s ease 0.6s;
}

.stack-frame.in-view .z-pattern-mid {
    opacity: 1;
}

.z-pattern-bottom {
    opacity: 0;
    transition: opacity 0.5s ease 0.8s;
}

.stack-frame.in-view .z-pattern-bottom {
    opacity: 1;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1200px) {
    #variable-inspector {
        display: none;
    }

    .stack-frame {
        padding-right: 40px;
    }
}

@media (max-width: 900px) {
    .stack-frame {
        padding: 60px 24px 60px 80px;
    }

    .z-pattern-top {
        grid-template-columns: 1fr;
    }

    .z-pattern-bottom {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .frame-nav {
        flex-direction: row;
    }

    #session-footer {
        padding: 40px 24px 30px 80px;
    }

    .breakpoint-dot::after {
        width: 260px;
        left: auto;
        right: calc(100% + 16px);
    }
}

@media (max-width: 600px) {
    #gutter-spine {
        width: 40px;
    }

    .stack-frame {
        padding: 40px 16px 40px 56px;
        margin-left: 40px;
    }

    #session-footer {
        padding: 30px 16px 20px 56px;
        margin-left: 40px;
    }

    .terminal-body {
        padding: 16px;
        font-size: 13px;
    }

    .syntax-block {
        font-size: 12px;
        padding: 12px 16px;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .frame-nav {
        flex-direction: column;
    }

    .breakpoint-dot::after {
        position: fixed;
        left: 56px;
        right: 16px;
        top: auto;
        bottom: 20px;
        width: auto;
    }

    #frame-counter {
        left: 50px;
        font-size: 11px;
    }
}
