:root {
    /* GNOME Libadwaita Dark Palette */
    --bg-app: #181818;
    --gnome-window-bg: #242424;
    --gnome-headerbar-bg: #303030;
    --bg-card: #2e2e2e;
    --bg-surface: #383838;
    --bg-input: #1e1e1e;
    
    --primary: #3584e4; /* GNOME Adwaita Blue */
    --primary-glow: rgba(53, 132, 228, 0.35);
    --primary-dark: #1c71d8;
    
    --accent-blue: #3584e4;
    --accent-success: #2ec27e; /* GNOME Green */
    --accent-warning: #f6d32d; /* GNOME Yellow */
    --accent-error: #e01b24; /* GNOME Red */
    
    --text-main: #ffffff;
    --text-muted: #9a9996;
    --text-dim: #77767b;
    --text-hidden: #3f3f46;
    
    --border: rgba(255, 255, 255, 0.12);
    --border-strong: rgba(255, 255, 255, 0.2);
    --radius: 12px;
    --radius-window: 16px;
    
    --font-ui: 'Cantarell', 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

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

html {
    font-size: 18px; /* Increased base font size across the application */
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-ui);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 50% 10%, rgba(53, 132, 228, 0.08), transparent 50%),
        radial-gradient(circle at 85% 90%, rgba(46, 194, 126, 0.05), transparent 40%);
}

/* --- Layout --- */

#app {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    position: relative;
    z-index: 1;
    min-height: 100vh;
    justify-content: space-between;
}

/* --- Header --- */

header {
    text-align: center;
    margin-bottom: 2rem;
    margin-top: 1rem;
}

header h1 {
    font-size: 3.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-muted);
    font-size: 1.25rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* --- Components & Cards --- */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.25rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.95rem 2rem;
    font-weight: 700;
    font-size: 1.15rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    border: 1px solid transparent;
    gap: 0.75rem;
    font-family: inherit;
    letter-spacing: 0.01em;
    user-select: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 6px 16px var(--primary-glow);
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.btn-secondary:hover {
    background-color: #424242;
    border-color: var(--border-strong);
}

.btn-lg {
    padding: 1.15rem 3.5rem;
    font-size: 1.3rem;
    border-radius: 12px;
}

.full-width { width: 100%; }

.icon-btn {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 10px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: #424242;
    color: #ffffff;
    border-color: var(--border-strong);
    transform: rotate(20deg);
}

.link-btn {
    background: none;
    border: none;
    color: var(--accent-blue);
    cursor: pointer;
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 1.25rem;
    transition: color 0.2s;
}

.link-btn:hover {
    color: #62a0ea;
    text-decoration: underline;
}

/* --- Screens --- */

.screen {
    display: none;
    animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.screen.active { display: block; }

/* Setup Screen */

.input-wrapper {
    position: relative;
    margin-bottom: 1.75rem;
}

textarea#setup-text {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-main);
    padding: 1.75rem;
    font-family: var(--font-mono);
    font-size: 1.4rem; /* Scaled up for focus */
    line-height: 1.7;
    resize: vertical;
    min-height: 380px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
    white-space: pre-wrap;
    word-break: break-word;
}

textarea#setup-text:focus {
    border-color: var(--primary);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4), 0 0 0 3px rgba(53, 132, 228, 0.4);
}

.error-toast {
    color: var(--accent-error);
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 0.5rem;
}

#upload-text {
    text-align: center;
    border-top: 1px solid var(--border);
    padding: 1.75rem 0;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.button-group {
    display: flex;
    gap: 1.25rem;
}

.button-group > * { flex: 1; }

/* Difficulty Screen */

.section-title {
    font-size: 2.35rem; /* Scaled up title */
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-align: center;
    color: var(--text-main);
}

.sub-text {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 2.25rem;
    font-size: 1.25rem;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.card-interactive {
    text-align: left;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 1.75rem;
}

.card-interactive:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    background: #3e3e3e;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
}

.icon-box {
    width: 54px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    margin-bottom: 1.25rem;
    transition: transform 0.2s;
}

.card-interactive:hover .icon-box { transform: scale(1.1); }

.text-blue { color: var(--accent-blue); }
.text-green { color: var(--accent-success); }
.text-yellow { color: var(--accent-warning); }
.text-red { color: var(--accent-error); }

.card-interactive h3 { 
    font-size: 1.4rem; 
    margin-bottom: 0.6rem; 
    color: var(--text-main); 
}

.card-interactive p { 
    color: var(--text-muted); 
    line-height: 1.5; 
    font-size: 1.1rem; 
}

/* Playing Screen */

.progress-container {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    margin-bottom: 1.75rem;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #62a0ea 100%);
    width: 0%;
    transition: width 0.1s linear;
    box-shadow: 0 0 10px var(--primary-glow);
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
}

.badge {
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0.4rem 1rem;
    border-radius: 9999px; /* GNOME pill badge */
    border: 2px solid;
    letter-spacing: 0.06em;
}

/* Typing Container & High-Focus Display */

.typing-container {
    position: relative;
    min-height: 500px;
    height: 55vh;
    max-height: 650px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.5);
    cursor: text;
    border-radius: 12px;
}

.typing-display, .typing-input {
    font-family: var(--font-mono);
    font-size: 1.85rem; /* Significantly enlarged for maximum clarity & focus */
    line-height: 1.85;
    padding: 2.25rem;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    overflow-y: auto;
    border: none;
    scrollbar-gutter: stable;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Invisible input layer */
.typing-input {
    color: transparent;
    background: transparent;
    caret-color: transparent;
    z-index: 2;
    resize: none;
    outline: none;
}

.typing-display {
    color: var(--text-muted);
    z-index: 1;
    pointer-events: none;
}

/* Character States */
.char-correct { 
    color: #ffffff; 
    font-weight: 600;
}

.char-wrong { 
    color: #ffffff; 
    background-color: #c01c28; /* Keypunch red highlight block */
    border-radius: 2px;
    box-shadow: 0 0 6px rgba(224, 27, 36, 0.5);
}

.char-hint { 
    color: #e0e0e0; /* Bright visible hint color */
    opacity: 0.9;
}

/* Hidden block styling */
.char-hidden { 
    color: transparent; 
    background: rgba(255, 255, 255, 0.12); 
    border-radius: 3px;
    display: inline-block;
    vertical-align: bottom;
}

/* Active Cursor Bar */
.cursor-active {
    position: relative;
}

.cursor-active::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0.1em;
    width: 100%;
    height: 1.25em;
    background-color: var(--primary);
    opacity: 0.75;
    animation: blink 1s step-end infinite;
    pointer-events: none;
    border-radius: 2px;
}

/* Results Screen */

.results-header {
    text-align: center;
    margin-bottom: 2rem;
}

.trophy-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 110px;
    height: 110px;
    background: rgba(53, 132, 228, 0.15);
    border: 2px solid var(--primary);
    color: var(--primary);
    border-radius: 50%;
    margin-bottom: 1.5rem;
    box-shadow: 0 0 35px var(--primary-glow);
    animation: scaleIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2.25rem;
}

.stat-card {
    text-align: center;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 1.75rem;
    transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.stat-value {
    font-size: 3.2rem; /* Scaled up stat counter */
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #ffffff;
}

.stat-label {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 0.6rem;
}

.centered-action {
    text-align: center;
}

.timer-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface);
    padding: 0.5rem 1.2rem;
    border-radius: 9999px;
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-blue);
}

/* Utils & Helpers */

.hidden { display: none !important; }

/* Keyframe Animations */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes blink {
    0%, 100% { opacity: 0.75; }
    50% { opacity: 0; }
}

/* Custom GNOME Scrollbar */

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.35); }

footer {
    color: var(--text-dim);
    font-size: 0.95rem;
    padding: 3rem 0 1.5rem;
    text-align: center;
}