/* ------------------------------------------------------------------ */
/*  PCI Subsystem Visualizer – Styles                                  */
/*  Dark orange/blue theme                                             */
/* ------------------------------------------------------------------ */

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

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

    /* accents */
    --primary:        #f97316;
    --primary-dim:    rgba(249, 115, 22, 0.18);
    --accent:         #38bdf8;
    --accent-dim:     rgba(56, 189, 248, 0.15);

    /* domain colours */
    --pci-color:      #f97316;
    --pci-bg:         rgba(249, 115, 22, 0.10);
    --bridge-color:   #a78bfa;
    --bridge-bg:      rgba(167, 139, 250, 0.10);
    --bar-color:      #34d399;
    --bar-bg:         rgba(52, 211, 153, 0.10);
    --ecam-color:     #38bdf8;
    --ecam-bg:        rgba(56, 189, 248, 0.10);
    --io-color:       #fbbf24;
    --io-bg:          rgba(251, 191, 36, 0.10);
    --driver-color:   #f472b6;
    --driver-bg:      rgba(244, 114, 182, 0.10);
    --x86-color:      #60a5fa;
    --x86-bg:         rgba(96, 165, 250, 0.10);
    --arm-color:      #4ade80;
    --arm-bg:         rgba(74, 222, 128, 0.10);

    /* phase colours */
    --phase-pei:      #a78bfa;
    --phase-dxe:      #f97316;
    --phase-assign:   #34d399;
    --phase-driver:   #38bdf8;
    --phase-bds:      #f472b6;

    /* 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(--pci-color); }
.orb-b { width: 280px; height: 280px; bottom: -40px; right: -60px; background: var(--accent); }

/* ================================================================== */
/*  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(--pci-color) 0%, var(--accent) 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.pei-phase    { background: rgba(167,139,250,0.12);  color: var(--phase-pei);    border-color: rgba(167,139,250,0.25); }
.phase-item.dxe-phase    { background: rgba(249,115,22,0.12);   color: var(--phase-dxe);    border-color: rgba(249,115,22,0.25); }
.phase-item.assign-phase { background: rgba(52,211,153,0.12);   color: var(--phase-assign); border-color: rgba(52,211,153,0.25); }
.phase-item.driver-phase { background: rgba(56,189,248,0.12);   color: var(--phase-driver); border-color: rgba(56,189,248,0.25); }
.phase-item.bds-phase    { background: rgba(244,114,182,0.12);  color: var(--phase-bds);    border-color: rgba(244,114,182,0.25); }
.phase-item.highlight {
    animation: pulseGlow 2s ease-in-out infinite;
}
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,0.25); }
    50%      { box-shadow: 0 0 18px 4px rgba(249,115,22,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;
}
.pci-icon    { background: var(--pci-bg);    color: var(--pci-color);    border: 1px solid rgba(249,115,22,0.25); }
.bridge-icon { background: var(--bridge-bg); color: var(--bridge-color); border: 1px solid rgba(167,139,250,0.25); }
.arch-icon   { background: var(--ecam-bg);   color: var(--ecam-color);   border: 1px solid rgba(56,189,248,0.25); }
.driver-icon { background: var(--driver-bg); color: var(--driver-color); border: 1px solid rgba(244,114,182,0.25); }

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

/* ================================================================== */
/*  Config Space Toggle                                                */
/* ================================================================== */
.config-toggle {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 24px;
}
.config-toggle-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(--muted);
    cursor: pointer;
    transition: all 0.2s;
}
.config-toggle-btn:hover {
    color: var(--text);
    border-color: var(--primary);
}
.config-toggle-btn.active {
    color: var(--primary);
    background: var(--primary-dim);
    border-color: var(--primary);
}

/* ================================================================== */
/*  Config Space Cards                                                 */
/* ================================================================== */
.config-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 28px;
}
.config-card {
    padding: 22px 20px;
    border-radius: 12px;
    border: 1px solid transparent;
}
.config-card h3 { font-size: 1.05rem; margin-bottom: 6px; }
.config-card p  { color: var(--muted); font-size: 0.88rem; line-height: 1.65; }
.type0-card  { background: var(--pci-bg);    border-color: rgba(249,115,22,0.18); }
.type0-card h3  { color: var(--pci-color); }
.type1-card  { background: var(--bridge-bg); border-color: rgba(167,139,250,0.18); }
.type1-card h3  { color: var(--bridge-color); }
.ext-card    { background: var(--ecam-bg);   border-color: rgba(56,189,248,0.18); }
.ext-card h3    { color: var(--ecam-color); }

/* ================================================================== */
/*  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; }

/* ================================================================== */
/*  Register Tooltip                                                   */
/* ================================================================== */
.reg-tooltip {
    position: fixed;
    z-index: 200;
    max-width: 360px;
    background: #1a2233;
    border: 1px solid var(--primary);
    border-radius: 10px;
    padding: 14px 18px;
    font-family: var(--body);
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.6;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.reg-tooltip.visible { opacity: 1; }
.reg-tooltip .tt-name {
    color: var(--primary);
    font-family: var(--mono);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
}
.reg-tooltip .tt-offset {
    color: var(--accent);
    font-family: var(--mono);
    font-size: 0.78rem;
    margin-bottom: 6px;
}

/* ================================================================== */
/*  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;
}

/* ================================================================== */
/*  Access Section                                                     */
/* ================================================================== */
.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(249,115,22,0.25);
    display: inline-block;
}

/* ================================================================== */
/*  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(249,115,22,0.3);
    color: var(--pci-color);
}
.step-btn.reset:hover {
    background: rgba(249,115,22,0.12);
    border-color: var(--pci-color);
}
#enum-indicator {
    font-family: var(--mono);
    font-size: 0.9rem;
    color: var(--primary);
    min-width: 120px;
    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;
}

/* ================================================================== */
/*  Protocol Cards                                                     */
/* ================================================================== */
.proto-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}
.proto-card {
    background: var(--bg-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 22px 20px;
}
.proto-card h3 { color: var(--accent); font-size: 1rem; margin-bottom: 8px; font-family: var(--mono); }
.proto-card p  { color: var(--muted); font-size: 0.88rem; line-height: 1.65; }

.proto-label {
    display: inline-block;
    font-family: var(--mono);
    font-size: 0.82rem;
    padding: 4px 12px;
    border-radius: 6px;
    margin-bottom: 16px;
}
.proto-label.producer { background: var(--bar-bg); color: var(--bar-color); border: 1px solid rgba(52,211,153,0.25); }
.proto-label.consumer { background: var(--io-bg);  color: var(--io-color);  border: 1px solid rgba(251,191,36,0.25); }

.proto-desc {
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.7;
    margin-bottom: 20px;
}

/* ================================================================== */
/*  Comparison Table                                                   */
/* ================================================================== */
.arch-table-wrapper {
    overflow-x: auto;
    margin-top: 24px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
}
.arch-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.arch-table th {
    font-family: var(--head);
    font-weight: 600;
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(0,0,0,0.25);
}
.arch-table th:first-child { color: var(--text); }
.arch-table th:nth-child(2) { color: var(--x86-color); }
.arch-table th:nth-child(3) { color: var(--arm-color); }
.arch-table td {
    padding: 12px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--muted);
    line-height: 1.6;
}
.arch-table tr:last-child td { border-bottom: none; }
.arch-table tr:hover td { background: rgba(255,255,255,0.02); }
.arch-table td:first-child { color: var(--text); font-weight: 500; }

/* ================================================================== */
/*  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;
}

/* syntax highlight */
.code-block .kw  { color: #ff7b72; }
.code-block .fn  { color: #d2a8ff; }
.code-block .str { color: #a5d6ff; }
.code-block .cmt { color: #8b949e; font-style: italic; }
.code-block .typ { color: #79c0ff; }
.code-block .num { color: #79c0ff; }

/* ================================================================== */
/*  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; }

/* ================================================================== */
/*  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; }
    .config-toggle { flex-wrap: wrap; }
    .arch-table { font-size: 0.8rem; }
    .arch-table th, .arch-table td { padding: 10px 12px; }
}

@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;
    }
}
