:root {
    --bg-base: #090B0F;
    --bg-panel: rgba(15, 18, 25, 0.85);
    --bg-input: #1A1F2B;
    --bg-hover: rgba(6, 182, 212, 0.1);

    --border-light: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(6, 182, 212, 0.3);

    --text-main: #F8FAFC;
    --text-muted: #94A3B8;

    --primary: #06B6D4;
    --primary-hover: #0891B2;
    --secondary: #22D3EE;
    --accent: #F43F5E;

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.5);

    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    overflow: hidden;
}

svg {
    display: block;
}

.w-4 {
    width: 1rem;
}

.h-4 {
    height: 1rem;
}

.w-5 {
    width: 1.25rem;
}

.h-5 {
    height: 1.25rem;
}

.w-6 {
    width: 1.5rem;
}

.h-6 {
    height: 1.5rem;
}

.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-1 {
    flex: 1;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.w-full {
    width: 100%;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-sm {
    font-size: 0.875rem;
}

.text-xl {
    font-size: 1.25rem;
}

.text-muted {
    color: var(--text-muted);
}

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

.font-bold {
    font-weight: 700;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.875rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border-color: var(--border-light);
    color: var(--text-main);
}

.btn-outline:hover {
    background: var(--bg-hover);
    border-color: var(--border-highlight);
}

.btn-icon {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.375rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.btn-small {
    padding: 0.25rem;
}

/* Code Input Area */
.code-input {
    width: 100%;
    height: 150px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8125rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
    line-height: 1.6;
}

.code-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
}

/* Select & Radios */
.select-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    padding: 0.625rem;
    border-radius: var(--radius-md);
    outline: none;
    font-size: 0.875rem;
    font-family: inherit;
    appearance: none;
}

.radio-group {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-input);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.radio-label {
    flex: 1;
    cursor: pointer;
}

.radio-label input {
    display: none;
}

.radio-btn {
    display: block;
    text-align: center;
    padding: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.radio-label input:checked+.radio-btn {
    background: var(--border-light);
    color: var(--text-main);
}

/* Glass Panel */
.glass-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 300px;
    display: flex;
    flex-direction: column;
    z-index: 20;
    border-right: 1px solid var(--border-light);
}

.brand {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--border-light);
}

.brand h2 {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.color-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.swatch-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
}

.swatch-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-light);
}

/* Workspace */
.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-base);
    position: relative;
}

.topbar {
    padding: 1rem 1.5rem;
    z-index: 10;
    border-bottom: 1px solid var(--border-light);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.matrix-container {
    flex: 1;
    overflow: auto;
    padding: 2rem;
}

.empty-state {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Matrix Table Structure */
.matrix-wrapper {
    display: inline-block;
    padding: 1px;
    background: var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.contrast-matrix {
    border-collapse: collapse;
    background: var(--bg-base);
}

.contrast-matrix th,
.contrast-matrix td {
    padding: 0;
    min-width: 100px;
    height: 100px;
    text-align: center;
    border: 1px solid var(--border-light);
    position: relative;
}

.matrix-header {
    background: var(--bg-input);
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    padding: 0.5rem !important;
    height: auto !important;
}

.matrix-header-color {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin: 0 auto 0.25rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.matrix-cell {
    cursor: pointer;
    transition: transform 0.2s, z-index 0.2s;
}

.matrix-cell:hover {
    transform: scale(1.05);
    z-index: 10;
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-md);
    outline: 2px solid var(--primary);
}

.matrix-cell-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

.ratio-val {
    font-size: 1.125rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.05em;
}

.badges {
    display: flex;
    gap: 0.25rem;
}

/* Pass/Fail Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.625rem;
    letter-spacing: 0.05em;
}

.pass-aaa {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.pass-aa {
    background: rgba(234, 179, 8, 0.15);
    color: #fde047;
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.pass-aa-lg {
    background: rgba(56, 189, 248, 0.15);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.fail {
    background: rgba(244, 63, 94, 0.15);
    color: #fb7185;
    border: 1px solid rgba(244, 63, 94, 0.3);
}

/* SVG Filters applied globally to matrix wrapper */
[data-filter="protanopia"] {
    filter: url(#protanopia);
}

[data-filter="deuteranopia"] {
    filter: url(#deuteranopia);
}

[data-filter="tritanopia"] {
    filter: url(#tritanopia);
}

[data-filter="achromatopsia"] {
    filter: url(#achromatopsia);
}

/* Preview Sidebar */
.preview-sidebar {
    width: 320px;
    border-left: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    z-index: 20;
    position: absolute;
    right: -320px;
    top: 0;
    bottom: 0;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.preview-sidebar.open {
    right: 0;
}

.preview-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

.preview-body {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.preview-box {
    padding: 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.preview-large {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    line-height: 1.2;
}

.preview-regular {
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    font-weight: 400;
}

.preview-ui {
    display: flex;
    justify-content: flex-end;
}

.preview-btn {
    background: transparent;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: default;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed var(--border-light);
    padding-bottom: 0.25rem;
}

.wcag-results {
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 1rem;
    border: 1px solid var(--border-light);
}

.wcag-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-main);
    color: var(--bg-base);
    padding: 0.75rem 1.5rem;
    border-radius: 999px;
    font-weight: 500;
    font-size: 0.875rem;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 100;
    pointer-events: none;
    box-shadow: var(--shadow-md);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}