:root {
    /* Android 16 / Material You Inspired Palette */
    --md-sys-color-primary: #d0bcff;
    --md-sys-color-on-primary: #381e72;
    --md-sys-color-primary-container: #4f378b;
    --md-sys-color-on-primary-container: #eaddff;

    --md-sys-color-background: #141218;
    --md-sys-color-on-background: #e6e1e5;

    --md-sys-color-surface: #141218;
    --md-sys-color-on-surface-variant: #cac4d0;
    --md-sys-color-outline: #938f99;

    /* Header */
    --header-bg: #2b2930;
    --header-text: #fff;

    /* Keyboard Specifics - Multi-colored Zones */
    --key-base-color: #1a1a1a;

    /* Zone 1: Alphas (Letters) */
    --key-alpha-bg: #4a4458;
    --key-alpha-text: #e6e1e5;

    /* Zone 2: Modifiers (Shift, Enter, Ctrl) */
    --key-mod-bg: #635b75;
    --key-mod-text: #fff;

    /* Zone 3: Accents (Spacebar, Action) */
    --key-accent-bg: var(--md-sys-color-primary);
    --key-accent-text: var(--md-sys-color-on-primary);

    --shadow-color: rgba(0, 0, 0, 0.5);

    /* Terminal */
    --term-bg: rgba(30, 30, 35, 0.95);
    --term-text: #e6e1e5;
    --term-accent: var(--md-sys-color-primary);

    /* Download Button */
    --btn-red: #ff5449;
    /* Round red color */
}

body {
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    margin: 0;
    height: 100vh;
    font-family: 'Roboto', sans-serif;
    /* Cleaner font for UI */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.5s;
}

.background-mesh {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 10%, var(--md-sys-color-primary-container) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, var(--md-sys-color-primary) 0%, transparent 30%);
    opacity: 0.2;
    z-index: -1;
    transition: all 0.5s;
}

/* Header Redesign */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    /* Taller */
    background-color: var(--header-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 32px;
    box-sizing: border-box;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.app-title {
    font-size: 1.8rem;
    font-weight: 800;
    /* Bold */
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--header-text);
    text-shadow: 2px 2px 0 var(--md-sys-color-primary);
}

.settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--header-text);
    cursor: pointer;
    padding: 10px;
    border-radius: 12px;
    transition: background 0.2s, transform 0.2s;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(45deg);
}

/* Modal Styling */
.settings-modal {
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface-variant);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 28px;
    /* Extra round M3 */
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    font-family: 'Roboto', sans-serif;
    min-width: 320px;
}

.settings-modal::backdrop {
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--md-sys-color-primary);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

input[type="color"] {
    border: none;
    width: 50px;
    height: 30px;
    cursor: pointer;
    background: none;
}

.setting-group {
    margin-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 15px;
}

.setting-group h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    opacity: 0.8;
}

.preset-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.preset-btn {
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    color: #000;
    cursor: pointer;
    transition: transform 0.1s;
}

.preset-btn:hover {
    transform: scale(1.1);
}

/* Scene Layout */
.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    /* changed from 100% to ensure full view */
    perspective: 1000px;
    /* Reduced perspective for more dramatic angle */
    gap: 20px;
    overflow: hidden;
    /* Fix scrollbars */
    padding-top: 60px;
    /* Offset for header */
}

.scene {
    transform-style: preserve-3d;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

/* Modern Terminal */
.terminal-container {
    width: 90%;
    max-width: 700px;
    height: 180px;
    /* Slightly smaller to fit huge keyboard */
    background: var(--term-bg);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    font-family: 'VT323', monospace;
    font-size: 1.3rem;
    /* Larger text */
    position: relative;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: rotateX(5deg);
    transition: transform 0.3s;
    margin-bottom: 15px;
}

.terminal-container:hover {
    transform: rotateX(0deg) scale(1.01);
}

.terminal-output {
    flex-grow: 1;
    overflow-y: auto;
    color: var(--term-text);
    padding-bottom: 10px;
}

.terminal-header-bar {
    display: none;
    /* Collapsed for clean look unless needed */
}

.line {
    margin-bottom: 4px;
}

.system-msg {
    color: var(--md-sys-color-secondary);
    opacity: 0.8;
}

.prompt {
    color: var(--term-accent);
    margin-right: 8px;
}

.cursor {
    display: inline-block;
    width: 8px;
    height: 1.2rem;
    background: var(--term-accent);
    animation: blink 1s infinite;
    vertical-align: middle;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* 3D Keyboard Base */
.keyboard-base {
    background: #111;
    padding: 24px;
    border-radius: 32px;
    transform: rotateX(25deg);
    box-shadow:
        0 20px 0 #000,
        0 40px 60px rgba(0, 0, 0, 0.8),
        inset 0 2px 2px rgba(255, 255, 255, 0.1);
    /* Subtle top light */
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: transform 0.3s;
    transform-style: preserve-3d;
    margin-bottom: 30px;
    border: 2px solid #222;
}

.key-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    transform-style: preserve-3d;
}

/* CHUNKY 3D Keys */
.key {
    position: relative;
    width: 52px;
    height: 52px;
    background: var(--key-alpha-bg);
    border-radius: 14px;
    /* More rounded */
    color: var(--key-alpha-text);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.08s cubic-bezier(0.2, 0.8, 0.2, 1);
    user-select: none;
    transform-style: preserve-3d;

    /* Deep 3D Shadow Stack */
    box-shadow:
        0 2px 0 var(--key-base-color),
        0 4px 0 var(--key-base-color),
        0 6px 0 var(--key-base-color),
        0 8px 0 var(--key-base-color),
        0 10px 0 var(--key-base-color),
        0 12px 0 var(--key-base-color),
        /* 12px deep */
        0 15px 10px rgba(0, 0, 0, 0.4),
        inset 0 2px 1px rgba(255, 255, 255, 0.15);
}

.key:active,
.key.pressed {
    transform: translateY(12px);
    box-shadow:
        0 0 0 var(--key-base-color),
        0 1px 0 rgba(0, 0, 0, 0.2),
        inset 0 3px 6px rgba(0, 0, 0, 0.6);
}

/* Color Zones */
/* Spacebar */
.key-space {
    background: var(--key-accent-bg) !important;
    color: var(--key-accent-text) !important;
}

/* Modifiers (Darker/Different) */
.key-enter,
.key-shift-l,
.key-shift-r,
.key-backspace,
.key-tab,
.key-caps,
.key-ctrl,
.key-alt,
.key-fn,
.key-num {
    background: var(--key-mod-bg) !important;
    color: var(--key-mod-text) !important;
}

/* Sizing Overrides (Desktop) */
.desktop-keyboard .key-tab {
    width: 80px;
}

.desktop-keyboard .key-caps {
    width: 90px;
}

.desktop-keyboard .key-shift-l {
    width: 110px;
}

.desktop-keyboard .key-shift-r {
    width: 120px;
}

.desktop-keyboard .key-enter {
    width: 100px;
}

.desktop-keyboard .key-space {
    width: 340px;
}

.desktop-keyboard .key-backspace {
    width: 90px;
}

.desktop-keyboard .key-ctrl,
.desktop-keyboard .key-alt {
    width: 60px;
}

/* Sizing overrides for Desktop */
.desktop-keyboard .key-fn {
    width: 50px;
}

/* Mobile Sizes & Layout Fix */
.mobile-keyboard {
    display: none !important;
    /* Default hidden */
    padding: 5px;
    /* Tighter padding */
    gap: 6px;
}

/* Header Redesign */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background-color: var(--header-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    /* Adjusted padding */
    box-sizing: border-box;
    z-index: 1000;
    /* High z-index */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ... existing app-title ... */

/* Mobile & Layers */
.mobile-layer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.mobile-keyboard {
    display: none !important;
    padding: 10px 5px;
    gap: 8px;
}

.mobile-keyboard .key {
    width: 9vw;
    max-width: 44px;
    height: 72px;
    /* Increased Height */
    border-radius: 12px;
    font-size: 1.4rem;
    /* Larger Text */
    margin: 0 2px;
}

.mobile-keyboard .key:active,
.mobile-keyboard .key.pressed {
    transform: translateY(8px);
    box-shadow: 0 0 0 var(--key-base-color);
}

.mobile-keyboard .key-space {
    width: 45vw;
    max-width: none;
    /* remove max-width constraint for space */
    flex-grow: 2;
}

.mobile-keyboard .key-enter,
.mobile-keyboard .key-shift-l,
.mobile-keyboard .key-backspace,
.mobile-keyboard .key-num {
    width: 13vw;
    font-size: 1rem;
    flex-grow: 1;
}

/* Terminal Mobile Padding */
@media (max-width: 768px) {
    .app-container {
        padding-top: 80px;
        /* Clear the header */
        justify-content: flex-start;
        /* Align top mostly */
    }

    .terminal-container {
        width: 92%;
        padding: 20px 15px;
        /* Side padding */
        height: 25vh;
        margin-bottom: 20px;
    }

    /* Ensure header isn't cut off */
    .app-header {
        position: fixed;
        width: 100%;
    }
}

@media (max-width: 768px) {
    .app-container {
        perspective: 800px;
        gap: 10px;
    }

    .desktop-keyboard {
        display: none !important;
    }

    .mobile-keyboard {
        display: flex !important;
    }

    .terminal-container {
        width: 95%;
        height: 25vh;
    }

    /* Ensure rows wrap nicely if needed, but flex-nowrap is standard for keyboards */
    .key-row {
        gap: 3px;
    }
}

/* Button */
.controls-container {
    margin-top: 10px;
    z-index: 200;
}

.download-btn {
    background: var(--btn-red);
    color: white;
    padding: 16px 40px;
    font-size: 1.2rem;
    border-radius: 999px;
    /* Full Stadium */
    border: none;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 84, 73, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 84, 73, 0.6);
}

.download-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 10px rgba(255, 84, 73, 0.4);
}

.download-btn .icon {
    font-weight: bold;
}