/* 差分机 — Babbage Difference Engine */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=EB+Garamond:ital,wght@0,400;0,600;1,400&family=Source+Code+Pro:wght@400;600&display=swap');

:root {
    --bg: #0a1628;
    --panel-bg: #f0e6d0;
    --brass: #b8860b;
    --brass-lt: #d4a54a;
    --steel: #8090a0;
    --ink: #3b3020;
    --ink-faint: rgba(59, 48, 32, 0.2);
    --bp-blue: #4fc3f7;
    --hl-color: #ffd700;
    --hl-glow: rgba(255, 215, 0, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--panel-bg);
    background-image: radial-gradient(circle at center, transparent 0%, rgba(50, 30, 10, 0.2) 150%);
    font-family: 'EB Garamond', serif;
    color: var(--ink);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ===== ENTRANCE: BLUEPRINT ===== */
.entrance-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg);
    background-image:
        linear-gradient(rgba(79, 195, 247, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(79, 195, 247, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: bpFadeOut 1.5s 5s forwards;
}

@keyframes bpFadeOut {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        pointer-events: none;
    }
}

.entrance-svg {
    width: 60vw;
    max-width: 700px;
    margin-bottom: 30px;
}

/* Blueprint draw-on effect */
.bp-draw line,
.bp-draw rect,
.bp-draw circle {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: bpDraw 3.5s 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes bpDraw {
    to {
        stroke-dashoffset: 0;
    }
}

.entrance-title {
    font-family: 'Source Code Pro', monospace;
    font-size: 2.8rem;
    color: var(--bp-blue);
    letter-spacing: 10px;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(79, 195, 247, 0.3);
    opacity: 0;
    animation: bpTextIn 1.5s 2s forwards;
}

.entrance-sub {
    font-family: 'EB Garamond', serif;
    font-style: italic;
    font-size: 1.1rem;
    color: rgba(79, 195, 247, 0.5);
    margin-top: 10px;
    letter-spacing: 3px;
    opacity: 0;
    animation: bpTextIn 1s 3s forwards;
}

@keyframes bpTextIn {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== MAIN ===== */
.main-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    opacity: 0;
    animation: fadeIn 1.5s 5.5s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

.back-link {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    color: var(--ink);
    text-decoration: none;
    border: 1px solid var(--ink);
    padding: 5px 12px;
    letter-spacing: 1px;
    transition: all 0.3s;
}

.back-link:hover {
    background: var(--ink);
    color: var(--panel-bg);
}

.engine-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 0;
}

/* ===== LABEL COLUMNS ===== */
.label-column {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 215px;
    flex-shrink: 0;
    padding: 10px 6px;
    opacity: 0;
    animation: fadeIn 1s 7s forwards;
    max-height: 90vh;
    overflow-y: auto;
}

.label-column-left {
    align-items: flex-end;
}

.label-column-right {
    align-items: flex-start;
}

.feature-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    background: transparent;
    border: 1px solid var(--ink-faint);
    border-radius: 3px;
    padding: 4px 8px;
    font-family: 'EB Garamond', serif;
    font-size: 0.75rem;
    color: var(--ink);
    cursor: pointer;
    width: 100%;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: left;
    letter-spacing: 0.3px;
    position: relative;
}

.feature-btn:hover,
.feature-btn.active {
    background: rgba(184, 134, 11, 0.1);
    border-color: var(--brass);
    color: var(--brass);
    box-shadow: 0 2px 10px rgba(184, 134, 11, 0.12);
}

.label-column-left .feature-btn:hover {
    transform: translateX(3px);
}

.label-column-right .feature-btn:hover {
    transform: translateX(-3px);
}

.btn-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--brass);
    flex-shrink: 0;
    opacity: 0.5;
}

.feature-btn:hover .btn-dot,
.feature-btn.active .btn-dot {
    opacity: 1;
}

.btn-arrow {
    position: absolute;
    font-size: 0.65rem;
    color: var(--brass);
    opacity: 0;
    transition: opacity 0.3s;
}

.label-column-left .btn-arrow {
    right: -12px;
}

.label-column-right .btn-arrow {
    left: -12px;
}

.feature-btn:hover .btn-arrow {
    opacity: 1;
}

.btn-status {
    width: 100%;
    font-size: 0.62rem;
    color: var(--brass);
    font-family: 'Source Code Pro', monospace;
    font-style: normal;
    margin-top: 1px;
    padding-left: 11px;
    line-height: 1.2;
    opacity: 0.8;
}

/* ===== ENGINE CENTER ===== */
.engine-center {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.engine-wrapper {
    position: relative;
    width: 52vmin;
    height: auto;
    max-width: 600px;
}

#engine-svg {
    width: 100%;
    height: auto;
}

/* SVG labels */
.eng-label {
    font-family: 'Cinzel', serif;
    font-size: 8px;
    fill: rgba(90, 74, 58, 0.5);
    letter-spacing: 1px;
}

.eng-col-label {
    font-family: 'Source Code Pro', monospace;
    font-size: 11px;
    fill: var(--ink);
    font-weight: 600;
}

/* SVG drawing animation */
.eng-draw rect,
.eng-draw line,
.eng-draw circle {
    stroke-dasharray: 3000;
    stroke-dashoffset: 3000;
}

.eng-draw {
    animation: engDraw 3s 5.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.eng-draw rect,
.eng-draw line,
.eng-draw circle {
    animation: engDraw 3s 5.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes engDraw {
    to {
        stroke-dashoffset: 0;
    }
}

/* Wheel styling */
.digit-wheel {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.digit-wheel text {
    font-family: 'Source Code Pro', monospace;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
}

.digit-wheel.spinning rect {
    fill: rgba(255, 215, 0, 0.15) !important;
}

.digit-wheel.spinning text {
    fill: var(--hl-color) !important;
}

/* Carry flash */
@keyframes carryFlash {
    0% {
        opacity: 0;
    }

    30% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

.carry-arrow {
    opacity: 0;
}

.carry-arrow.active {
    animation: carryFlash 0.8s forwards;
}

/* Crank rotation */
@keyframes crankTurn {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.crank-spinning {
    transform-origin: 640px 260px;
    animation: crankTurn 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Run/Reset/Select controls */
.run-btn,
.reset-btn {
    position: absolute;
    bottom: -40px;
    font-family: 'Source Code Pro', monospace;
    font-size: 0.75rem;
    padding: 6px 14px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.3s;
    letter-spacing: 1px;
}

.run-btn {
    left: 10px;
    background: var(--brass);
    color: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(184, 134, 11, 0.3);
}

.run-btn:hover {
    background: var(--brass-lt);
    transform: scale(1.05);
}

.run-btn:active {
    transform: scale(0.95);
}

.reset-btn {
    left: 130px;
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--ink-faint);
}

.reset-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.poly-select {
    position: absolute;
    bottom: -40px;
    right: 10px;
    font-family: 'EB Garamond', serif;
    font-size: 0.8rem;
    padding: 5px 10px;
    border: 1px solid var(--ink-faint);
    background: transparent;
    color: var(--ink);
    border-radius: 3px;
    cursor: pointer;
}

/* ===== HIGHLIGHT ===== */
.highlightable {
    transition: filter 0.4s, opacity 0.4s;
}

.highlightable.highlighted {
    filter: url(#hl-glow-eng) !important;
    opacity: 1 !important;
}

.highlightable.highlighted rect,
.highlightable.highlighted line,
.highlightable.highlighted circle {
    stroke: var(--hl-color) !important;
    stroke-width: 3 !important;
    transition: stroke 0.3s, stroke-width 0.3s;
}

.highlightable.highlighted text {
    fill: var(--hl-color) !important;
}

.dimmed {
    opacity: 0.15 !important;
    transition: opacity 0.4s;
}

/* ===== FEATURE PANEL ===== */
.feature-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(240, 230, 208, 0.97);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
    overflow-y: auto;
    padding: 40px 0;
}

.feature-panel.open {
    opacity: 1;
    pointer-events: auto;
}

.close-panel-btn {
    position: fixed;
    top: 18px;
    right: 22px;
    z-index: 201;
    background: transparent;
    border: 1.5px solid var(--ink);
    width: 38px;
    height: 38px;
    font-size: 1.3rem;
    color: var(--ink);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
}

.close-panel-btn:hover {
    background: var(--ink);
    color: var(--panel-bg);
}

.feature-panel-inner {
    max-width: 680px;
    width: 90%;
    padding: 35px 25px;
}

.fp-title {
    font-family: 'Cinzel', serif;
    font-size: 1.7rem;
    color: var(--ink);
    letter-spacing: 2px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ink-faint);
}

.fp-desc {
    font-family: 'EB Garamond', serif;
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--ink);
    text-align: justify;
    margin-bottom: 20px;
}

.fp-demo-section {
    background: rgba(59, 48, 32, 0.04);
    border: 1px solid var(--ink-faint);
    border-radius: 6px;
    padding: 15px 18px;
    margin-bottom: 18px;
}

.fp-demo-title {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.8rem;
    color: var(--brass);
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.fp-demo {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 160px;
}

.fp-demo svg {
    width: 100%;
    max-width: 460px;
    height: auto;
}

.fp-demo-note {
    font-family: 'EB Garamond', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: rgba(59, 48, 32, 0.6);
    margin-top: 8px;
    text-align: center;
    line-height: 1.5;
    white-space: pre-line;
}

.fp-details {
    font-family: 'EB Garamond', serif;
    font-size: 0.92rem;
    color: rgba(59, 48, 32, 0.7);
    line-height: 1.6;
}

.fp-details h3 {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    margin: 15px 0 5px;
    color: var(--ink);
    letter-spacing: 1px;
}

.fp-details ul {
    padding-left: 16px;
    margin-bottom: 6px;
}

.fp-details li {
    margin-bottom: 3px;
}

.fp-details code {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.85rem;
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 2px;
}