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

.hidden {
    display: none !important;
}

:root {
    --primary: #5a7a8c;
    --primary-dark: #4a6b7c;
    --primary-light: #6a8a9c;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --lima-lime: #B3DF4D;
    --catalog-teal: #142C3D;
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --surface-code: #f8fafc;
    --text: #1e293b;
    --text-light: #64748b;
    --border: #e2e8f0;
    --border-elevated: #cbd5e1;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --sidebar-width: 280px;
    --scrollbar-thumb: #cbd5e1;
    --scrollbar-track: #f1f5f9;
    color-scheme: light;
}

/* Dark theme */
[data-theme="dark"] {
    --primary: #6a8a9c;
    --primary-dark: #5a7a8c;
    --primary-light: #7a9aac;
    --secondary: #94a3b8;
    --success: #34d399;
    --warning: #fbbf24;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-elevated: #2d3748;
    --surface-code: #1a202c;
    --text: #f1f5f9;
    --text-light: #94a3b8;
    --border: #334155;
    --border-elevated: #475569;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
    --scrollbar-thumb: #475569;
    --scrollbar-track: #1e293b;
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Header - Compact */
header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.25rem 0;
    box-shadow: var(--shadow-lg);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 1.5rem 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.header-icon {
    width: 96px;
    height: 96px;
    border-radius: 10px;
}

.header-text h1 {
    font-size: 1.875rem;
    margin-bottom: 0.125rem;
    line-height: 1.2;
}

.header-text .subtitle {
    font-size: 0.875rem;
    opacity: 0.9;
}

.header-stats {
    display: flex;
    gap: 2rem;
}

.stat-compact {
    text-align: center;
}

.stat-compact .stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-compact .stat-label {
    display: block;
    font-size: 0.75rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Header Controls (Theme + Help) */
.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Keyboard Help Button */
.keyboard-help-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
}

.keyboard-help-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.keyboard-help-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Theme Switcher */
.theme-switcher {
    display: flex;
    gap: 0.25rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.25rem;
    border-radius: 0.5rem;
    backdrop-filter: blur(10px);
}

.theme-option {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.25rem;
    padding: 0.375rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0.7;
    line-height: 1;
}

.theme-option:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.theme-option.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.25);
}

.theme-option:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Sidebar Search Box */
.sidebar .search-box {
    width: 100%;
    position: relative;
}

.sidebar .search-box input {
    width: 100%;
    padding: 0.625rem 2rem 0.625rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    transition: border-color 0.2s;
    background: var(--surface);
    color: var(--text);
}

.sidebar .search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Type Checkboxes - 2-column grid layout */
.type-checkboxes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.checkbox-column {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0.125rem 0;
}

.checkbox-label input[type="checkbox"] {
    width: 0.75rem;
    height: 0.75rem;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-label input[type="checkbox"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 3px;
    box-shadow: 0 0 0 3px rgba(90, 122, 140, 0.2);
}

.checkbox-label:hover {
    color: var(--primary);
}

/* Sidebar Select */
.sidebar-select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s;
}

.sidebar-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Clear Button in Sidebar */
.sidebar .clear-btn {
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
    color: var(--text);
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar .clear-btn:hover {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

/* Construction Warning Banner */
.construction-warning {
    max-width: 1600px;
    margin: 1.5rem auto;
    padding: 1rem 1.5rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    border-radius: 0.375rem;
    color: #856404;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.construction-warning strong {
    font-weight: 600;
}

:root[data-theme="dark"] .construction-warning {
    background: rgba(255, 193, 7, 0.15);
    border-color: #ffc107;
    color: rgba(255, 193, 7, 0.95);
}

/* Main Layout - Sidebar + Content */
.main-layout {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    gap: 2rem;
    padding: 0 1.5rem;
    min-height: calc(100vh - 300px);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 1.5rem 0.75rem 1.5rem 0.5rem;
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.sidebar-header .sidebar-title {
    margin-bottom: 0;
}

.clear-keywords-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.clear-keywords-btn:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

/* Selected Keywords */
.selected-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.selected-keywords:not(:empty) {
    margin-bottom: 0.75rem;
}

.selected-keyword {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--primary);
    color: white;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.selected-keyword:hover {
    background: var(--primary-dark);
}

.selected-keyword:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.selected-keyword .remove {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
}

/* Keyword Cloud */
.keyword-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
}

.keyword-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.75rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.keyword-tag:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.keyword-tag:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.keyword-tag.selected {
    background: var(--primary-light);
    border-color: var(--primary);
    color: white;
}

.keyword-count {
    font-size: 0.6875rem;
    opacity: 0.7;
    font-weight: 600;
}

/* Dynamic Keywords (org/repo filters) */
.keyword-tag-dynamic {
    background: linear-gradient(135deg, #e0f2f1 0%, #b2dfdb 100%);
    border-color: #80cbc4;
    color: #00695c;
}

.keyword-tag-dynamic:hover {
    border-color: #26a69a;
    color: #004d40;
    background: linear-gradient(135deg, #b2dfdb 0%, #80cbc4 100%);
}

.keyword-tag-dynamic:focus {
    outline: 2px solid #26a69a;
    outline-offset: 2px;
}

.selected-keyword-dynamic {
    background: linear-gradient(135deg, #26a69a 0%, #00897b 100%);
    border-color: #00796b;
}

.selected-keyword-dynamic:hover {
    background: linear-gradient(135deg, #00897b 0%, #00695c 100%);
}

.selected-keyword-dynamic:focus {
    outline: 2px solid #26a69a;
    outline-offset: 2px;
}

/* Dark theme adjustments for dynamic keywords */
[data-theme="dark"] .keyword-tag-dynamic {
    background: linear-gradient(135deg, #1a4d47 0%, #0d3d38 100%);
    border-color: #26a69a;
    color: #80cbc4;
}

[data-theme="dark"] .keyword-tag-dynamic:hover {
    border-color: #4db6ac;
    color: #b2dfdb;
    background: linear-gradient(135deg, #0d3d38 0%, #004d45 100%);
}

[data-theme="dark"] .selected-keyword-dynamic {
    background: linear-gradient(135deg, #00897b 0%, #00695c 100%);
    border-color: #004d40;
}

[data-theme="dark"] .selected-keyword-dynamic:hover {
    background: linear-gradient(135deg, #00695c 0%, #004d40 100%);
}

/* Highlighted keywords (from selected template) */
.keyword-tag-highlighted {
    background: #fff9c4;
    border-color: #f9a825;
    color: #f57f17;
    font-weight: 700;
}

.keyword-tag-highlighted:hover {
    background: #fff59d;
    border-color: #f57f17;
    color: #e65100;
}

[data-theme="dark"] .keyword-tag-highlighted {
    background: #ffd54f;
    border-color: #ffb300;
    color: #3e2723;
    font-weight: 700;
}

[data-theme="dark"] .keyword-tag-highlighted:hover {
    background: #ffc107;
    border-color: #ff8f00;
    color: #1b0000;
}

/* Category List */
.category-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.25rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.category-item:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.category-item:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.category-item.selected {
    background: var(--primary-light);
    border-color: var(--primary);
    color: white;
}

.category-name {
    font-size: 0.75rem;
    font-weight: 500;
}

.category-count {
    font-size: 0.6875rem;
    opacity: 0.7;
    font-weight: 600;
}

/* Content Area */
.content {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 0;
}

/* Loading & Error */
.loading, .error {
    text-align: center;
    padding: 3rem;
    font-size: 1.125rem;
}

.error {
    color: #dc2626;
    background: #fef2f2;
    border-radius: 0.5rem;
}

/* Templates Grid */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

.template-card {
    background: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.25rem;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border);
    overflow: visible; /* Allow debug popup to extend outside card */
    scroll-margin: 0.625rem; /* Half the gap (1.25rem) for better visibility when navigating */
    position: relative; /* For debug score positioning */
}

.template-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.template-card:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.875rem;
    gap: 0.75rem;
}

.template-title {
    flex: 1 1 auto;
    min-width: 0;
}

.template-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
    word-break: break-word;
    transition: color 0.2s ease;
}

.template-name:hover {
    color: var(--primary);
    text-decoration: underline;
}

.template-id {
    font-size: 0.6875rem;
    color: var(--text-light);
    font-family: monospace;
    word-break: break-word;
}

.template-badge {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.template-badge.official {
    background: var(--lima-lime);
    color: #2d4a5a;
}

.template-badge.community {
    background: #64748b;
    color: white;
}

.template-description {
    color: var(--text-light);
    font-size: 0.8125rem;
    margin-bottom: 0.875rem;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
    margin-bottom: 0.875rem;
    font-size: 0.8125rem;
}

.template-category {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text);
    font-weight: 500;
    font-size: 0.75rem;
}

.template-os {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-light);
    font-size: 0.75rem;
}

.template-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.875rem;
}

.keyword {
    padding: 0.125rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.6875rem;
    color: var(--text-light);
}

.keyword-highlighted {
    background: #fff9c4;
    border-color: #f9a825;
    color: #f57f17;
    font-weight: 700;
}

[data-theme="dark"] .keyword-highlighted {
    background: #ffd54f;
    border-color: #ffb300;
    color: #3e2723;
    font-weight: 700;
}

.template-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.875rem;
    border-top: 1px solid var(--border);
}

.template-repo {
    font-size: 0.8125rem;
    color: var(--text-light);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-repo:hover {
    color: var(--primary);
    text-decoration: underline;
}

.template-stars {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: var(--warning);
    flex-shrink: 0;
}

/* Footer */
footer {
    background: var(--surface);
    padding: 2rem 0;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text-light);
    margin-top: 3rem;
}

footer a {
    color: var(--primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Responsive */
@media (max-width: 640px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding-top: 1rem;
        position: static;
        max-height: none;
        overflow-y: visible;
    }

    .sidebar-section {
        margin-bottom: 1.5rem;
    }

    .keyword-cloud, .category-list {
        max-height: none;
    }
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-stats {
        gap: 1.5rem;
    }

    .container-wide {
        flex-direction: column;
        align-items: stretch;
    }

    .quick-filters {
        width: 100%;
        justify-content: space-between;
    }

    .quick-filters select {
        flex: 1;
    }

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

    .header-title h1 {
        font-size: 1.5rem;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
}

.modal-content {
    position: relative;
    background: var(--surface-elevated);
    border: 1px solid var(--border-elevated);
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.3);
    width: 100%;
    max-width: 900px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.15s ease-in;
}

.modal-content.ready {
    opacity: 1;
}

.modal-header {
    display: flex;
    align-items: start;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-elevated);
    gap: 1rem;
}

.modal-title-section {
    flex: 1;
    min-width: 0;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.modal-github-url {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-light);
}

.github-scheme-url {
    font-family: monospace;
}

.copy-button-inline {
    padding: 0.125rem 0.375rem;
    margin-left: 0.5rem;
    font-size: 0.625rem;
    font-weight: 500;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-elevated);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.copy-button-inline:hover {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

.copy-button-inline:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

.copy-button-inline:active {
    transform: scale(0.95);
}

.copy-button-inline.copied {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
}

.modal-code-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.copy-yaml-button {
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border-elevated);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    z-index: 10;
}

.copy-yaml-button:hover {
    background: var(--surface);
    color: var(--primary);
    border-color: var(--primary);
}

.copy-yaml-button:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    background: var(--surface);
    color: var(--primary);
    border-color: var(--primary);
}

.copy-yaml-button:active {
    transform: scale(0.95);
}

.copy-yaml-button.copied {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
}

.modal-close {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-light);
    transition: all 0.2s;
}

.modal-close:hover,
.modal-close:focus {
    outline: none;
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.modal-body {
    flex: 1;
    overflow: hidden;
    padding: 1.5rem;
    min-height: 400px;
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-light);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.modal-loading.hidden {
    display: none;
}

.modal-code {
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    font-size: 0.8125rem;
    line-height: 1.5;
    overflow: auto;
    flex: 0 1 auto;
    max-height: 100%;
    /* Firefox scrollbar styling */
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    scrollbar-width: thin;
}

/* WebKit scrollbar styling (Chrome, Safari, Edge) */
.modal-code::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.modal-code::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.modal-code::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
    border: 2px solid var(--scrollbar-track);
}

.modal-code::-webkit-scrollbar-thumb:hover {
    background: var(--border-elevated);
}

.modal-code.hidden {
    display: none;
}

.modal-code code {
    display: block;
    padding: 1rem;
    background: var(--surface-code);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    box-sizing: border-box;
    width: fit-content;
    min-width: 100%;
}

/* Similar Templates Section */
.similar-templates-section {
    margin-bottom: 1rem;
}

.similar-templates-title {
    margin: 0 0 0.25rem 0;
    padding-left: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.item-diff-stats {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    margin-left: auto;
    padding-right: 0.5rem;
}

.diff-additions {
    color: #22c55e;
    font-weight: 600;
    margin-right: 0.25rem;
}

.diff-deletions {
    color: #ef4444;
    font-weight: 600;
}

.similar-templates-list {
    display: flex;
    flex-direction: column;
    max-height: calc(4 * 1.75rem); /* 4 lines, each ~1.75rem tall */
    overflow-y: scroll; /* Always show scrollbar, even without overflow */
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    background: var(--bg-secondary);
}

.similar-templates-list:focus {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}

/* WebKit scrollbar styling for similar templates list (Chrome, Safari, Edge) */
/* Force non-overlay scrollbar that doesn't fade away on macOS */
.similar-templates-list::-webkit-scrollbar {
    -webkit-appearance: none;
    background-color: var(--scrollbar-track);
    width: 14px;
}

.similar-templates-list::-webkit-scrollbar-track {
    background-color: var(--scrollbar-track);
    border-left: 1px solid var(--border);
}

.similar-templates-list::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    background-clip: padding-box;
    border-radius: 7px;
    border: 3px solid var(--scrollbar-track);
    min-height: 40px;
}

.similar-templates-list::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-light);
}

.similar-templates-list::-webkit-scrollbar-button {
    display: none;
}

.similar-templates-list::-webkit-scrollbar-corner {
    background: transparent;
}

/* Hide scrollbar when there are 4 or fewer items (no overflow) */
.similar-templates-list.no-scroll {
    overflow-y: hidden;
}

.similar-template-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-size: 0.8125rem;
    line-height: 1.4;
    min-height: 1.75rem;
    box-sizing: border-box;
}

.similar-template-item:last-child {
    border-bottom: none;
}

.similar-template-item:hover {
    background: var(--bg-elevated);
}

.similar-template-item.selected {
    background: var(--primary);
    color: white;
}

.similar-template-item.selected .similar-template-path {
    color: white;
}

.similar-template-item.selected .similarity-percentage {
    color: rgba(255,255,255,0.9);
}

.similar-template-tooltip {
    position: fixed;
    background: var(--surface-elevated);
    border: 1px solid var(--border-elevated);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-light);
    white-space: nowrap;
    z-index: 10001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

.similar-template-path {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-family: var(--font-mono, monospace);
}

.duplicate-badge {
    padding: 0.0625rem 0.25rem;
    border-radius: 0.1875rem;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 3.5rem;
    text-align: center;
    display: inline-block;
}

.duplicate-badge.exact {
    background: #ef4444;
    color: white;
}

.duplicate-badge.near {
    background: #f97316;
    color: white;
}

.duplicate-badge.similar {
    background: #3b82f6;
    color: white;
}

.duplicate-badge.original {
    background: #10b981;
    color: white;
}

.similarity-percentage {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-light);
    min-width: 2rem;
    text-align: right;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Diff syntax highlighting enhancements */
.language-diff .hljs-addition {
    background-color: rgba(46, 160, 67, 0.15);
    color: #22863a;
    display: inline-block;
    width: 100%;
}

.language-diff .hljs-deletion {
    background-color: rgba(248, 81, 73, 0.15);
    color: #cb2431;
    display: inline-block;
    width: 100%;
}

.language-diff .hljs-meta {
    color: #6f42c1;
    font-weight: 600;
}

/* Dark mode diff colors */
@media (prefers-color-scheme: dark) {
    .language-diff .hljs-addition {
        background-color: rgba(46, 160, 67, 0.2);
        color: #85e89d;
    }

    .language-diff .hljs-deletion {
        background-color: rgba(248, 81, 73, 0.2);
        color: #f97583;
    }

    .language-diff .hljs-meta {
        color: #b392f0;
    }
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-elevated);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
}

.modal-footer-url {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
}

.modal-footer-url a {
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
}

.modal-footer-url a:hover {
    text-decoration: underline;
}

.modal-button {
    padding: 0.625rem 1.25rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
}

.modal-button.primary {
    background: var(--primary);
    color: white;
    border: none;
}

.modal-button.primary:hover {
    background: var(--primary-dark);
}

.modal-button.primary:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    background: var(--primary-dark);
}

.modal-button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-elevated);
}

.modal-button.secondary:hover {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

.modal-button.secondary:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

/* Keyboard Help Overlay */
.keyboard-help-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.keyboard-help-content {
    background: var(--surface);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    max-width: 900px;
    width: 100%;
    height: 850px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
}

.keyboard-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: #3C5E6D;
}

.keyboard-help-header h2 {
    margin: 0;
    font-size: 1.125rem;
}

.keyboard-help-header h2 .title-lima {
    color: var(--lima-lime) !important;
}

.keyboard-help-header h2 .title-catalog {
    color: var(--catalog-teal) !important;
}

.keyboard-help-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 0;
    width: 1.75rem;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.keyboard-help-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
}

.keyboard-help-close:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.keyboard-help-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    background: var(--bg-light);
}

.help-tab {
    background: none;
    border: none;
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    position: relative;
    top: 1px;
}

.help-tab:hover {
    color: var(--text);
    background: var(--bg);
}

.help-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--surface);
}

.help-tab:focus {
    outline: none;
    box-shadow: inset 0 -2px 0 0 var(--primary);
}

.tab-content {
    display: none !important;
}

.tab-content.active {
    display: block !important;
}

.tab-content h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    color: var(--text);
    font-weight: 700;
}

.tab-content h4 {
    margin: 1.25rem 0 0.5rem 0;
    font-size: 0.875rem;
    color: var(--text);
    font-weight: 700;
}

.tab-content p {
    margin: 0 0 0.75rem 0;
    line-height: 1.6;
    color: var(--text);
    font-size: 0.875rem;
}

.tab-content ul {
    margin: 0.5rem 0 1rem 0;
    padding-left: 1.5rem;
    color: var(--text);
    font-size: 0.875rem;
    line-height: 1.6;
}

.tab-content li {
    margin-bottom: 0.375rem;
}

.tab-content a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.tab-content a:hover {
    text-decoration: underline;
}

.warning-box {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-left: 4px solid #ffc107;
    border-radius: 0.25rem;
    padding: 1rem;
    margin: 1rem 0;
}

:root[data-theme="dark"] .warning-box {
    background: rgba(255, 193, 7, 0.15);
    border-color: #ffc107;
}

.warning-box h4 {
    margin: 0 0 0.5rem 0;
    color: #856404;
    font-size: 0.875rem;
    font-weight: 700;
}

:root[data-theme="dark"] .warning-box h4 {
    color: #ffc107;
}

.warning-box p {
    margin: 0;
    color: #856404;
    font-size: 0.8125rem;
    line-height: 1.5;
}

:root[data-theme="dark"] .warning-box p {
    color: rgba(255, 193, 7, 0.9);
}

.keyboard-help-body {
    padding: 1.25rem;
    flex: 1;
    overflow-y: auto;
}

/* Two-column layout for keyboard help tab only when active */
#tab-help.active {
    display: grid !important;
    gap: 1.25rem;
    grid-template-columns: 1fr;
}

@media (min-width: 600px) {
    #tab-help.active {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }
}

.keyboard-help-section h3 {
    margin: 0 0 0.625rem 0;
    font-size: 0.875rem;
    color: var(--text);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.keyboard-shortcuts {
    display: grid;
    gap: 0.5rem;
    margin: 0;
}

.keyboard-shortcuts dt {
    font-weight: 600;
    color: var(--text);
    display: flex;
    gap: 0.25rem;
    align-items: center;
    font-size: 0.8125rem;
}

.keyboard-shortcuts dd {
    margin: 0;
    color: var(--text-light);
    font-size: 0.75rem;
    padding-left: 0.75rem;
    margin-bottom: 0.25rem;
}

.keyboard-shortcuts kbd {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-size: 0.6875rem;
    font-family: monospace;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.1875rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    color: var(--text);
    font-weight: 600;
}

/* Mobile Modal */
@media (max-width: 768px) {
    .modal {
        padding: 0;
    }

    .modal-content {
        max-height: 100vh;
        border-radius: 0;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-button {
        width: 100%;
        text-align: center;
    }

    .keyboard-help-content {
        max-height: 95vh;
        border-radius: 0.5rem;
    }

    .keyboard-help-header {
        padding: 0.875rem 1rem;
    }

    .keyboard-help-body {
        padding: 1rem;
    }
}

/* Shake animation for feedback when typing disallowed characters */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

/* Debug Mode */
.debug-mode-notification {
    position: fixed;
    top: 5rem;
    right: 1.5rem;
    background: var(--surface-elevated);
    color: var(--text);
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 10000;
    border: 1px solid var(--border-elevated);
    opacity: 1;
    transition: opacity 0.3s ease;
}

.debug-mode-notification.fade-out {
    opacity: 0;
}

.debug-score-popup {
    display: none;
    position: fixed;
    background: var(--surface-elevated);
    border: 1px solid var(--border-elevated);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    min-width: 200px;
    z-index: 10000;
    white-space: nowrap;
}

.debug-popup-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.debug-popup-items {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.debug-popup-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 1rem;
    font-size: 0.6875rem;
}

.debug-popup-label {
    color: var(--text-light);
}

.debug-popup-value {
    color: var(--text);
    font-weight: 600;
    font-family: monospace;
    text-align: right;
}

.debug-popup-rank {
    color: var(--text-light);
    font-family: monospace;
    font-size: 0.625rem;
    text-align: right;
    min-width: 2rem;
}

.debug-popup-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.debug-popup-penalty .debug-popup-value {
    color: #ef4444; /* Red color for negative penalties */
}

.debug-popup-total {
    font-weight: 600;
    font-size: 0.75rem;
}

.debug-popup-total .debug-popup-label {
    color: var(--text);
}

.debug-popup-total .debug-popup-value {
    color: var(--warning);
}
