/* ==========================================================================
   TGM SPEC SHEET - Executive Architectural Specification & Due Diligence Brief
   Print-First US Letter Layout with Zero-Server-Load PDF Export
   ========================================================================== */

:root {
    /* Executive Palette (Dark Screen Theme) */
    --bg-canvas: #07090E;
    --sheet-bg: #0D111A;
    --card-bg: #131A26;
    --card-bg-elevated: #1A2332;
    --card-border: rgba(255, 255, 255, 0.08);
    --card-border-strong: rgba(255, 255, 255, 0.16);
    
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    
    --accent-emerald: #01F5BB;
    --accent-emerald-dark: #00BA88;
    --accent-emerald-bg: rgba(1, 245, 187, 0.08);
    --accent-emerald-border: rgba(1, 245, 187, 0.3);
    
    --accent-purple: #A78BFA;
    --accent-purple-dark: #8B5CF6;
    --accent-purple-bg: rgba(167, 139, 250, 0.08);
    --accent-purple-border: rgba(167, 139, 250, 0.3);
    
    --accent-blue: #38BDF8;
    --accent-blue-dark: #0284C7;
    --accent-blue-bg: rgba(56, 189, 248, 0.08);
    --accent-blue-border: rgba(56, 189, 248, 0.3);
    
    --amber-bg: rgba(245, 158, 11, 0.12);
    --amber-border: #F59E0B;
    --amber-text: #FBBF24;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* Light Paper Theme (For On-Screen Paper Preview & Print Matching) */
body.light-theme {
    --bg-canvas: #E2E8F0;
    --sheet-bg: #FFFFFF;
    --card-bg: #F8FAFC;
    --card-bg-elevated: #F1F5F9;
    --card-border: #CBD5E1;
    --card-border-strong: #94A3B8;
    
    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-muted: #64748B;
    
    --accent-emerald: #059669;
    --accent-emerald-dark: #047857;
    --accent-emerald-bg: rgba(5, 150, 105, 0.08);
    --accent-emerald-border: rgba(5, 150, 105, 0.35);
    
    --accent-purple: #7C3AED;
    --accent-purple-dark: #6D28D9;
    --accent-purple-bg: rgba(124, 58, 237, 0.08);
    --accent-purple-border: rgba(124, 58, 237, 0.35);
    
    --accent-blue: #0284C7;
    --accent-blue-dark: #0369A1;
    --accent-blue-bg: rgba(2, 132, 199, 0.08);
    --accent-blue-border: rgba(2, 132, 199, 0.35);
    
    --amber-bg: #FEF3C7;
    --amber-border: #D97706;
    --amber-text: #92400E;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px 48px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ==========================================================================
   Screen-Only Top Toolbar
   ========================================================================== */
.spec-toolbar {
    width: 100%;
    max-width: 860px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 18px;
    background: var(--sheet-bg);
    border: 1px solid var(--card-border-strong);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    gap: 12px;
    flex-wrap: wrap;
}

.toolbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.05em;
    color: var(--text-primary);
}

.toolbar-brand span {
    color: var(--accent-emerald);
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 7px 13px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--card-border-strong);
    background: var(--card-bg);
    color: var(--text-primary);
    transition: all 0.15s ease;
    text-decoration: none;
    font-family: inherit;
}

.tool-btn:hover {
    background: var(--card-bg-elevated);
    border-color: var(--accent-emerald);
}

.tool-btn.primary {
    background: var(--accent-emerald);
    color: #07090E;
    border-color: var(--accent-emerald-dark);
    font-weight: 800;
}

body.light-theme .tool-btn.primary {
    color: #FFFFFF;
}

.tool-btn.primary:hover {
    filter: brightness(1.1);
}

/* ==========================================================================
   The Spec Sheet Container (US Letter 8.5" x 11" Ratio)
   ========================================================================== */
.spec-sheet {
    width: 100%;
    max-width: 860px;
    background: var(--sheet-bg);
    border: 1px solid var(--card-border-strong);
    border-radius: 6px;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    position: relative;
    overflow: hidden;
}

/* Loading & Error States */
.spec-loading-box, .spec-error-box {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--card-border);
    border-top-color: var(--accent-emerald);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   1. Document Header
   ========================================================================== */
.spec-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--card-border-strong);
    padding-bottom: 10px;
    gap: 16px;
}

.header-brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo-icon {
    height: 32px;
    width: auto;
    max-width: 125px;
    object-fit: contain;
    flex-shrink: 0;
}

.header-titles h1 {
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-primary);
    line-height: 1.15;
}

.header-titles .doc-subtitle {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-emerald);
    margin-top: 2px;
}

.header-telemetry-block {
    text-align: right;
    font-size: 8.5px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    line-height: 1.4;
}

.header-telemetry-block strong {
    color: var(--text-secondary);
}

/* ==========================================================================
   2. Game Profile & Scope Bar Banner
   ========================================================================== */
.spec-game-profile {
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 12px 14px;
    gap: 10px;
}

.profile-main-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.profile-meta-group {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
}

.profile-cover-art {
    width: 54px;
    height: 74px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--card-border-strong);
    background: #111827;
    flex-shrink: 0;
}

.profile-info {
    flex: 1;
}

.profile-info h2 {
    font-size: 20px;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1.15;
    margin-bottom: 3px;
    letter-spacing: -0.01em;
}

.profile-credits {
    font-size: 10px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.profile-credits strong {
    color: var(--text-primary);
}

.profile-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.profile-tag {
    font-size: 8.5px;
    font-weight: 700;
    color: var(--text-secondary);
    background: var(--card-bg-elevated);
    border: 1px solid var(--card-border);
    padding: 2px 7px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.profile-status-seal {
    text-align: right;
    flex-shrink: 0;
    padding-left: 14px;
    border-left: 1px dashed var(--card-border-strong);
}

.seal-eyebrow {
    font-size: 7.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.seal-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--amber-bg);
    border: 1px solid var(--amber-border);
    color: var(--amber-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.seal-badge.official {
    background: var(--accent-emerald-bg);
    border-color: var(--accent-emerald);
    color: var(--accent-emerald);
}

.seal-subtext {
    font-size: 8px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 3px;
}

/* 6-Field Scope Bar */
.spec-scope-bar {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--card-border);
}

.scope-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.scope-label {
    font-size: 7.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.scope-value {
    font-size: 8.5px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scope-value.pending {
    color: #F59E0B;
    font-style: italic;
    font-weight: 600;
    font-size: 8px;
}

/* ==========================================================================
   3. Tri-Metric Decoupled Benchmark Scorecard
   ========================================================================== */
.spec-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.metric-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 9px 12px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 96px;
    position: relative;
}

.metric-card.dd-card {
    border-top: 3px solid var(--accent-purple);
}

.metric-card.sge-card {
    border-top: 3px solid var(--accent-blue);
}

.metric-card.index-card {
    border-top: 3px solid var(--accent-emerald);
}

.metric-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric-title {
    font-size: 8.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.metric-badge {
    font-size: 7.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 3px;
    border: 1px solid var(--card-border);
    background: var(--card-bg-elevated);
    color: var(--text-secondary);
}

.metric-card.dd-card .metric-badge {
    color: var(--accent-purple);
    border-color: var(--accent-purple-border);
    background: var(--accent-purple-bg);
}

.metric-card.sge-card .metric-badge {
    color: var(--accent-blue);
    border-color: var(--accent-blue-border);
    background: var(--accent-blue-bg);
}

.metric-card.index-card .metric-badge {
    color: var(--accent-emerald);
    border-color: var(--accent-emerald-border);
    background: var(--accent-emerald-bg);
}

.metric-value-row {
    margin: 4px 0 2px;
}

.metric-number {
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
    font-family: var(--font-mono);
    letter-spacing: -0.03em;
}

.metric-card.dd-card .metric-number { color: var(--accent-purple); }
.metric-card.sge-card .metric-number { color: var(--accent-blue); }
.metric-card.index-card .metric-number { color: var(--accent-emerald); }

.metric-number.pending {
    font-size: 19px;
    color: #F59E0B !important;
    font-style: italic;
    font-family: var(--font-sans);
    letter-spacing: 0;
}

.metric-scale {
    font-size: 8px;
    font-weight: 700;
    color: var(--text-muted);
}

.metric-desc {
    font-size: 8px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* ==========================================================================
   4. 8-Pillar Engineering Matrix
   ========================================================================== */
.spec-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1.5px solid var(--card-border-strong);
    padding-bottom: 3px;
}

.section-heading {
    font-size: 9.5px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-primary);
}

.section-subtext {
    font-size: 8px;
    color: var(--text-muted);
    font-weight: 600;
}

.pillars-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.pillar-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 5px;
    padding: 7px 9px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 64px;
}

.pillar-box-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.pillar-name {
    font-size: 8.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
}

.pillar-score {
    font-size: 9px;
    font-weight: 800;
    font-family: var(--font-mono);
    color: var(--accent-purple);
}

.pillar-component-tag {
    font-size: 8.5px;
    font-weight: 700;
    color: var(--accent-blue);
    background: var(--accent-blue-bg);
    border: 1px solid var(--accent-blue-border);
    padding: 1px 6px;
    border-radius: 3px;
    width: fit-content;
    margin-bottom: 3px;
}

.pillar-evidence {
    font-size: 7.5px;
    color: var(--text-secondary);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================================================
   5. Genre Peer Benchmark Matrix (Top 5 + Selected Game)
   ========================================================================== */
.peer-table-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    overflow: hidden;
}

.peer-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5px;
    text-align: left;
}

.peer-table th {
    background: var(--card-bg-elevated);
    padding: 5px 8px;
    font-size: 7.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--card-border-strong);
}

.peer-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--card-border);
    color: var(--text-secondary);
}

.peer-table tr:last-child td {
    border-bottom: none;
}

.peer-table .col-rank {
    width: 32px;
    font-family: var(--font-mono);
    font-weight: 800;
    color: var(--text-muted);
}

.peer-table .col-title {
    font-weight: 700;
    color: var(--text-primary);
}

.peer-table .col-year {
    width: 44px;
    font-family: var(--font-mono);
}

.peer-table .col-dev {
    color: var(--text-muted);
}

.peer-table .col-score {
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 700;
    width: 80px;
}

.peer-table .col-score.pending {
    color: #F59E0B;
    font-style: italic;
    font-weight: 600;
}

.peer-table .col-score.dd {
    color: var(--accent-purple);
}

.peer-table .col-score.sge {
    color: var(--accent-blue);
}

.peer-table .col-score.index {
    color: var(--accent-emerald);
}

/* Target Game Highlight Row */
.peer-table tr.highlight-selected {
    background: var(--accent-emerald-bg);
    border-left: 3px solid var(--accent-emerald);
}

.peer-table tr.highlight-selected td {
    color: var(--text-primary);
    font-weight: 800;
}

.peer-table tr.highlight-selected .col-title {
    color: var(--accent-emerald);
}

.selected-badge {
    display: inline-block;
    font-size: 7px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: var(--accent-emerald);
    color: #07090E;
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

body.light-theme .selected-badge {
    color: #FFFFFF;
}

.table-footnote {
    font-size: 7.5px;
    color: var(--text-muted);
    padding: 4px 8px;
    font-style: italic;
    line-height: 1.3;
}

/* ==========================================================================
   6. Executive Verification & Conversion Footer
   ========================================================================== */
.spec-footer {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border: 1.5px solid var(--accent-emerald-border);
    border-radius: 6px;
    padding: 8px 12px;
    gap: 12px;
}

.footer-qr-block {
    width: 60px;
    height: 60px;
    background: #FFFFFF;
    padding: 3px;
    border-radius: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.footer-qr-block img, .footer-qr-block svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.footer-content {
    flex: 1;
}

.footer-eyebrow {
    font-size: 7.5px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent-emerald);
    margin-bottom: 2px;
}

.footer-headline {
    font-size: 11px;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 2px;
}

.footer-desc {
    font-size: 8px;
    color: var(--text-secondary);
    line-height: 1.35;
    margin-bottom: 3px;
}

.footer-action-links {
    font-size: 7.5px;
    font-weight: 700;
    color: var(--accent-emerald);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.footer-action-links a {
    color: var(--accent-emerald);
    text-decoration: underline;
    font-family: var(--font-mono);
}

/* ==========================================================================
   PRINT STYLES (Strict 1-Page US Letter Portrait 8.5" x 11")
   ========================================================================== */
@page {
    size: letter portrait;
    margin: 0.3in 0.35in;
}

@media print {
    body {
        background: #FFFFFF !important;
        color: #0F172A !important;
        padding: 0 !important;
        margin: 0 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .spec-toolbar {
        display: none !important;
    }

    .spec-sheet {
        max-width: 100% !important;
        width: 100% !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        background: #FFFFFF !important;
        gap: 8px !important;
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    /* Print color overrides for crisp black and white paper legibility */
    .spec-header {
        border-bottom: 2px solid #0F172A !important;
    }

    .header-titles h1 {
        color: #0F172A !important;
    }

    .header-titles .doc-subtitle {
        color: #059669 !important;
    }

    .spec-game-profile, .metric-card, .pillar-box, .peer-table-container, .spec-footer {
        background: #F8FAFC !important;
        border: 1px solid #CBD5E1 !important;
        box-shadow: none !important;
    }

    .profile-info h2 {
        color: #0F172A !important;
    }

    .profile-credits, .scope-value, .metric-number, .pillar-name, .peer-table td {
        color: #0F172A !important;
    }

    .metric-card.dd-card { border-top: 3px solid #7C3AED !important; }
    .metric-card.sge-card { border-top: 3px solid #0284C7 !important; }
    .metric-card.index-card { border-top: 3px solid #059669 !important; }

    .metric-card.dd-card .metric-number { color: #6D28D9 !important; }
    .metric-card.sge-card .metric-number { color: #0369A1 !important; }
    .metric-card.index-card .metric-number { color: #047857 !important; }

    .metric-number.pending, .scope-value.pending, .peer-table .col-score.pending {
        color: #B45309 !important;
    }

    .pillar-component-tag {
        background: #EEF2FF !important;
        border-color: #C7D2FE !important;
        color: #3730A3 !important;
    }

    .pillar-score {
        color: #6D28D9 !important;
    }

    .pillar-evidence {
        color: #334155 !important;
    }

    .peer-table th {
        background: #EDF2F7 !important;
        color: #475569 !important;
    }

    .peer-table tr.highlight-selected {
        background: #ECFDF5 !important;
        border-left: 3px solid #059669 !important;
    }

    .peer-table tr.highlight-selected .col-title {
        color: #047857 !important;
    }

    .selected-badge {
        background: #059669 !important;
        color: #FFFFFF !important;
    }

    .spec-footer {
        border-color: #059669 !important;
        background: #F8FAFC !important;
    }

    .footer-headline {
        color: #0F172A !important;
    }

    .footer-eyebrow, .footer-action-links, .footer-action-links a {
        color: #047857 !important;
    }
}

/* Responsive adjustments for mobile screen view */
@media screen and (max-width: 680px) {
    .spec-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar-actions {
        justify-content: flex-start;
    }
    .profile-main-row {
        flex-direction: column;
        align-items: flex-start;
    }
    .profile-status-seal {
        border-left: none;
        border-top: 1px dashed var(--card-border-strong);
        padding-left: 0;
        padding-top: 8px;
        width: 100%;
        text-align: left;
    }
    .spec-scope-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    .spec-metrics-grid {
        grid-template-columns: 1fr;
    }
    .pillars-grid {
        grid-template-columns: 1fr;
    }
}
