:root {
    /* Color Palette - Light */
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    --primary: #3b82f6;
    --primary-hover: #2563eb;

    --success: #10b981;
    --success-bg: #d1fae5;
    --fail: #ef4444;
    --fail-bg: #fee2e2;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.theme-dark {
    /* Color Palette - Dark */
    --bg-base: #020617;
    --bg-surface: #0f172a;
    --bg-surface-elevated: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --border-hover: #475569;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.15);
    --fail: #f87171;
    --fail-bg: rgba(239, 68, 68, 0.15);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 1.5rem;
}

/* Header */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

/* Buttons */
.icon-btn,
.icon-btn-sm {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.icon-btn {
    padding: 0.5rem;
}

.icon-btn-sm {
    padding: 0.375rem;
}

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

.theme-dark .sun-icon {
    display: none;
}

.theme-light .moon-icon {
    display: none;
}

/* Tooltips */
.tooltip-trigger {
    position: relative;
}

.tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--text-main);
    color: var(--bg-base);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s;
    font-weight: 500;
}

.tooltip-trigger:hover .tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: minmax(300px, 1fr) minmax(350px, 1fr) 280px;
    gap: 2rem;
    padding-bottom: 2rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr 1fr;
    }

    .saved-panel {
        grid-column: 1 / -1;
        margin-top: 2rem;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Inputs */
.color-inputs {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-picker-wrapper {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}

input[type="color"] {
    width: 150%;
    height: 150%;
    margin: -25%;
    /* Hide the default border of color picker in some browsers */
    cursor: pointer;
    border: none;
    padding: 0;
}

.hex-input {
    flex-grow: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    text-transform: uppercase;
    transition: all 0.2s;
}

.hex-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Preview Area */
.preview-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.preview-header {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gradient-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    padding: 0.25rem;
    transition: all 0.2s;
}

.gradient-toggle:hover {
    color: var(--text-main);
}

.gradient-toggle.active {
    color: var(--primary);
}

.preview-content {
    padding: 2rem;
    /* transition: background 0.3s ease, color 0.3s ease; */
    /* Handled by JS for immediate feedback */
}

/* The structural elements inside preview inherit current text color */
.preview-xl {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.preview-lg {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1rem;
}

.preview-md {
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

.preview-ui {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.preview-input {
    background: transparent;
    border: 1px solid currentColor;
    color: currentColor;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.875rem;
    width: 140px;
    opacity: 0.7;
}

.preview-input::placeholder {
    color: currentColor;
    opacity: 0.5;
}

.preview-btn {
    background: currentColor;
    color: var(--preview-bg, transparent);
    /* Set via JS */
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
}

/* Results Panel */
.ratio-display {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 2rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.ratio-value-wrapper {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.25rem;
    font-family: var(--font-mono);
}

.ratio-value {
    font-size: 4rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.05em;
    color: var(--text-main);
    transition: color 0.3s;
}

.ratio-suffix {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-muted);
}

.ratio-label {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Status Colors dynamically updated */
.ratio-display.status-fail .ratio-value {
    color: var(--fail);
}

.ratio-display.status-pass .ratio-value {
    color: var(--success);
}

/* WCAG Grid */
.wcag-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.wcag-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    transition: all 0.2s;
}

.wcag-card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.wcag-target {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

.wcag-level {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-surface-elevated);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
}

.wcag-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wcag-card.pass {
    border-color: var(--success);
    background: var(--success-bg);
}

.wcag-card.pass .status-icon {
    background: var(--success);
    color: #fff;
}

.wcag-card.pass .status-text {
    color: var(--success);
    font-weight: 600;
}

.wcag-card.fail {
    border-color: var(--border);
    opacity: 0.8;
}

.wcag-card.fail .status-icon {
    background: var(--fail-bg);
    color: var(--fail);
}

.wcag-card.fail .status-text {
    color: var(--fail);
    font-weight: 600;
}

/* Suggestions */
.suggestions-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.panel-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

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

.suggestion-item:hover {
    border-color: var(--primary);
}

.sug-color {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sug-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.sug-hex {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 500;
}

.sug-ratio {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--success);
}

/* Saved Panel */
.saved-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 8rem);
}

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

.saved-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.saved-list {
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.saved-pair {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
}

.saved-pair:hover {
    border-color: var(--text-muted);
}

.saved-pair-colors {
    display: flex;
    align-items: center;
}

.saved-swatch {
    width: 32px;
    height: 32px;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.saved-swatch.fg {
    border-radius: 6px 0 0 6px;
    position: relative;
    z-index: 2;
}

.saved-swatch.bg {
    border-radius: 0 6px 6px 0;
    transform: translateX(-4px);
}

.saved-info {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 600;
}

.saved-del {
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
}

.saved-pair:hover .saved-del {
    opacity: 1;
}

.saved-del:hover {
    color: var(--fail);
    background: var(--fail-bg);
}

.empty-saved {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}