/* ===== DESIGN TOKENS ===== */
:root {
    --color-bg: #0A121A;
    --color-surface: rgba(116, 185, 255, 0.05);
    --color-surface-solid: #0F1A26;
    --color-glass: rgba(116, 185, 255, 0.04);
    --color-border: rgba(116, 185, 255, 0.15);
    --color-border-focus: #74B9FF;
    --color-text: #DFE6E9;
    --color-text-secondary: #9BB0C4;
    --color-text-muted: #5A7186;
    --color-primary: #74B9FF;
    --color-primary-hover: #5EAAEE;
    --color-primary-glow: rgba(116, 185, 255, 0.25);
    --color-secondary: #DFE6E9;
    --color-accent: #E17055;
    --color-accent-glow: rgba(225, 112, 85, 0.25);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
}

/* ===== HEADER ===== */
.app-header {
    background: var(--color-surface-solid);
    border-bottom: 1px solid var(--color-border);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
}

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

.header-actions select {
    padding: 6px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    color: var(--color-text);
    cursor: pointer;
}

.header-actions select:focus {
    outline: none;
    border-color: var(--color-border-focus);
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-primary);
    color: #0A121A;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 4px 16px var(--color-primary-glow);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-secondary);
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 0.78rem;
}

/* ===== MAIN ===== */
.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ===== INPUT ===== */
.input-section {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
}

.input-section textarea {
    width: 100%;
    padding: 14px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.87rem;
    color: var(--color-text);
    resize: vertical;
    line-height: 1.6;
    transition: border-color var(--transition);
}

.input-section textarea:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(116, 185, 255, 0.1);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.char-count {
    margin-left: auto;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-family: var(--font-mono);
}

/* ===== KEYBOARD ===== */
.keyboard-section {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
    overflow-x: auto;
}

.keyboard {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 700px;
}

.key-row {
    display: flex;
    gap: 5px;
}

.key {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-bg);
    position: relative;
    transition: all 300ms ease;
    cursor: default;
}

.key.space {
    width: 300px;
}

.key.wide {
    width: 72px;
    font-size: 0.65rem;
}

.key.wider {
    width: 96px;
    font-size: 0.65rem;
}

.key .key-count {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 0.55rem;
    color: rgba(255, 255, 255, 0.5);
}

.key:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Heatmap levels */
.key.heat-0 {
    background: var(--color-bg);
}

.key.heat-1 {
    background: rgba(116, 185, 255, 0.08);
}

.key.heat-2 {
    background: rgba(116, 185, 255, 0.18);
}

.key.heat-3 {
    background: rgba(116, 185, 255, 0.30);
    color: #fff;
}

.key.heat-4 {
    background: rgba(116, 185, 255, 0.45);
    color: #fff;
}

.key.heat-5 {
    background: rgba(225, 112, 85, 0.35);
    color: #fff;
}

.key.heat-6 {
    background: rgba(225, 112, 85, 0.50);
    color: #fff;
}

.key.heat-7 {
    background: rgba(225, 112, 85, 0.65);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.key.heat-8 {
    background: rgba(225, 112, 85, 0.80);
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 10px var(--color-accent-glow);
}

.key.heat-9 {
    background: rgba(225, 112, 85, 0.95);
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 16px var(--color-accent-glow);
}

/* ===== STATS ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 20px;
    text-align: center;
}

.stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-primary);
}

/* ===== FINGER USAGE ===== */
.finger-section {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.finger-section h2 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.finger-bars {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
}

.finger-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.finger-bar-fill {
    width: 100%;
    height: 120px;
    border-radius: 6px 6px 0 0;
    background: var(--color-bg);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--color-border);
}

.finger-bar-fill .fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 4px 4px 0 0;
    transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.finger-bar .finger-label {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-align: center;
}

.finger-bar .finger-pct {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-primary);
    font-family: var(--font-mono);
}

/* ===== FREQUENCY TABLE ===== */
.freq-section {
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.freq-section h2 {
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.freq-table-wrap {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.freq-table {
    width: 100%;
    border-collapse: collapse;
}

.freq-table th,
.freq-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(116, 185, 255, 0.06);
    font-size: 0.82rem;
}

.freq-table th {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background: var(--color-surface-solid);
}

.freq-table td {
    font-family: var(--font-mono);
}

.freq-table td:first-child {
    font-weight: 700;
    color: var(--color-accent);
}

.freq-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--color-primary);
    transition: width 0.4s ease;
}

/* ===== REALTIME ===== */
.realtime-overlay {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 100;
}

.realtime-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 20px;
    background: rgba(225, 112, 85, 0.15);
    border-bottom: 1px solid rgba(225, 112, 85, 0.3);
    font-size: 0.85rem;
    color: var(--color-accent);
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 24px;
    background: var(--color-primary);
    color: #0A121A;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    font-weight: 600;
    box-shadow: 0 4px 24px var(--color-primary-glow);
    z-index: 200;
    animation: toastSlide 0.3s ease;
}

@keyframes toastSlide {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 800px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .finger-bars {
        grid-template-columns: repeat(5, 1fr);
    }

    .keyboard-section {
        padding: 12px;
    }

    .app-main {
        padding: 16px;
    }
}

@media (max-width: 500px) {
    .header-inner {
        flex-direction: column;
        height: auto;
        padding: 12px 16px;
        gap: 8px;
    }

    .stats-row {
        grid-template-columns: 1fr 1fr;
    }
}