:root {
    --md-sys-color-surface: #fdf8f6;
    --md-sys-color-on-surface: #1c1b1f;
    --md-sys-color-primary-container: #dce5dd;
    --md-sys-color-on-primary-container: #002022;
    --md-sys-color-outline: #79747e;
    --font-sans: 'Roboto Flex', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    --text-highlight: #1A4228;
    --text-dim: #98A89E;
    --cursor-color: #3D6A4B;
}

/* Reset & Base */
body {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    font-family: var(--font-sans);
    transition: background-color 0.5s ease, color 0.5s ease;
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Themes */
body[data-theme='relaxed'] {
    --md-sys-color-surface: #F2F6F3;
    --md-sys-color-primary: #3D6A4B;
    --md-sys-color-primary-container: #D1E5D6;
    --text-highlight: #1A4228;
    --text-dim: #98A89E;
    --cursor-color: #3D6A4B;
}

body[data-theme='stressed'] {
    --md-sys-color-surface: #FFF0EE;
    --md-sys-color-primary: #B3261E;
    --md-sys-color-primary-container: #FFDAD6;
    --text-highlight: #410E0B;
    --text-dim: #D4A8A5;
    --cursor-color: #B3261E;
}

/* --- Layout Components --- */

/* Header */
.app-header {
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 1rem;
    /* Reduced padding */
    display: flex;
    flex-direction: column;
    /* Stack on mobile */
    gap: 1rem;
    align-items: center;
    position: relative;
    z-index: 10;
}

@media (min-width: 768px) {
    .app-header {
        flex-direction: row;
        justify-content: space-between;
        padding: 1.5rem;
    }
}

.logo-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s;
}

.logo-link:hover {
    opacity: 0.8;
}

.logo-icon {
    font-size: 1.875rem;
    /* text-3xl */
    opacity: 0.5;
    color: var(--text-highlight);
}

.logo-text {
    font-size: 1.25rem;
    /* text-xl */
    font-weight: 500;
    letter-spacing: -0.025em;
    opacity: 0.8;
    margin: 0;
}

.logo-sub {
    font-size: 0.75rem;
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-left: 0.5rem;
}

/* Navigation (Desktop) */
.nav-links {
    display: none;
    gap: 2rem;
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.7;
}

@media (min-width: 768px) {
    .nav-links {
        display: flex;
    }
}

.nav-link {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--text-highlight);
    opacity: 1;
}

.btn-small {
    padding: 0.5rem 1.5rem;
    border-radius: 9999px;
    background-color: #065f46;
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: opacity 0.2s;
}

.btn-small:hover {
    opacity: 0.9;
}


/* Mode Switcher */
.mode-switcher {
    background-color: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(4px);
    padding: 0.25rem;
    border-radius: 9999px;
    /* rounded-full */
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    display: flex;
    gap: 0.25rem;
    width: 100%;
    /* Full width on mobile */
    justify-content: center;
}

@media (min-width: 768px) {
    .mode-switcher {
        width: auto;
    }
}

.mode-btn {
    padding: 0.5rem 1rem;
    /* Smaller padding on mobile */
    border-radius: 9999px;
    font-size: 0.875rem;
    /* text-sm */
    font-weight: 500;
    transition: all 0.3s;
    border: none;
    cursor: pointer;
    background: transparent;
    color: #6b7280;
    /* gray-500 */
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    /* Stretch on mobile */
    justify-content: center;
}

@media (min-width: 768px) {
    .mode-btn {
        padding: 0.5rem 1.5rem;
        flex: initial;
    }
}

.mode-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.mode-btn.active {
    background-color: var(--md-sys-color-primary-container);
    color: var(--text-highlight);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* Main Container */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
    max-width: 64rem;
    margin: 0 auto;
    padding: 1rem;
    /* Reduced padding */
}

@media (min-width: 768px) {
    .main-content {
        padding: 0 2rem;
    }
}

/* Hero Section */
.hero-section {
    padding: 3rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

@media (min-width: 768px) {
    .hero-section {
        padding: 5rem 1.5rem;
    }
}

.hero-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    background-color: #ecfdf5;
    /* emerald-50 */
    color: #065f46;
    /* emerald-800 */
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2rem;
}

.pulse-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: #10b981;
    /* emerald-500 */
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(1.1);
    }
}

.hero-title {
    font-size: 2.5rem;
    /* Smaller on mobile */
    font-weight: 300;
    line-height: 1.1;
    margin-bottom: 2rem;
    color: var(--md-sys-color-on-surface);
}

@media (min-width: 768px) {
    .hero-title {
        font-size: 4.5rem;
        /* md:text-7xl */
    }
}

.hero-title em {
    font-family: serif;
    font-style: italic;
    color: var(--text-highlight);
}

.hero-text {
    max-width: 36rem;
    font-size: 1rem;
    /* Smaller on mobile */
    opacity: 0.7;
    line-height: 1.6;
    margin-bottom: 2.5rem;
}

@media (min-width: 768px) {
    .hero-text {
        font-size: 1.125rem;
    }
}

.hero-actions {
    display: flex;
    gap: 1rem;
    flex-direction: column;
    width: 100%;
}

@media (min-width: 768px) {
    .hero-actions {
        flex-direction: row;
        width: auto;
    }
}

.btn-secondary {
    padding: 1rem 2rem;
    border-radius: 9999px;
    border: 1px solid #d1d5db;
    font-weight: 500;
    font-size: 1.125rem;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
   
}

.btn-secondary:hover {
    background-color: white;
}

/* Stats Section */
.stats-section {
    width: 100%;
    background-color: white;
    border-top: 1px solid #f3f4f6;
    border-bottom: 1px solid #f3f4f6;
    padding: 3rem 0;
    margin-top: auto;
}

.stats-grid {
    max-width: 64rem;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: center;
    gap: 2rem;
    text-align: center;
    flex-wrap: wrap;
}

@media (min-width: 768px) {
    .stats-grid {
        justify-content: space-around;
        gap: 4rem;
    }
}

.stat-value {
    font-size: 1.875rem;
    /* text-3xl */
    font-family: var(--font-mono);
    position: relative;
    display: inline-block;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.5;
    margin-top: 0.5rem;
}

/* Content Pages (About/Research) */
.page-container {
    width: 100%;
    max-width: 42rem;
    /* max-w-2xl */
    margin: 0 auto;
    padding: 3rem 1.5rem;
    flex: 1;
}

.page-title {
    font-size: 2.25rem;
    /* text-4xl */
    font-weight: 300;
    margin-bottom: 2rem;
}

.page-text {
    font-size: 1.125rem;
    line-height: 1.7;
    opacity: 0.8;
    margin-bottom: 1.5rem;
}

.research-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.research-item {
    padding: 1.5rem;
    background-color: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid #f3f4f6;
}

.research-title {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    margin-top: 0;
}

/* HUD (Heads Up Display) */
.hud {
    position: absolute;
    top: 1rem;
    /* Higher on mobile */
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    color: var(--text-highlight);
    opacity: 0.6;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    /* Smaller */
}

@media (min-width: 768px) {
    .hud {
        top: 2.5rem;
        font-size: 0.875rem;
    }
}

.hud-timer {
    display: none;
    /* Hidden by default */
    align-items: center;
    gap: 0.5rem;
    color: #dc2626;
    /* red-600 */
    font-weight: bold;
}

.hud-stats {
    display: flex;
    gap: 1rem;
    /* Tighter gap */
}

@media (min-width: 768px) {
    .hud-stats {
        gap: 2rem;
    }
}

/* Game Board */
.game-board {
    position: relative;
    width: 100%;
    font-size: 1.25rem;
    /* Smaller font for mobile */
    line-height: 1.625;
    outline: none;
    font-family: var(--font-mono);
    letter-spacing: 0.025em;
    min-height: 50vh;
    /* Ensure touch target size */
    display: flex;
    /* Center text vertically */
    align-items: center;
}

@media (min-width: 768px) {
    .game-board {
        font-size: 1.875rem;
        /* md:text-3xl */
        min-height: auto;
    }
}

/* Mobile Input Proxy */
.mobile-input-proxy {
    position: absolute;
    opacity: 0;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5;
    /* Above background, but below visual text? checking.. */
    cursor: text;
    pointer-events: auto;
    /* MUST interact */
    font-size: 16px;
    /* Prevent zoom */
}

.words-container {
    overflow-wrap: break-word;
    /* break-words */
    user-select: none;
    position: relative;
    z-index: 10;
    /* Visual text on top of input for clarity */
    pointer-events: none;
    /* Let clicks pass through to input */
}

/* Action Button */
.action-container {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 30;
    width: 100%;
}

.btn-primary {
    padding: 1rem 2rem;
    border-radius: 9999px;
    background-color: #065f46;
    color: white;
    font-weight: 500;
    font-size: 1.2rem;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
   
}

.btn-primary:hover {
    background-color: #1A4228;
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Overlay */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.5);
    /* Surface opacity/80 approx */
    z-index: 20;
    transition: opacity 0.3s;
}

.overlay-card {
    text-align: center;
    padding: 2rem;
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid #f3f4f6;
    margin: 1rem;
    /* Margin for mobile */
}

/* FAB */
.fab-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 50;
}

.btn-fab {
    height: 3rem;
    /* Smaller on mobile */
    padding: 0 1rem;
    border-radius: 1rem;
    background-color: #111827;
    /* gray-900 */
    color: white;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

@media (min-width: 768px) {
    .btn-fab {
        height: 3.5rem;
        padding: 0 1.5rem;
        bottom: 2rem;
        right: 2rem;
    }
}

.btn-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

/* --- Typography & Elements --- */

.word {
    margin-right: 0.4em;
    display: inline-block;
    position: relative;
    white-space: nowrap;
}

.letter {
    position: relative;
    transition: color 0.1s;
    color: var(--text-dim);
}

.letter.correct {
    color: var(--text-highlight);
}

.letter.incorrect {
    color: #B3261E;
    text-decoration: underline;
}

.letter.active {
    position: relative;
}

.letter.active::before {
    content: "";
    position: absolute;
    left: -1px;
    top: 10%;
    height: 80%;
    width: 2px;
    background-color: var(--cursor-color);
    animation: blink 1s infinite;
}

/* Cursor variations */
.letter[data-cursor='right']::before {
    left: auto;
    right: -2px;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Ripple */
.ripple {
    position: relative;
    overflow: hidden;
    transform: translate3d(0, 0, 0);
}

.ripple:after {
    content: "";
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, #000 10%, transparent 10.01%);
    background-repeat: no-repeat;
    background-position: 50%;
    transform: scale(10, 10);
    opacity: 0;
    transition: transform .5s, opacity 1s;
}

.ripple:active:after {
    transform: scale(0, 0);
    opacity: .1;
    transition: 0s;
}

/* Animations */
@keyframes shake {
    0% {
        transform: translate(1px, 1px) rotate(0deg);
    }

    10% {
        transform: translate(-1px, -2px) rotate(-1deg);
    }

    20% {
        transform: translate(-3px, 0px) rotate(1deg);
    }

    30% {
        transform: translate(3px, 2px) rotate(0deg);
    }

    40% {
        transform: translate(1px, -1px) rotate(1deg);
    }

    50% {
        transform: translate(-1px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(-3px, 1px) rotate(0deg);
    }

    70% {
        transform: translate(3px, 1px) rotate(-1deg);
    }

    80% {
        transform: translate(-1px, -1px) rotate(1deg);
    }

    90% {
        transform: translate(1px, 2px) rotate(0deg);
    }

    100% {
        transform: translate(1px, -2px) rotate(-1deg);
    }
}

.shake-screen {
    animation: shake 0.5s;
    border: 4px solid #B3261E;
}

/* Utilities */
.hidden {
    display: none !important;
}

.text-red {
    color: #dc2626 !important;
}