/**
 * All-Combinatorial Hexachords - Enhanced Styles
 * World-class UX/UI for music theory education
 */

/* ============================================
   CSS VARIABLES - Color System
   ============================================ */

:root {
    /* Hexachord Colors */
    --h1-color: #00BFFF;
    --h1-bg: rgba(0, 191, 255, 0.15);
    --h1-bg-solid: #e6f7ff;
    --h2-color: #FF4500;
    --h2-bg: rgba(255, 69, 0, 0.15);
    --h2-bg-solid: #fff0e6;

    /* Order Colors */
    --first-order: #3b82f6;
    --second-order: #8b5cf6;
    --third-order: #10b981;
    --sixth-order: #f59e0b;

    /* Transformation Colors */
    --prime-color: #3b82f6;
    --inversion-color: #8b5cf6;
    --retrograde-color: #f59e0b;
    --ri-color: #10b981;

    /* UI Colors */
    --zero-color: #ef4444;
    --progress-color: var(--primary);
}

body.dark-mode {
    --h1-bg: rgba(0, 191, 255, 0.2);
    --h1-bg-solid: #0a2a3a;
    --h2-bg: rgba(255, 69, 0, 0.2);
    --h2-bg-solid: #3a1a0a;
}

/* ============================================
   PROGRESS BAR
   ============================================ */

.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    z-index: 9999;
    transition: width 0.1s ease-out;
    box-shadow: 0 0 10px var(--primary);
}

/* ============================================
   BACK TO TOP BUTTON
   ============================================ */

.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(20, 184, 166, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(20, 184, 166, 0.5);
}

.back-to-top:active {
    transform: scale(0.95);
}

/* ============================================
   HERO SECTION
   ============================================ */

.hero {
    position: relative;
    padding: 48px 24px;
    margin: -16px -16px 24px;
    border-radius: 0 0 24px 24px;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.hero-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        rgba(20, 184, 166, 0.1) 0%,
        rgba(8, 145, 178, 0.15) 50%,
        rgba(139, 92, 246, 0.1) 100%
    );
}

.hero-pattern {
    position: absolute;
    inset: 0;
    opacity: 0.03;
    background-image:
        repeating-linear-gradient(45deg, currentColor 0, currentColor 1px, transparent 0, transparent 50%),
        repeating-linear-gradient(-45deg, currentColor 0, currentColor 1px, transparent 0, transparent 50%);
    background-size: 20px 20px;
}

.hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.hero-badge {
    display: inline-block;
    padding: 6px 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border-radius: 20px;
    margin-bottom: 16px;
}

.hero-tagline {
    font-size: 18px;
    color: var(--text);
    line-height: 1.6;
    margin: 0 0 20px;
}

.hero-meta {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-light);
}

.meta-item svg {
    opacity: 0.7;
}

/* ============================================
   MAIN LAYOUT WITH SIDEBAR
   ============================================ */

.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}

@media (min-width: 1024px) {
    .main-layout {
        grid-template-columns: 200px 1fr;
        gap: 48px;
    }
}

/* ============================================
   TABLE OF CONTENTS SIDEBAR
   ============================================ */

.toc-sidebar {
    display: none;
}

@media (min-width: 1024px) {
    .toc-sidebar {
        display: block;
        position: sticky;
        top: 24px;
        height: fit-content;
        max-height: calc(100vh - 48px);
        overflow-y: auto;
    }
}

.toc {
    background: var(--card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.toc-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-light);
    margin-bottom: 16px;
    font-weight: 700;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toc-link {
    display: block;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-light);
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    position: relative;
}

.toc-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--primary);
    border-radius: 2px;
    transition: height 0.2s ease;
}

.toc-link:hover {
    background: var(--bg);
    color: var(--text);
}

.toc-link.active {
    color: var(--primary);
    background: rgba(20, 184, 166, 0.08);
    font-weight: 600;
}

.toc-link.active::before {
    height: 20px;
}

/* ============================================
   CONTENT SECTIONS
   ============================================ */

.content-area {
    min-width: 0;
}

.content-section {
    margin-bottom: 48px;
    scroll-margin-top: 24px;
}

.section-header {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 24px;
}

.section-number {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    font-family: 'JetBrains Mono', monospace;
}

.section-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.3;
    margin: 0;
}

.section-intro {
    font-size: 16px;
    color: var(--text-light);
    line-height: 1.7;
    margin-bottom: 24px;
}

.prose {
    margin-bottom: 24px;
}

.prose p {
    font-size: 16px;
    color: var(--text);
    line-height: 1.8;
    margin-bottom: 16px;
}

.prose .lead {
    font-size: 18px;
    color: var(--text);
}

/* ============================================
   DEFINITION CARD
   ============================================ */

.definition-card {
    background: var(--card);
    border-radius: 20px;
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin: 0;
}

.definition-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.definition-term {
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
}

.definition-source {
    font-size: 13px;
    color: var(--text-light);
    font-style: italic;
}

.definition-body {
    margin-bottom: 24px;
}

.definition-body p {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text);
    margin-bottom: 12px;
}

.definition-body a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.definition-body a:hover {
    color: var(--secondary);
}

.definition-visual {
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.order-summary {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.order-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg);
    border-radius: 12px;
    flex: 1;
    min-width: 100px;
}

.order-item.first { border-left: 4px solid var(--first-order); }
.order-item.second { border-left: 4px solid var(--second-order); }
.order-item.third { border-left: 4px solid var(--third-order); }
.order-item.sixth { border-left: 4px solid var(--sixth-order); }

.order-count {
    font-size: 32px;
    font-weight: 900;
    color: var(--text);
    line-height: 1;
}

.order-label {
    font-size: 12px;
    color: var(--text-light);
    margin-top: 4px;
}

.visual-caption {
    font-size: 14px;
    color: var(--text-light);
    text-align: center;
    margin: 0;
}

/* ============================================
   TRANSFORMATIONS GRID
   ============================================ */

.transformations-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (min-width: 640px) {
    .transformations-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.transform-card {
    background: var(--card);
    border-radius: 16px;
    padding: 20px 16px;
    text-align: center;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    cursor: default;
}

.transform-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.transform-card[data-transform="T"] { border-color: var(--prime-color); }
.transform-card[data-transform="I"] { border-color: var(--inversion-color); }
.transform-card[data-transform="R"] { border-color: var(--retrograde-color); }
.transform-card[data-transform="RI"] { border-color: var(--ri-color); }

.transform-card[data-transform="T"]:hover { background: rgba(59, 130, 246, 0.08); }
.transform-card[data-transform="I"]:hover { background: rgba(139, 92, 246, 0.08); }
.transform-card[data-transform="R"]:hover { background: rgba(245, 158, 11, 0.08); }
.transform-card[data-transform="RI"]:hover { background: rgba(16, 185, 129, 0.08); }

.transform-symbol {
    font-size: 28px;
    font-weight: 900;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 8px;
}

.transform-card[data-transform="T"] .transform-symbol { color: var(--prime-color); }
.transform-card[data-transform="I"] .transform-symbol { color: var(--inversion-color); }
.transform-card[data-transform="R"] .transform-symbol { color: var(--retrograde-color); }
.transform-card[data-transform="RI"] .transform-symbol { color: var(--ri-color); }

.transform-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.transform-desc {
    font-size: 12px;
    color: var(--text-light);
    line-height: 1.4;
}

/* ============================================
   EXAMPLE CARD
   ============================================ */

.example-card {
    background: var(--card);
    border-radius: 20px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.example-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.example-icon {
    font-size: 24px;
}

.example-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.example-content {
    padding: 24px;
}

.chromatic-demo {
    display: grid;
    gap: 24px;
}

@media (min-width: 640px) {
    .chromatic-demo {
        grid-template-columns: 1fr 1.5fr;
        align-items: center;
    }
}

.demo-circle {
    aspect-ratio: 1;
    max-width: 200px;
    margin: 0 auto;
    background: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
}

.demo-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.demo-instruction,
.demo-result,
.demo-conclusion {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    margin: 0;
}

.h1-badge,
.h2-badge,
.transform-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 14px;
}

.h1-badge {
    background: var(--h1-bg);
    color: var(--h1-color);
}

.h2-badge {
    background: var(--h2-bg);
    color: var(--h2-color);
}

.transform-badge {
    background: rgba(139, 92, 246, 0.15);
    color: var(--inversion-color);
    font-family: 'JetBrains Mono', monospace;
}

.demo-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: fit-content;
}

.demo-btn:hover {
    background: var(--secondary);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(20, 184, 166, 0.3);
}

/* ============================================
   KEY INSIGHT
   ============================================ */

.key-insight {
    display: flex;
    gap: 16px;
    padding: 24px;
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(8, 145, 178, 0.12));
    border-radius: 16px;
    border-left: 4px solid var(--primary);
}

.insight-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.insight-content h4 {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin: 0 0 8px;
}

.insight-content p {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    margin: 0;
}

/* ============================================
   HEXACHORD TABLE
   ============================================ */

.hexachord-table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.hexachord-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    min-width: 700px;
}

.hexachord-table th {
    padding: 14px 12px;
    background: var(--bg);
    font-weight: 700;
    text-align: center;
    color: var(--text-light);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.hexachord-table .th-label { text-align: left; }
.hexachord-table .th-h1 { color: var(--h1-color); }
.hexachord-table .th-h2 { color: var(--h2-color); }
.hexachord-table .th-divider { width: 8px; background: var(--border); padding: 0; }
.hexachord-table .th-icv { min-width: 100px; }
.hexachord-table .th-order { min-width: 120px; }

.hexachord-table td {
    padding: 14px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    background: var(--card);
}

.hex-row {
    transition: background 0.2s ease;
}

.hex-row:hover td {
    background: rgba(20, 184, 166, 0.04);
}

.hex-row.featured td {
    background: rgba(139, 92, 246, 0.06);
}

.hex-row.featured:hover td {
    background: rgba(139, 92, 246, 0.1);
}

.cell-label {
    font-weight: 700;
    color: var(--text);
    text-align: left !important;
}

.cell-pc {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 15px;
}

.cell-pc.h1 {
    color: var(--h1-color);
    background: var(--h1-bg);
}

.cell-pc.h2 {
    color: var(--h2-color);
    background: var(--h2-bg);
}

.cell-divider {
    width: 8px;
    background: var(--border) !important;
    padding: 0 !important;
}

.cell-icv {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text);
    letter-spacing: -0.5px;
}

.cell-icv .zero {
    color: var(--zero-color);
    font-weight: 700;
}

.cell-order {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.order-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
}

.order-badge.first {
    background: rgba(59, 130, 246, 0.15);
    color: var(--first-order);
}

.order-badge.second {
    background: rgba(139, 92, 246, 0.15);
    color: var(--second-order);
}

.order-badge.third {
    background: rgba(16, 185, 129, 0.15);
    color: var(--third-order);
}

.order-badge.sixth {
    background: rgba(245, 158, 11, 0.15);
    color: var(--sixth-order);
}

.order-name {
    font-size: 11px;
    color: var(--text-light);
}

.zero-text {
    color: var(--zero-color);
    font-weight: 600;
}

/* Table Legend */
.table-legend {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 16px;
    background: var(--bg);
    border-radius: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-light);
}

.legend-swatch {
    width: 24px;
    height: 16px;
    border-radius: 4px;
}

.legend-swatch.h1 {
    background: var(--h1-bg);
    border: 2px solid var(--h1-color);
}

.legend-swatch.h2 {
    background: var(--h2-bg);
    border: 2px solid var(--h2-color);
}

.legend-swatch.zero {
    background: rgba(239, 68, 68, 0.15);
    border: 2px solid var(--zero-color);
}

/* ============================================
   ORDERS ACCORDION
   ============================================ */

.orders-accordion {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 32px;
}

.order-details {
    background: var(--card);
    border-radius: 16px;
    border: 2px solid var(--border);
    overflow: hidden;
    transition: border-color 0.3s ease;
}

.order-details.first:hover,
.order-details.first[open] { border-color: var(--first-order); }
.order-details.second:hover,
.order-details.second[open] { border-color: var(--second-order); }
.order-details.third:hover,
.order-details.third[open] { border-color: var(--third-order); }
.order-details.sixth:hover,
.order-details.sixth[open] { border-color: var(--sixth-order); }

.order-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.order-summary::-webkit-details-marker {
    display: none;
}

.order-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.order-badge-lg {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
}

.order-badge-lg.first {
    background: rgba(59, 130, 246, 0.15);
    color: var(--first-order);
}

.order-badge-lg.second {
    background: rgba(139, 92, 246, 0.15);
    color: var(--second-order);
}

.order-badge-lg.third {
    background: rgba(16, 185, 129, 0.15);
    color: var(--third-order);
}

.order-badge-lg.sixth {
    background: rgba(245, 158, 11, 0.15);
    color: var(--sixth-order);
}

.order-sets {
    font-size: 14px;
    color: var(--text-light);
}

.order-chevron {
    transition: transform 0.3s ease;
    color: var(--text-light);
}

.order-details[open] .order-chevron {
    transform: rotate(180deg);
}

.order-content {
    padding: 0 24px 24px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.order-grid {
    display: grid;
    gap: 24px;
}

@media (min-width: 640px) {
    .order-grid {
        grid-template-columns: 200px 1fr;
    }
}

.order-image {
    background: var(--bg);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.order-image img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.order-text p {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    margin-bottom: 16px;
}

.order-text code {
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 13px;
}

.transposition-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    background: var(--bg);
    border-radius: 10px;
    margin-bottom: 16px;
}

.t-label {
    font-size: 13px;
    color: var(--text-light);
}

.t-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
    background: rgba(20, 184, 166, 0.1);
    padding: 4px 12px;
    border-radius: 6px;
}

.t-and {
    color: var(--text-light);
    font-size: 12px;
}

.note-callout,
.order-note {
    font-size: 14px;
    color: var(--text-light);
    padding: 12px 16px;
    background: rgba(20, 184, 166, 0.06);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
    margin: 0;
}

/* ============================================
   VIDEO CARDS
   ============================================ */

.video-card {
    background: var(--card);
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 32px;
}

.video-card.featured {
    border-color: var(--second-order);
}

.video-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.video-badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-radius: 20px;
    margin-bottom: 8px;
}

.video-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.video-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
}

.video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.video-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.video-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.video-cta:hover {
    color: var(--secondary);
    gap: 12px;
}

/* ============================================
   MATRIX SECTION
   ============================================ */

.matrix-intro {
    margin-bottom: 24px;
}

.matrix-intro p {
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
}

.h1-inline {
    color: var(--h1-color);
    font-weight: 700;
}

/* Matrix Legend */
.matrix-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.legend-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.legend-card .legend-color {
    width: 24px;
    height: 24px;
    border-radius: 6px;
}

.h1-legend .legend-color {
    background: var(--h1-bg);
    border: 2px solid var(--h1-color);
}

.h2-legend .legend-color {
    background: var(--h2-bg);
    border: 2px solid var(--h2-color);
}

.legend-card .legend-text {
    display: flex;
    flex-direction: column;
}

.legend-card .legend-text strong {
    font-size: 14px;
    color: var(--text);
}

.legend-card .legend-text span {
    font-size: 12px;
    color: var(--text-light);
}

/* Matrix Wrapper */
.matrix-wrapper {
    display: grid;
    gap: 24px;
    margin-bottom: 32px;
}

@media (min-width: 900px) {
    .matrix-wrapper {
        grid-template-columns: 1fr 280px;
    }
}

.matrix-scroll {
    overflow-x: auto;
    background: var(--card);
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 8px;
}

.matrix-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 600px;
}

.matrix-corner {
    width: 40px;
    background: transparent;
}

.matrix-index {
    padding: 8px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-light);
    text-align: center;
    background: var(--bg);
}

.matrix-header-row th,
.matrix-footer-row td {
    background: var(--bg);
}

.matrix-cell {
    padding: 10px 8px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    min-width: 40px;
}

.matrix-cell.h1 {
    background: var(--h1-bg);
    color: var(--h1-color);
    font-weight: 700;
}

.matrix-cell.h2-highlight {
    background: var(--h2-bg);
    color: var(--h2-color);
    font-weight: 700;
}

/* Matrix Controls */
.matrix-controls {
    position: sticky;
    top: 24px;
}

.controls-card {
    background: var(--card);
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow);
}

.controls-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.control-section {
    margin-bottom: 16px;
}

.control-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 10px;
}

.control-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.control-dot.prime { background: var(--prime-color); }
.control-dot.inversion { background: var(--inversion-color); }
.control-dot.retrograde { background: var(--retrograde-color); }
.control-dot.ri { background: var(--ri-color); }

.control-buttons {
    display: flex;
    gap: 8px;
}

.matrix-btn {
    padding: 8px 16px;
    border: 2px solid var(--border);
    background: var(--bg);
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.matrix-btn:hover {
    transform: translateY(-2px);
}

.matrix-btn.active {
    color: white;
}

.matrix-btn.prime { border-color: var(--prime-color); }
.matrix-btn.prime:hover { background: rgba(59, 130, 246, 0.1); }
.matrix-btn.prime.active { background: var(--prime-color); }

.matrix-btn.inversion { border-color: var(--inversion-color); }
.matrix-btn.inversion:hover { background: rgba(139, 92, 246, 0.1); }
.matrix-btn.inversion.active { background: var(--inversion-color); }

.matrix-btn.retrograde { border-color: var(--retrograde-color); }
.matrix-btn.retrograde:hover { background: rgba(245, 158, 11, 0.1); }
.matrix-btn.retrograde.active { background: var(--retrograde-color); }

.matrix-btn.ri { border-color: var(--ri-color); }
.matrix-btn.ri:hover { background: rgba(16, 185, 129, 0.1); }
.matrix-btn.ri.active { background: var(--ri-color); }

.control-divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

.control-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: var(--card);
    border-color: var(--primary);
    color: var(--primary);
}

.notation-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-label {
    font-size: 13px;
    color: var(--text-light);
}

.toggle-buttons {
    display: flex;
    background: var(--bg);
    border-radius: 8px;
    padding: 4px;
    flex: 1;
}

.toggle-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
}

/* ============================================
   IMAGE CARDS
   ============================================ */

.image-card {
    background: var(--card);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.image-card img {
    width: 100%;
    display: block;
}

.image-caption {
    padding: 16px;
    font-size: 14px;
    color: var(--text-light);
    text-align: center;
    background: var(--bg);
    margin: 0;
}

/* ============================================
   COMPARISON CARD
   ============================================ */

.comparison-card {
    background: var(--card);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

.comparison-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.comparison-item {
    text-align: center;
}

.comparison-label {
    display: block;
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.comparison-values {
    font-family: 'JetBrains Mono', monospace;
    font-size: 24px;
    font-weight: 700;
}

.comparison-values.h1-text {
    color: var(--h1-color);
}

.comparison-values.h2-text {
    color: var(--h2-color);
}

.comparison-divider {
    color: var(--text-light);
}

.comparison-note {
    font-size: 15px;
    color: var(--text);
    text-align: center;
    margin: 0;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ============================================
   PULL QUOTE
   ============================================ */

.pull-quote {
    position: relative;
    padding: 32px 32px 32px 48px;
    margin: 32px 0;
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.06), rgba(8, 145, 178, 0.08));
    border-radius: 16px;
    border-left: 4px solid var(--primary);
}

.pull-quote::before {
    content: '"';
    position: absolute;
    top: 16px;
    left: 16px;
    font-size: 48px;
    font-family: Georgia, serif;
    color: var(--primary);
    opacity: 0.3;
    line-height: 1;
}

.pull-quote p {
    font-size: 18px;
    line-height: 1.7;
    color: var(--text);
    font-style: italic;
    margin: 0 0 12px;
}

.pull-quote cite {
    font-size: 14px;
    color: var(--text-light);
    font-style: normal;
}

/* ============================================
   GLOSSARY GRID
   ============================================ */

.glossary-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.glossary-card {
    background: var(--card);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.glossary-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.glossary-card dt {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.glossary-card dd {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
    margin: 0;
}

/* ============================================
   SOURCES LIST
   ============================================ */

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.source-item {
    padding: 16px 20px;
    background: var(--card);
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text);
}

.source-author {
    font-weight: 600;
}

.source-item em {
    font-style: italic;
}

/* ============================================
   DARK MODE ADJUSTMENTS
   ============================================ */

body.dark-mode .hero-gradient {
    background: linear-gradient(
        135deg,
        rgba(20, 184, 166, 0.15) 0%,
        rgba(8, 145, 178, 0.2) 50%,
        rgba(139, 92, 246, 0.15) 100%
    );
}

body.dark-mode .transform-card:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

body.dark-mode .order-badge.first { background: rgba(59, 130, 246, 0.25); }
body.dark-mode .order-badge.second { background: rgba(139, 92, 246, 0.25); }
body.dark-mode .order-badge.third { background: rgba(16, 185, 129, 0.25); }
body.dark-mode .order-badge.sixth { background: rgba(245, 158, 11, 0.25); }

body.dark-mode .order-badge-lg.first { background: rgba(59, 130, 246, 0.25); }
body.dark-mode .order-badge-lg.second { background: rgba(139, 92, 246, 0.25); }
body.dark-mode .order-badge-lg.third { background: rgba(16, 185, 129, 0.25); }
body.dark-mode .order-badge-lg.sixth { background: rgba(245, 158, 11, 0.25); }

body.dark-mode .glossary-card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    .hero {
        padding: 32px 16px;
        margin: -16px -16px 20px;
    }

    .hero-tagline {
        font-size: 16px;
    }

    .section-header {
        flex-direction: column;
        gap: 8px;
    }

    .section-title {
        font-size: 24px;
    }

    .definition-card {
        padding: 24px;
    }

    .definition-term {
        font-size: 20px;
    }

    .order-summary {
        flex-direction: column;
    }

    .order-item {
        flex: auto;
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
    }

    .order-count {
        font-size: 24px;
    }

    .matrix-wrapper {
        grid-template-columns: 1fr;
    }

    .matrix-controls {
        position: static;
    }

    .controls-card {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .controls-title {
        grid-column: 1 / -1;
    }

    .control-divider {
        grid-column: 1 / -1;
    }

    .control-actions {
        grid-column: 1 / -1;
    }

    .notation-toggle {
        grid-column: 1 / -1;
    }

    .pull-quote {
        padding: 24px 24px 24px 40px;
    }

    .pull-quote p {
        font-size: 16px;
    }

    .back-to-top {
        bottom: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .hero-meta {
        flex-direction: column;
        gap: 12px;
    }

    .transformations-grid {
        grid-template-columns: 1fr;
    }

    .comparison-row {
        flex-direction: column;
        gap: 16px;
    }

    .comparison-divider {
        transform: rotate(90deg);
    }

    .glossary-grid {
        grid-template-columns: 1fr;
    }

    .controls-card {
        grid-template-columns: 1fr;
    }
}
