/* ============================================
   THIRDLE - Daily Word Puzzle
   Following Word Forge brand identity
   ============================================ */

/* --- CSS Variables --- */
:root {
    /* Brand Colors */
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: rgba(37, 99, 235, 0.08);
    --accent: #f97316;
    --accent-dark: #ea580c;
    --accent-light: rgba(249, 115, 22, 0.08);
    --purple: #7c3aed;

    /* Neutrals */
    --bg: #ffffff;
    --surface: #f8fafc;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-light: #94a3b8;
    --border: #e2e8f0;

    /* Semantic */
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --error: #ef4444;
    --error-light: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;

    /* Gradients */
    --gradient-brand: linear-gradient(135deg, #2563eb 0%, #f97316 100%);
    --gradient-hero: linear-gradient(135deg, #2563eb 0%, #7c3aed 50%, #f97316 100%);

    /* Typography */
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --fs-xs: 12px;
    --fs-sm: 14px;
    --fs-base: 16px;
    --fs-lg: 18px;
    --fs-xl: 20px;
    --fs-xxl: 28px;
    --fs-huge: 36px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --shadow-tile: 0 2px 8px rgba(37,99,235,0.15);

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    font-size: var(--fs-base);
    color: var(--text);
    background: var(--bg);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.loading-content {
    text-align: center;
}

.loading-title {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: -1px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-lg);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-right-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto var(--space-md);
    animation: spin 0.8s linear infinite;
}

.loading-text {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Game Container --- */
#game-container {
    max-width: 440px;
    margin: 0 auto;
    padding: var(--space-md);
    padding-bottom: 100px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
#game-header {
    margin-bottom: var(--space-md);
}

.header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.header-left,
.header-right {
    width: 60px;
    display: flex;
}

.header-right {
    justify-content: flex-end;
}

.game-title {
    font-size: var(--fs-xxl);
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: var(--fs-lg);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.timer {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

/* --- Level Navigation --- */
.level-nav {
    text-align: center;
}

.level-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: var(--space-xs);
}

.level-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s var(--ease-out);
}

.level-dot.active {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.level-dot.active .dot-number {
    color: #fff;
}

.level-dot.completed {
    background: var(--success);
    border-color: var(--success);
}

.level-dot.completed .dot-number {
    color: #fff;
}

.dot-number {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text-light);
}

.level-connector {
    width: 32px;
    height: 2px;
    background: var(--border);
    transition: background 0.3s ease;
}

.level-connector.filled {
    background: var(--success);
}

.level-label {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    font-weight: 500;
}

/* --- Message --- */
.message {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: var(--fs-sm);
    text-align: center;
    margin-bottom: var(--space-md);
    animation: slideDown 0.3s var(--ease-out);
}

.message.success {
    background: var(--success-light);
    color: #065f46;
}

.message.error {
    background: var(--error-light);
    color: #991b1b;
}

.message.info {
    background: var(--primary-light);
    color: var(--primary-dark);
}

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

/* --- Word Grid --- */
#word-grid-container {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-lg);
    flex-grow: 1;
    align-items: flex-start;
    padding-top: var(--space-sm);
}

#word-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
}

.word-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.tile {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xl);
    font-weight: 700;
    text-transform: uppercase;
    transition: all 0.2s var(--ease-out);
    user-select: none;
}

.tile-filled {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-tile);
}

.tile-blank {
    background: var(--surface);
    border: 2.5px dashed var(--border);
    color: var(--text);
    cursor: pointer;
    position: relative;
}

.tile-blank::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tile-blank:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.tile-blank.selected {
    border-color: var(--primary);
    border-style: solid;
    background: rgba(37, 99, 235, 0.06);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
    animation: blankPulse 1.5s ease-in-out infinite;
}

.tile-blank.placed {
    border-style: solid;
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.08);
    color: var(--primary);
    font-weight: 800;
}

.tile-blank.correct {
    border-color: var(--success);
    background: var(--success-light);
    color: #065f46;
    animation: correctPop 0.4s var(--ease-bounce);
}

.tile-blank.incorrect {
    border-color: var(--error);
    background: var(--error-light);
    color: #991b1b;
    animation: shake 0.4s ease;
}

.tile-blank.hint-revealed {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent-dark);
    border-style: solid;
}

/* Vertical word indicator - subtle column highlight */
.word-row .tile:nth-child(3) {
    position: relative;
}

.vertical-highlight {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: calc(52px + 12px);
    top: -4px;
    bottom: -4px;
    background: rgba(37, 99, 235, 0.04);
    border-radius: var(--radius-md);
    z-index: -1;
    pointer-events: none;
}

@keyframes blankPulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.1); }
}

@keyframes correctPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

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

/* Arrow showing vertical read direction */
.vertical-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-left: var(--space-sm);
    color: var(--text-light);
    font-size: var(--fs-xs);
    gap: 2px;
}

.vertical-arrow .arrow-line {
    width: 2px;
    height: 100%;
    background: var(--border);
    min-height: 20px;
}

.vertical-arrow .arrow-head {
    font-size: var(--fs-lg);
    line-height: 1;
}

/* --- Alphabet Grid --- */
#alphabet-container {
    margin-bottom: var(--space-md);
}

.alphabet-label {
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--text-light);
    margin-bottom: var(--space-sm);
    font-weight: 500;
}

#alphabet-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 5px;
    max-width: 100%;
}

.alpha-btn {
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
}

.alpha-btn:hover:not(.used):not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
    transform: translateY(-1px);
}

.alpha-btn:active:not(.used):not(:disabled) {
    transform: scale(0.95);
}

.alpha-btn.used {
    opacity: 0.25;
    cursor: not-allowed;
    background: var(--surface);
    border-color: transparent;
}

.alpha-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* --- Action Bar --- */
#action-bar {
    display: flex;
    gap: var(--space-sm);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--space-md);
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 100;
    justify-content: center;
    max-width: 440px;
    margin: 0 auto;
}

.btn {
    padding: 12px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-family: var(--font);
    font-size: var(--fs-base);
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-hint {
    background: var(--accent-light);
    color: var(--accent-dark);
    border: 1.5px solid rgba(249, 115, 22, 0.2);
}

.btn-hint:hover:not(:disabled) {
    background: rgba(249, 115, 22, 0.15);
}

.btn-hint:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-lg {
    padding: 14px 32px;
    font-size: var(--fs-lg);
    border-radius: var(--radius-lg);
    width: 100%;
}

.hint-icon {
    font-size: var(--fs-lg);
}

#check-btn {
    flex: 1;
    max-width: 200px;
}

#hint-btn {
    flex-shrink: 0;
}

/* --- Modals --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.modal-content {
    position: relative;
    background: var(--bg);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    max-width: 380px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s var(--ease-bounce);
    max-height: 90dvh;
    overflow-y: auto;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: var(--fs-xl);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text);
}

.modal-title {
    font-size: var(--fs-xxl);
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: var(--space-md);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Level Complete Modal --- */
.level-complete-icon {
    font-size: 48px;
    margin-bottom: var(--space-sm);
}

.level-time {
    color: var(--text-secondary);
    font-size: var(--fs-lg);
    margin-bottom: var(--space-sm);
}

.level-vertical {
    font-size: var(--fs-xl);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--space-lg);
    text-transform: uppercase;
    letter-spacing: 4px;
}

/* --- Game Complete End Screen (Full-page style) --- */
.end-screen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gradient-hero);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.3s ease-out;
}

.end-screen-modal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 20%, rgba(255,255,255,0.1) 0%, transparent 60%),
                radial-gradient(circle at 80% 80%, rgba(249,115,22,0.15) 0%, transparent 50%);
    pointer-events: none;
}

.end-screen-modal.hidden {
    display: none !important;
}

.end-screen-content {
    width: 100%;
    max-width: 440px;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 var(--space-lg);
    position: relative;
    animation: endScreenFadeUp 0.4s ease-out both;
}

@keyframes endScreenFadeUp {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Hero section - transparent bg, centered on gradient */
.end-hero {
    padding: 40px 0 16px;
    position: relative;
    background: transparent;
}

.end-hero::before {
    display: none;
}

.end-hero-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 6px;
    position: relative;
}

.end-hero-stars {
    font-size: 32px;
    letter-spacing: 4px;
    margin-bottom: 8px;
    position: relative;
}

.end-hero-score {
    font-size: 64px;
    font-weight: 800;
    color: white;
    line-height: 1;
    margin-bottom: 4px;
    position: relative;
    text-shadow: 0 2px 16px rgba(0,0,0,0.2);
    animation: endScoreCount 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
    font-variant-numeric: tabular-nums;
}

@keyframes endScoreCount {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

.end-hero-sublabel {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
    position: relative;
}

/* Stats row - semi-transparent white text */
.end-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    width: 100%;
    padding: 4px 0;
    animation: endStatsSlide 0.4s ease-out 0.15s both;
}

@keyframes endStatsSlide {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

.end-stat {
    padding: 12px 8px;
    position: relative;
}

.end-stat:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: 12px;
    bottom: 12px;
    width: 1px;
    background: rgba(255, 255, 255, 0.2);
}

.end-stat .stat-value {
    font-size: 22px;
    font-weight: 800;
    color: white;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.end-stat .stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 2px;
}

/* Spacer pushes buttons to bottom */
.end-spacer {
    flex: 1;
}

/* Stacked full-width buttons at bottom */
.end-buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: max(var(--space-lg), env(safe-area-inset-bottom, 24px));
    animation: endSectionFade 0.35s ease-out 0.3s both;
}

@keyframes endSectionFade {
    0% { opacity: 0; transform: translateY(6px); }
    100% { opacity: 1; transform: translateY(0); }
}

.end-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.end-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.end-btn:active {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.98);
}

/* --- How To Play Modal --- */
.howto-content {
    text-align: left;
    padding: var(--space-lg) var(--space-lg) var(--space-md);
}

.howto-content .modal-title {
    text-align: center;
    font-size: var(--fs-xl);
    margin-bottom: var(--space-sm);
}

.howto-body {
    margin-bottom: var(--space-md);
}

.howto-step {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: flex-start;
}

.step-number {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.step-text strong {
    font-size: var(--fs-sm);
    display: block;
    margin-bottom: 1px;
}

.step-text p {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    line-height: 1.35;
}

.howto-example {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 10px;
    margin-top: 10px;
}

.example-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    text-align: center;
}

.example-grid {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: center;
    margin-bottom: 6px;
}

.example-row {
    display: flex;
    gap: 3px;
}

.ex-tile {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    font-weight: 700;
    background: var(--primary);
    color: #fff;
}

.ex-tile.ex-blank {
    background: var(--accent);
}

.example-caption {
    text-align: center;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

/* --- Ad Modal --- */
.ad-content {
    text-align: center;
}

.ad-container {
    min-height: 100px;
    margin: var(--space-md) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.ad-timer {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.ad-content .btn {
    width: 100%;
    margin-bottom: var(--space-sm);
}

/* --- Already Completed State --- */
.completed-overlay {
    text-align: center;
    padding: var(--space-xl) var(--space-md);
}

.completed-overlay h2 {
    font-size: var(--fs-xxl);
    font-weight: 800;
    margin-bottom: var(--space-sm);
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.completed-overlay .completed-time {
    font-size: var(--fs-huge);
    font-weight: 800;
    margin-bottom: var(--space-md);
}

.completed-overlay .completed-message {
    color: var(--text-secondary);
    font-size: var(--fs-base);
}

/* --- Responsive --- */
@media (min-width: 768px) {
    .tile {
        width: 58px;
        height: 58px;
        font-size: 22px;
    }

    #alphabet-grid {
        gap: 6px;
    }

    .alpha-btn {
        height: 44px;
        font-size: var(--fs-base);
    }

    #action-bar {
        position: static;
        border-top: none;
        padding: var(--space-md) 0;
    }

    #game-container {
        padding-bottom: var(--space-lg);
    }
}

@media (max-width: 360px) {
    .tile {
        width: 44px;
        height: 44px;
        font-size: var(--fs-lg);
    }

    #alphabet-grid {
        gap: 3px;
    }

    .alpha-btn {
        height: 36px;
        font-size: var(--fs-xs);
    }

    .game-title {
        font-size: var(--fs-xl);
    }
}

/* --- Animations --- */
@keyframes levelUp {
    0% { opacity: 0; transform: translateY(30px); }
    100% { opacity: 1; transform: translateY(0); }
}

.level-enter {
    animation: levelUp 0.4s var(--ease-out);
}

@keyframes tileReveal {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.tile-reveal {
    animation: tileReveal 0.3s var(--ease-bounce);
}

@keyframes celebrate {
    0% { transform: scale(1); }
    25% { transform: scale(1.05) rotate(-2deg); }
    50% { transform: scale(1.1) rotate(2deg); }
    75% { transform: scale(1.05) rotate(-1deg); }
    100% { transform: scale(1); }
}

.celebrate {
    animation: celebrate 0.5s var(--ease-bounce);
}

/* --- Side Menu --- */
.side-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 200;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.2s ease;
}

.side-menu {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    max-width: 85vw;
    height: 100dvh;
    background: var(--bg);
    z-index: 300;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    transition: right 0.3s var(--ease-out);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.side-menu.open {
    right: 0;
}

.side-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-md);
    border-bottom: 1px solid var(--border);
}

.side-menu-title {
    font-size: var(--fs-xl);
    font-weight: 800;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.side-menu-nav {
    padding: var(--space-md);
    flex: 1;
}

.menu-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 12px var(--space-md);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: var(--fs-base);
    cursor: pointer;
    transition: background 0.15s ease;
}

.menu-link:hover {
    background: var(--surface);
}

.menu-icon {
    font-size: var(--fs-lg);
    width: 24px;
    text-align: center;
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-xs) var(--space-md);
}

.side-menu-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border);
}

.menu-credit {
    font-size: var(--fs-xs);
    color: var(--text-light);
    text-align: center;
}

/* --- Page Modal --- */
.page-modal {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: var(--bg);
}

.page-modal-backdrop {
    display: none;
}

.page-modal-content {
    position: relative;
    width: 100%;
    height: 100%;
}

.page-modal-close-btn {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: var(--fs-xl);
    cursor: pointer;
    z-index: 410;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}

.page-modal-close-btn:hover {
    background: var(--border);
}

.page-modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* --- Level Info Row --- */
.level-info-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
}

.level-info-row .timer {
    font-size: var(--fs-base);
    min-width: 40px;
}

.level-info-row .level-label {
    font-size: var(--fs-sm);
    min-width: 50px;
    text-align: right;
}

/* --- Ad Modals --- */
.ad-desc {
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    margin-bottom: var(--space-md);
    line-height: 1.4;
}

.ad-remaining-text {
    color: var(--text-light);
    font-size: var(--fs-xs);
    margin-bottom: var(--space-lg);
}

.ad-slot-container {
    min-height: 100px;
    margin: var(--space-md) 0;
    background: var(--surface);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ad-countdown-timer {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.ad-content .btn {
    width: 100%;
    margin-bottom: var(--space-sm);
}

.noad-icon {
    font-size: 48px;
    margin-bottom: var(--space-sm);
}

/* --- Game Chooser Modal --- */
.game-chooser-content {
    text-align: center;
}

.game-chooser-list {
    margin-bottom: var(--space-md);
}

.game-chooser-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 14px var(--space-md);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: var(--space-sm);
}

.game-chooser-item:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.game-chooser-icon {
    font-size: 28px;
    flex-shrink: 0;
}

.game-chooser-info {
    flex: 1;
    text-align: left;
}

.game-chooser-name {
    display: block;
    font-size: var(--fs-base);
    font-weight: 700;
    color: var(--text);
}

.game-chooser-desc {
    display: block;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: 1px;
}

.game-chooser-arrow {
    font-size: var(--fs-xl);
    color: var(--primary);
    font-weight: 700;
    flex-shrink: 0;
}

/* --- Print hidden --- */
@media print {
    #action-bar, #alphabet-container, .btn { display: none; }
}
