:root {
    --primary: #6366F1;
    --primary-dim: rgba(99, 102, 241, 0.12);
    --accent: #EC4899;
    --accent-dim: rgba(236, 72, 153, 0.12);
    --success: #10B981;
    --success-dim: rgba(16, 185, 129, 0.12);
    --warning: #F59E0B;
    --danger: #EF4444;

    --bg: #0F0E17;
    --bg-card: rgba(22, 21, 35, 0.8);
    --bg-elevated: #1A1930;
    --bg-input: rgba(15, 14, 23, 0.9);
    --text: #FFFFFE;
    --text-sec: #A7A9BE;
    --text-muted: #53536A;
    --border: rgba(167, 169, 190, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Inter', -apple-system, sans-serif;
}

[data-theme="light"] {
    --bg: #F8F7FF;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-elevated: #FFFFFF;
    --bg-input: rgba(240, 239, 255, 0.9);
    --text: #0F0E17;
    --text-sec: #53536A;
    --text-muted: #A7A9BE;
    --border: rgba(15, 14, 23, 0.06);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    transition: background 300ms, color 300ms;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(15, 14, 23, 0.95);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

[data-theme="light"] .app-header {
    background: rgba(248, 247, 255, 0.95);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.logo-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    font-size: 1.25rem;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-dim);
    border-radius: var(--radius-sm);
}

.app-title {
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-subtitle {
    font-size: 0.65rem;
    color: var(--text-sec);
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 4px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 7px 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 150ms ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #4F46E5);
    color: #fff;
}

.btn-primary:hover {
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-sec);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.625rem;
}

.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Input */
.input-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.bp-form {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.form-input {
    flex: 1;
    min-width: 80px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8125rem;
    outline: none;
}

.form-input:focus {
    border-color: var(--primary);
}

.presets {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.preset-label {
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

/* Breakpoint List */
.bp-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.bp-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    transition: all 200ms ease;
}

.bp-card.matched {
    border-color: var(--success);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

.bp-card.preview-match {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

.bp-name {
    font-size: 0.8125rem;
    font-weight: 700;
}

.bp-range {
    font-size: 0.6875rem;
    color: var(--text-sec);
    font-family: 'JetBrains Mono', monospace;
}

.bp-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.bp-indicator.active {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

.bp-indicator.inactive {
    background: var(--text-muted);
}

.bp-delete {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
}

.bp-delete:hover {
    color: var(--danger);
}

/* Preview */
.preview-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.preview-slider {
    flex: 1;
    accent-color: var(--primary);
}

.preview-value {
    font-size: 0.8125rem;
    font-weight: 700;
    min-width: 60px;
    text-align: right;
    color: var(--primary);
}

.preview-ruler {
    height: 20px;
    position: relative;
    margin-bottom: 8px;
    border-left: 1px solid var(--text-muted);
}

.ruler-mark {
    position: absolute;
    top: 0;
    height: 100%;
    border-left: 1px solid var(--border);
    font-size: 0.5rem;
    color: var(--text-muted);
    padding-left: 2px;
}

.preview-frame-wrapper {
    overflow-x: auto;
}

.preview-frame {
    border: 2px solid var(--border);
    border-radius: 8px;
    transition: width 200ms ease;
    overflow: hidden;
    margin: 0 auto;
}

.preview-content {
    padding: 12px;
}

.preview-block {
    background: var(--primary-dim);
    border-radius: 6px;
    padding: 10px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-sec);
    margin-bottom: 8px;
}

.preview-block:last-child {
    margin-bottom: 0;
    margin-top: 8px;
}

.preview-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

.preview-card {
    background: var(--accent-dim);
    border-radius: 6px;
    padding: 16px 10px;
    text-align: center;
    font-size: 0.6875rem;
    color: var(--text-sec);
}

/* Match */
.match-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.match-results {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.match-tag {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.6875rem;
    font-weight: 600;
}

.match-tag.active {
    background: var(--success-dim);
    color: var(--success);
}

.match-tag.inactive {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

/* CSS output */
.css-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.code-block {
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6875rem;
    color: var(--primary);
    line-height: 1.7;
    overflow-x: auto;
    white-space: pre;
}

[data-theme="light"] .code-block {
    background: rgba(0, 0, 0, 0.04);
}

.app-footer {
    text-align: center;
    padding: 12px;
    font-size: 0.625rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

kbd {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 0.5625rem;
}

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

    .bp-form {
        flex-direction: column;
    }

    .bp-list {
        grid-template-columns: 1fr;
    }
}

::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-thumb {
    background: rgba(167, 169, 190, 0.15);
    border-radius: 3px;
}