/* ------------------------------------------------------------------ */
/*  PEI Shadow Process Visualizer – Styles                            */
/*  Dark amber/blue theme                                             */
/* ------------------------------------------------------------------ */

:root {
    /* backgrounds */
    --bg:             #0c1118;
    --bg-soft:        #131a24;
    --panel:          rgba(19, 26, 36, 0.82);
    --panel-border:   rgba(232, 168, 56, 0.12);

    /* text */
    --text:           #e6edf3;
    --muted:          #8b9bb0;

    /* accents */
    --primary:        #e8a838;
    --primary-dim:    rgba(232, 168, 56, 0.18);
    --accent:         #58a6ff;
    --accent-dim:     rgba(88, 166, 255, 0.15);

    /* memory region colours */
    --flash-color:    #e8a838;
    --flash-bg:       rgba(232, 168, 56, 0.10);
    --car-color:      #f97316;
    --car-bg:         rgba(249, 115, 22, 0.10);
    --dram-color:     #58a6ff;
    --dram-bg:        rgba(88, 166, 255, 0.10);

    /* phase colours */
    --sec-color:      #a78bfa;
    --pei-color:      #e8a838;
    --shadow-color:   #f472b6;
    --dxe-color:      #34d399;

    /* fonts */
    --head:  'Space Grotesk', system-ui, sans-serif;
    --body:  'Manrope', system-ui, sans-serif;
    --mono:  'JetBrains Mono', 'Cascadia Code', monospace;

    /* layout */
    --nav-h: 64px;
    --max-w: 1120px;
    --radius: 16px;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--nav-h) + 24px);
}

body {
    font-family: var(--body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ---- ambient orbs ---- */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.18;
    pointer-events: none;
    z-index: -1;
}
.orb-a { width: 320px; height: 320px; top: -60px; left: -80px;  background: var(--flash-color); }
.orb-b { width: 280px; height: 280px; bottom: -40px; right: -60px; background: var(--dram-color); }

/* ================================================================== */
/*  Top Navigation                                                     */
/* ================================================================== */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--nav-h);
    padding: 0 24px;
    background: rgba(12, 17, 24, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--panel-border);
}

.back-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-family: var(--head);
    white-space: nowrap;
    transition: color 0.2s;
}
.back-link:hover { color: var(--primary); }

.nav-links {
    display: flex;
    gap: 6px;
    flex: 1;
    justify-content: center;
    overflow-x: auto;
}
.nav-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-family: var(--head);
    padding: 6px 14px;
    border-radius: 8px;
    transition: all 0.2s;
    white-space: nowrap;
}
.nav-link:hover            { color: var(--text); background: var(--primary-dim); }
.nav-link.active           { color: var(--primary); background: var(--primary-dim); font-weight: 600; }

.lang-switcher { display: flex; gap: 4px; }
.lang-btn {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--muted);
    font-family: var(--head);
    font-size: 0.78rem;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.lang-btn:hover  { color: var(--text); border-color: var(--primary); }
.lang-btn.active { color: var(--primary); border-color: var(--primary); background: var(--primary-dim); }

/* ================================================================== */
/*  Sections                                                           */
/* ================================================================== */
.section {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 60px 24px 40px;
}
.section + .section { padding-top: 30px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 48px 36px;
    margin-bottom: 32px;
}

h1 {
    font-family: var(--head);
    font-size: 2.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--flash-color) 0%, var(--dram-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    text-align: center;
}
h2 {
    font-family: var(--head);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
}
h3 {
    font-family: var(--head);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}
.section-subtitle {
    color: var(--muted);
    font-size: 0.95rem;
    margin-bottom: 28px;
    text-align: center;
}
.panel > .section-subtitle { text-align: left; }

/* ================================================================== */
/*  Phase Timeline                                                     */
/* ================================================================== */
.phase-timeline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 32px 0 40px;
}
.phase-item {
    padding: 10px 18px;
    border-radius: 10px;
    font-family: var(--head);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    transition: transform 0.2s;
}
.phase-item.sec      { background: rgba(167,139,250,0.12); color: var(--sec-color); border-color: rgba(167,139,250,0.25); }
.phase-item.pei-pre  { background: rgba(232,168,56,0.10);  color: var(--pei-color); border-color: rgba(232,168,56,0.22); }
.phase-item.shadow   { background: rgba(244,114,182,0.12); color: var(--shadow-color); border-color: rgba(244,114,182,0.30); }
.phase-item.pei-post { background: rgba(88,166,255,0.10);  color: var(--accent); border-color: rgba(88,166,255,0.22); }
.phase-item.dxe      { background: rgba(52,211,153,0.10);  color: var(--dxe-color); border-color: rgba(52,211,153,0.22); }
.phase-item.highlight {
    animation: pulseGlow 2s ease-in-out infinite;
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244,114,182,0.25); }
    50%      { box-shadow: 0 0 18px 4px rgba(244,114,182,0.18); }
}
.phase-arrow {
    color: var(--muted);
    font-size: 1.1rem;
    user-select: none;
}

/* ================================================================== */
/*  Info Cards (Overview)                                              */
/* ================================================================== */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}
.info-card {
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 28px 24px;
    transition: transform 0.25s, box-shadow 0.25s;
}
.info-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.info-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--head);
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 16px;
}
.flash-icon { background: var(--flash-bg); color: var(--flash-color); border: 1px solid rgba(232,168,56,0.25); }
.car-icon   { background: var(--car-bg);   color: var(--car-color);   border: 1px solid rgba(249,115,22,0.25); }
.dram-icon  { background: var(--dram-bg);  color: var(--dram-color);  border: 1px solid rgba(88,166,255,0.25); }

.info-card p { color: var(--muted); font-size: 0.9rem; line-height: 1.7; }

/* ================================================================== */
/*  Architecture Cards                                                 */
/* ================================================================== */
.arch-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 28px;
}
.arch-card {
    padding: 22px 20px;
    border-radius: 12px;
    border: 1px solid transparent;
}
.arch-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.arch-card p  { color: var(--muted); font-size: 0.88rem; line-height: 1.65; }
.flash-card { background: var(--flash-bg); border-color: rgba(232,168,56,0.18); }
.flash-card h3 { color: var(--flash-color); }
.car-card   { background: var(--car-bg);   border-color: rgba(249,115,22,0.18); }
.car-card h3   { color: var(--car-color); }
.dram-card  { background: var(--dram-bg);  border-color: rgba(88,166,255,0.18); }
.dram-card h3  { color: var(--dram-color); }

/* ================================================================== */
/*  Diagram Containers                                                 */
/* ================================================================== */
.diagram-container {
    width: 100%;
    margin: 20px 0;
    border-radius: 12px;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.05);
    overflow: hidden;
}
.diagram-container svg {
    display: block;
    width: 100%;
    height: auto;
}
.flow-diagram-container {
    min-height: 420px;
}

/* ================================================================== */
/*  Step Controls                                                      */
/* ================================================================== */
.step-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.step-btn {
    font-family: var(--head);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 20px;
    border-radius: 8px;
    border: 1px solid var(--panel-border);
    background: var(--bg-soft);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}
.step-btn:hover:not(:disabled) {
    background: var(--primary-dim);
    border-color: var(--primary);
    color: var(--primary);
}
.step-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.step-btn.reset {
    border-color: rgba(244,114,182,0.3);
    color: var(--shadow-color);
}
.step-btn.reset:hover {
    background: rgba(244,114,182,0.12);
    border-color: var(--shadow-color);
}
#flow-indicator {
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--primary);
    min-width: 100px;
    text-align: center;
}

/* ================================================================== */
/*  Step Description                                                   */
/* ================================================================== */
.step-description {
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 24px;
    margin-top: 16px;
}
.step-description h3 {
    color: var(--primary);
    margin-bottom: 10px;
}
.step-description p {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.7;
}
.step-detail {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--panel-border);
    font-size: 0.85rem !important;
    font-style: italic;
    opacity: 0.8;
}

/* ================================================================== */
/*  Fixup Section                                                      */
/* ================================================================== */
.fixup-intro {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.7;
    margin-bottom: 20px;
}
.formula-box {
    text-align: center;
    margin: 20px 0 28px;
}
.formula-box code {
    font-family: var(--mono);
    font-size: 1.05rem;
    color: var(--primary);
    background: var(--primary-dim);
    padding: 12px 28px;
    border-radius: 10px;
    border: 1px solid rgba(232,168,56,0.25);
    display: inline-block;
}
.fixup-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 24px;
}
.fixup-card {
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 22px 20px;
}
.fixup-card h3 { color: var(--accent); font-size: 1rem; margin-bottom: 8px; }
.fixup-card p  { color: var(--muted); font-size: 0.88rem; line-height: 1.65; }

/* ================================================================== */
/*  Code Blocks                                                        */
/* ================================================================== */
.code-blocks {
    display: flex;
    flex-direction: column;
    gap: 28px;
}
.code-block {
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 24px;
}
.code-block h3 { color: var(--primary); margin-bottom: 6px; }
.code-block > p { color: var(--muted); font-size: 0.88rem; margin-bottom: 16px; }

.code-block pre {
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 20px;
    overflow-x: auto;
    font-size: 0.82rem;
    line-height: 1.6;
}
.code-block code {
    font-family: var(--mono);
    color: #c9d1d9;
}

/* ================================================================== */
/*  Reference Grid                                                     */
/* ================================================================== */
.ref-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-top: 20px;
}
.ref-card {
    display: block;
    text-decoration: none;
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 22px 20px;
    transition: all 0.25s;
}
.ref-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.ref-card h3 { color: var(--primary); font-size: 1rem; margin-bottom: 6px; }
.ref-card p  { color: var(--muted); font-size: 0.85rem; line-height: 1.55; }

/* ================================================================== */
/*  Footer                                                             */
/* ================================================================== */
footer {
    max-width: var(--max-w);
    margin: 0 auto;
    text-align: center;
    padding: 40px 24px 48px;
    border-top: 1px solid var(--panel-border);
}
footer p   { color: #6e6e6e; font-size: 0.85rem; }
footer a   { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ================================================================== */
/*  SVG shared styles (injected into SVG via class names)              */
/* ================================================================== */
/* These are applied via inline style in JS-generated SVG */

/* ================================================================== */
/*  Responsive                                                         */
/* ================================================================== */
@media (max-width: 768px) {
    :root { --nav-h: 56px; }
    h1 { font-size: 1.8rem; }
    .panel { padding: 28px 18px; }
    .phase-timeline { gap: 6px; }
    .phase-item { padding: 7px 10px; font-size: 0.75rem; }
    .phase-arrow { font-size: 0.9rem; }
    .nav-links { gap: 2px; }
    .nav-link { font-size: 0.75rem; padding: 5px 8px; }
    .back-link { font-size: 0.78rem; }
    .step-controls { gap: 8px; }
    .step-btn { padding: 6px 12px; font-size: 0.8rem; }
    .flow-diagram-container { min-height: 320px; }
}

@media (max-width: 480px) {
    .phase-timeline { flex-direction: column; align-items: stretch; }
    .phase-arrow { text-align: center; transform: rotate(90deg); }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
