@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    /* Color Palette */
    --bg-color: #050508;
    --board-bg: rgba(15, 15, 25, 0.7);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);

    --neon-blue: #00f2ff;
    --neon-pink: #ff007a;
    --neon-yellow: #fff200;
    --neon-green: #00ffbd;
    --neon-purple: #bc13fe;
    --neon-orange: #ff9d00;
    --neon-red: #ff3c3c;

    /* Glows */
    --blue-glow: 0 0 15px rgba(0, 242, 255, 0.5);
    --pink-glow: 0 0 15px rgba(255, 0, 122, 0.5);
    --green-glow: 0 0 15px rgba(0, 255, 189, 0.5);
    --orange-glow: 0 0 15px rgba(255, 157, 0, 0.6);
    --purple-glow: 0 0 15px rgba(188, 19, 254, 0.6);
    --red-glow: 0 0 20px rgba(255, 60, 60, 0.7);
    --yellow-glow: 0 0 15px rgba(255, 242, 0, 0.5);

    /* Board Config (Set by JS) */
    --cell-size: 20px;
}

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

html {
    /* Prevent elastic overscroll on iOS */
    overscroll-behavior: none;
    height: 100%;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 20% 30%, rgba(0, 242, 255, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(255, 0, 122, 0.05) 0%, transparent 40%);
    color: white;
    height: 100%;
    min-height: 100dvh; /* dynamic viewport height on mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Eliminate 300ms tap delay globally */
    touch-action: manipulation;
    /* Prevent text selection on touch swipes */
    user-select: none;
    -webkit-user-select: none;
    /* iOS safe area insets */
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* ============================================================
   GAME CONTAINER — Horizontal (desktop / landscape default)
   ============================================================ */
#game-container {
    display: flex;
    flex-direction: row;
    gap: 28px;
    padding: 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8);
    max-width: 95vw;
    max-height: 95vh;
    position: relative;
}

/* ============================================================
   GAME CONTAINER — Vertical (portrait mobile)
   ============================================================ */
#game-container.vertical {
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 6px;
    max-height: 100dvh;
    border-radius: 20px;
    width: 100vw;
    max-width: 100vw;
}

/* ============================================================
   BOARD WRAP
   ============================================================ */
#board-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* board-wrap takes all remaining space after HUD strip */
#game-container.vertical #board-wrap {
    flex: 1;
    width: 100%;
    justify-content: flex-start;
    align-items: center;
    overflow: hidden;
    min-height: 0;  /* allow flex children to shrink */
}

/* ============================================================
   BOARD
   ============================================================ */
#board {
    display: grid;
    background: var(--board-bg);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    position: relative;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    /* Critical: no tap highlight on phone */
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   CELLS
   ============================================================ */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: calc(var(--cell-size) * 0.6);
    text-transform: uppercase;
    transition: background 0.15s ease, color 0.15s ease;
}

/* Letter Type Styles */
.letter {
    border-radius: 3px;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.letter.consonant {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.letter.vowel {
    color: var(--neon-blue);
    background: rgba(0, 242, 255, 0.1);
    box-shadow: inset 0 0 4px var(--neon-blue);
}

.letter.rare {
    color: var(--neon-yellow);
    background: rgba(255, 242, 0, 0.1);
    box-shadow: inset 0 0 4px var(--neon-yellow);
}

.letter.scored.len-2 {
    color: var(--neon-orange);
    background: rgba(255, 157, 0, 0.2);
    box-shadow: var(--orange-glow);
}

.letter.scored.len-3 {
    color: var(--neon-blue);
    background: rgba(0, 242, 255, 0.2);
    box-shadow: var(--blue-glow);
}

.letter.scored.len-4 {
    color: var(--neon-yellow);
    background: rgba(255, 242, 0, 0.2);
    box-shadow: var(--yellow-glow);
}

.letter.scored.len-5 {
    color: var(--neon-purple);
    background: rgba(188, 19, 254, 0.2);
    box-shadow: var(--purple-glow);
}

.letter.scored.len-6 {
    color: var(--neon-pink);
    background: rgba(255, 0, 122, 0.2);
    box-shadow: var(--pink-glow);
}

.letter.scored.len-7plus {
    color: var(--neon-red);
    background: rgba(255, 60, 60, 0.3);
    box-shadow: var(--red-glow);
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

/* ============================================================
   HUD — Desktop sidebar (horizontal layout)
   ============================================================ */
#hud {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 180px;
}

/* HUD in vertical (mobile portrait) — compact top strip */
#game-container.vertical #hud {
    flex-direction: row;
    align-items: center;
    width: 100%;
    gap: 5px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    /* target ~52px tall — matches JS reservation */
    height: 52px;
    min-height: 52px;
    max-height: 52px;
}

/* ============================================================
   TITLE
   ============================================================ */
.title {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: 4px;
    color: var(--neon-blue);
    text-shadow: 0 0 20px rgba(0, 242, 255, 0.4);
    text-align: center;
    white-space: nowrap;
}

#game-container.vertical .title {
    font-size: 20px;
    letter-spacing: 3px;
    margin: 0;
}

/* ============================================================
   HUD STRIP — row of stat chips (vertical mode)
   ============================================================ */
.hud-strip {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

#game-container.vertical .hud-strip {
    flex: 1;
    gap: 5px;
}

/* ============================================================
   STAT CHIPS (compact tiles)
   ============================================================ */
.stat-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 52px;
    flex: 1;
}

/* Larger stat chips in desktop/horizontal sidebar */
#game-container:not(.vertical) .stat-chip {
    padding: 12px 14px;
    border-radius: 12px;
}

.stat-label {
    font-size: 9px;
    text-transform: uppercase;
    color: #666;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--neon-blue);
    font-family: monospace;
    white-space: nowrap;
}

#game-container:not(.vertical) .stat-value {
    font-size: 22px;
}

.goal-word {
    color: var(--neon-pink);
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
}

#game-container:not(.vertical) .goal-word {
    font-size: 16px;
}

/* Legacy stat-box (used in overlays) */
.stat-box {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

/* ============================================================
   UTILITY BUTTONS
   ============================================================ */
.utility-row {
    display: flex;
    gap: 8px;
}

#game-container.vertical .utility-row {
    gap: 6px;
    flex-shrink: 0;
}

.util-btn {
    flex: 1;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 8px;
    min-height: 40px;
    min-width: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.util-btn:active,
.util-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--neon-blue);
    box-shadow: var(--blue-glow);
}

.util-btn svg {
    width: 18px;
    height: 18px;
}

/* ============================================================
   TOUCH CONTROLS (below board)
   ============================================================ */
#controls-hint {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
}

/* Hide touch controls on desktop horizontal layout; show on vertical (mobile) */
#game-container:not(.vertical) #controls-hint {
    display: none;
}

.control-item {
    background: rgba(255, 255, 255, 0.04);
    padding: 8px 6px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: background 0.15s ease, transform 0.1s ease;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* fixed height so JS reservation matches (~60px) */
    height: 56px;
}

.control-item:active {
    background: rgba(255, 255, 255, 0.14);
    transform: scale(0.93);
    border-color: var(--neon-blue);
    box-shadow: 0 0 14px var(--neon-blue);
}

.key {
    font-weight: 800;
    color: var(--neon-pink);
    font-size: 20px;
    line-height: 1;
    margin-bottom: 3px;
}

.action {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    line-height: 1.3;
}

.action small {
    display: block;
    margin-top: 2px;
    color: #555;
    font-size: 7px;
}

/* ============================================================
   OVERLAYS
   ============================================================ */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 20px;
    z-index: 100;
    padding: 20px;
    text-align: center;
}

.overlay.active {
    display: flex;
}

.overlay h2 {
    font-size: 36px;
    margin-bottom: 16px;
    color: var(--neon-pink);
    letter-spacing: 3px;
}

.overlay p {
    font-size: 15px;
    color: #888;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 32px;
    border-radius: 30px;
    border: none;
    background: var(--neon-blue);
    color: black;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active,
.btn:hover {
    transform: scale(1.05);
    box-shadow: var(--blue-glow);
}

.btn.btn-secondary {
    background: rgba(255, 0, 122, 0.2);
    border: 1px solid var(--neon-pink);
    color: white;
}

.btn.btn-secondary:active,
.btn.btn-secondary:hover {
    box-shadow: var(--pink-glow);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes score-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.2); filter: brightness(1.5); }
    100% { transform: scale(1); }
}

.scoring {
    animation: score-pop 0.3s ease-out;
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Small phones — iPhone SE (375px), Galaxy A series */
@media (max-width: 390px) {
    #game-container.vertical {
        padding: 6px 5px;
        gap: 5px;
        border-radius: 14px;
    }

    #game-container.vertical .title {
        font-size: 16px;
        letter-spacing: 2px;
    }

    .stat-chip {
        padding: 4px 7px;
        min-width: 44px;
        border-radius: 8px;
    }

    .stat-value {
        font-size: 13px;
    }

    .stat-label {
        font-size: 8px;
    }

    .goal-word {
        font-size: 11px;
    }

    .util-btn {
        min-height: 34px;
        min-width: 34px;
        padding: 6px;
    }

    .util-btn svg {
        width: 15px;
        height: 15px;
    }

    .control-item {
        padding: 8px 4px;
        border-radius: 10px;
    }

    .key {
        font-size: 16px;
    }

    .action {
        font-size: 8px;
    }

    #controls-hint {
        gap: 5px;
    }
}

/* Standard phones (391–480px) */
@media (min-width: 391px) and (max-width: 480px) {
    #game-container.vertical {
        padding: 8px 7px;
        gap: 7px;
    }

    #game-container.vertical .title {
        font-size: 18px;
    }

    .stat-chip {
        padding: 5px 9px;
    }

    .stat-value {
        font-size: 15px;
    }
}

/* Large phones / small tablets portrait (481–768px) */
@media (min-width: 481px) and (max-width: 820px) and (orientation: portrait) {
    #game-container.vertical {
        padding: 12px 10px;
        gap: 10px;
    }

    #game-container.vertical .title {
        font-size: 22px;
    }

    .stat-chip {
        padding: 7px 12px;
    }

    .stat-value {
        font-size: 17px;
    }

    .control-item {
        padding: 12px 8px;
    }

    .key {
        font-size: 22px;
    }
}

/* Landscape phones — keep horizontal-like layout */
@media (orientation: landscape) and (max-height: 500px) {
    #game-container {
        padding: 10px 16px;
        gap: 14px;
        border-radius: 16px;
    }

    .title {
        font-size: 22px;
        margin-bottom: 8px;
    }

    #hud {
        min-width: 130px;
        gap: 8px;
    }

    .stat-value {
        font-size: 17px;
    }

    #controls-hint {
        display: none; /* landscape: use keyboard or board touch zones */
    }
}