:root {
    --bg-main: #0f172a;
    --bg-panel: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --h-green: #10b981;
    --h-red: #ef4444;
    --tile-bg: #334155;
    --tile-selected: #3b82f6;
    --tile-found: #10b981;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    position: fixed;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-panel);
    border-bottom: 2px solid rgba(255, 255, 255, 0.05);
    z-index: 10;
}

.back-btn {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-btn:hover {
    color: var(--text-main);
}

.game-title {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--accent);
    margin: 0;
    text-align: center;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

.level-display {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 10px;
    border-radius: 12px;
}

#current-score {
    color: var(--h-green);
    font-weight: 700;
}

/* Game Container */
#game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    position: relative;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
    padding-bottom: 70px; /* Make space for bottom ad so it does not disturb the game area */
}

/* Target Word */
#target-display {
    background: var(--bg-panel);
    padding: 10px 20px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.05);
    width: 90%;
    max-width: 400px;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#target-display.pulse {
    transform: scale(1.05);
    border-color: var(--h-green);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}

#target-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

#target-word {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 3px;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

/* Word Grid */
#word-grid-container {
    position: relative;
    width: 90%;
    max-width: 380px;
    aspect-ratio: 1;
    max-height: 48vh;
    margin-bottom: 15px;
    touch-action: none;
}

#line-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

#word-grid {
    display: grid;
    width: 100%;
    height: 100%;
    gap: 3px;
    background: var(--bg-panel);
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.cell {
    background: var(--tile-bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.1s, transform 0.1s;
    text-transform: uppercase;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.2);
}

.cell.selected {
    background: var(--tile-selected);
    transform: scale(0.95);
    box-shadow: none;
}

.cell.found {
    background: var(--tile-found);
    color: #fff;
    animation: pop 0.3s ease-out;
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Controls */
#controls {
    display: flex;
    gap: 15px;
    margin-top: 15px;
    margin-bottom: 20px;
}

.control-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--bg-panel);
    color: var(--text-main);
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s, background 0.2s;
}

.control-btn:active {
    transform: scale(0.9);
}

/* Overlays */
.overlay-screen {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
    transition: opacity 0.3s;
}

.overlay-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.screen-content {
    background: var(--bg-panel);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
}

.game-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.game-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

.game-btn:active {
    transform: translateY(0);
}

@media (max-width: 400px) {
    .cell {
        font-size: 1.2rem;
    }
}

/* Tutorial Overlay */
.tutorial-demo {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.4s ease;
}

.tutorial-demo.hidden {
    opacity: 0;
    pointer-events: none;
}

.demo-box {
    background: rgba(20,20,40,0.9);
    padding: 25px 30px;
    border-radius: 18px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.demo-tiles {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.demo-tiles .tile {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-weight: 900;
    font-size: 20px;
    color: white;
    animation: tilePulse 1.5s infinite;
}

.demo-tiles .tile:nth-child(2) { animation-delay: 0.2s; }
.demo-tiles .tile:nth-child(3) { animation-delay: 0.4s; }
.demo-tiles .tile:nth-child(4) { animation-delay: 0.6s; }

@keyframes tilePulse {
    0%, 100% { transform: scale(1); background: linear-gradient(135deg, var(--accent), var(--accent-hover)); }
    50% { transform: scale(1.1); background: linear-gradient(135deg, var(--h-green), #059669); }
}

#bottom-ad {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 50px;
    z-index: 9999;
}

#adsterra-banner {
    position: fixed;
    bottom: 5px;
    right: 10px;
    z-index: 9000;
    display: none;
    width: 160px;
    height: 600px;
}

@media (min-width:1024px) {
    #adsterra-banner {
        display: block;
    }
}
