/**
 * Word Collapse - Mobile-First Game Styles
 *
 * @file        styles.css
 * @author      Mike Fairbrother <mike@fairbrother.me>
 * @copyright   2024-2026 Mike Fairbrother. All rights reserved.
 * @license     PROPRIETARY - No rights to copy, modify, distribute, or reuse
 *              any part of this code without explicit written permission from the author.
 */

:root {
    --bg-dark: #0f0c29;
    --bg-mid: #1a1640;
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --accent: #ffd93d;
    --accent-glow: rgba(255, 217, 61, 0.4);
    --danger: #ff4757;
    --danger-glow: rgba(255, 71, 87, 0.5);
    --success: #2ed573;
    --fire-a: #ff6b6b;
    --fire-b: #ff9f43;
    --vowel-bg: #3d2066;
    --vowel-border: #a855f7;
    --consonant-bg: #1a3a5c;
    --consonant-border: #3b82f6;
    --gold-bg: #5c4a00;
    --gold-border: #ffd93d;
    --rainbow-border: linear-gradient(135deg, #ff6b6b, #ffd93d, #2ed573, #3b82f6, #a855f7);
    --tile-size: 52px;
    --tile-gap: 4px;
    --transition-fast: 150ms;
    --transition-normal: 300ms;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ---- App container ---- */
#app {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    overflow: hidden;
    background: linear-gradient(170deg, #1a1640 0%, #0f0c29 40%, #1e1245 100%);
}

/* ---- Screen system ---- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}
.screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}
.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    padding: 40px 24px;
    text-align: center;
    overflow-y: auto;
}

/* ---- Menu Screen ---- */
.game-logo {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.logo-emoji {
    font-size: 48px;
    animation: logo-bounce 2s ease-in-out infinite;
}
.logo-emoji:nth-child(2) { animation-delay: 0.15s; }
.logo-emoji:nth-child(3) { animation-delay: 0.3s; }

@keyframes logo-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.game-title {
    font-size: 52px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #ffd93d 50%, #ff6b6b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}
.game-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.game-hint {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 20px;
}
.menu-best {
    font-size: 18px;
    color: var(--accent);
    margin-bottom: 24px;
    font-weight: 600;
}

/* ---- Settings Row ---- */
.settings-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: center;
    justify-content: center;
}
.pause-settings {
    margin-top: 20px;
}

/* ---- Footer ---- */
.game-footer {
    margin-top: 16px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.5px;
    font-weight: 500;
    flex-shrink: 0;
}
.game-footer a {
    color: inherit;
    text-decoration: none;
}
.game-footer a:hover {
    text-decoration: underline;
}

/* ---- Buttons ---- */
.btn {
    display: block;
    width: 220px;
    padding: 16px 32px;
    border: none;
    border-radius: 16px;
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    letter-spacing: 0.5px;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
    background: linear-gradient(135deg, #ffd93d, #ff9f43);
    color: #1a1640;
    box-shadow: 0 4px 20px rgba(255, 217, 61, 0.3);
}
.btn-primary:active { box-shadow: 0 2px 10px rgba(255, 217, 61, 0.2); }
.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }

.icon-btn-sm {
    width: 30px;
    height: 30px;
    font-size: 13px;
    border-radius: 8px;
}

/* ---- Game Header ---- */
#screen-game { display: flex; flex-direction: column; touch-action: none; }

#game-header {
    display: flex;
    align-items: center;
    padding: 10px 8px 6px;
    gap: 6px;
    min-height: 52px;
}
.stat {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.stat-right { align-items: flex-end; }
.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.stat-value {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

/* ---- Word Preview ---- */
#word-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 4px 12px;
    margin: 0 8px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    transition: background var(--transition-fast);
}
#word-preview.valid {
    background: rgba(46, 213, 115, 0.12);
}
#word-preview.invalid {
    background: rgba(255, 71, 87, 0.08);
}
#word-preview-text {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 3px;
    text-transform: uppercase;
    min-height: 28px;
    transition: color var(--transition-fast);
}
#word-preview.valid #word-preview-text {
    color: var(--success);
}
#word-preview.invalid #word-preview-text {
    color: rgba(255, 255, 255, 0.3);
}
#word-preview-status {
    font-size: 12px;
    font-weight: 700;
    opacity: 0.7;
}
#word-preview.valid #word-preview-status {
    color: var(--success);
}

/* ---- Streak Bar ---- */
#streak-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    margin: 2px 8px 0;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(255, 107, 107, 0.2), rgba(255, 159, 67, 0.2));
    transition: opacity var(--transition-fast);
}
#streak-bar.hidden {
    display: none;
}
#streak-text {
    font-size: 13px;
    font-weight: 700;
    color: var(--fire-b);
}

/* ---- Grid Area ---- */
#grid-area {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 8px;
    overflow: hidden;
    touch-action: none;
}

#grid-container {
    display: grid;
    grid-template-columns: repeat(6, var(--tile-size));
    gap: var(--tile-gap);
    justify-content: center;
    position: relative;
    z-index: 2;
    touch-action: none;
}

#selection-line {
    position: absolute;
    inset: 0;
    z-index: 3;
    pointer-events: none;
    overflow: visible;
}
#selection-line line {
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.7;
    filter: drop-shadow(0 0 4px var(--accent-glow));
}

/* ---- Letter Tiles ---- */
.tile {
    width: var(--tile-size);
    height: var(--tile-size);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    cursor: pointer;
    position: relative;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-normal);
    border: 2px solid transparent;
    text-transform: uppercase;
    touch-action: none;
}

.tile-vowel {
    background: var(--vowel-bg);
    border-color: var(--vowel-border);
    color: #e0b0ff;
}
.tile-consonant {
    background: var(--consonant-bg);
    border-color: var(--consonant-border);
    color: #a5c8ff;
}
.tile-gold {
    background: var(--gold-bg);
    border-color: var(--gold-border);
    color: var(--accent);
    box-shadow: 0 0 8px rgba(255, 217, 61, 0.3);
}
.tile-gold::after {
    content: '\2B50';
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 12px;
    line-height: 1;
}
.tile-rainbow {
    background: linear-gradient(135deg, #2d1b4e, #1b3a5c, #1b4a3a);
    color: #fff;
    animation: rainbow-border 2s linear infinite;
    border-image: linear-gradient(135deg, #ff6b6b, #ffd93d, #2ed573, #3b82f6, #a855f7) 1;
    border-style: solid;
    border-width: 2px;
    border-radius: 12px;
}
/* Rainbow tiles need a special approach for rounded border-image */
.tile-rainbow {
    border: none;
    outline: 2px solid transparent;
    background-clip: padding-box;
    position: relative;
    overflow: visible;
}
.tile-rainbow::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 13px;
    background: linear-gradient(135deg, #ff6b6b, #ffd93d, #2ed573, #3b82f6, #a855f7);
    z-index: -1;
    animation: rainbow-spin 2s linear infinite;
}
.tile-rainbow::after {
    content: '?';
    position: absolute;
    top: -4px;
    right: -2px;
    font-size: 11px;
    line-height: 1;
    color: rgba(255,255,255,0.6);
}

@keyframes rainbow-spin {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

.tile.selected {
    transform: scale(1.1);
    box-shadow: 0 0 16px var(--accent-glow), 0 0 32px rgba(255, 217, 61, 0.15);
    border-color: var(--accent) !important;
    z-index: 5;
}
.tile.selected::before {
    display: none;
}

.tile.pop {
    animation: tile-pop 0.35s ease-out forwards;
}
@keyframes tile-pop {
    0%   { transform: scale(1); opacity: 1; }
    40%  { transform: scale(1.3); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

.tile.slide-up {
    animation: tile-slide-up 0.3s ease-out;
}
@keyframes tile-slide-up {
    0%   { transform: translateY(calc(var(--tile-size) + var(--tile-gap))); opacity: 0.5; }
    100% { transform: translateY(0); opacity: 1; }
}

.tile.fall-in {
    animation: tile-fall 0.25s ease-out;
}
@keyframes tile-fall {
    0%   { transform: translateY(calc(-1 * (var(--tile-size) + var(--tile-gap)))); }
    70%  { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

/* Empty tile placeholder */
.tile-empty {
    width: var(--tile-size);
    height: var(--tile-size);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

/* ---- Row Timer Bar ---- */
#row-timer {
    height: 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 2px;
    margin: 0 16px 4px;
    overflow: hidden;
    flex-shrink: 0;
}
#row-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--success), var(--accent), var(--danger));
    border-radius: 2px;
    transition: width 25s linear;
}

/* ---- Hint Glow ---- */
.tile-hint {
    animation: hint-pulse 1.2s ease-in-out infinite;
    box-shadow: 0 0 12px rgba(255, 217, 61, 0.5), inset 0 0 8px rgba(255, 217, 61, 0.15) !important;
    border-color: var(--accent) !important;
}
@keyframes hint-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 217, 61, 0.3), inset 0 0 6px rgba(255, 217, 61, 0.1); }
    50% { box-shadow: 0 0 18px rgba(255, 217, 61, 0.6), inset 0 0 10px rgba(255, 217, 61, 0.2); }
}

/* ---- Particles ---- */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}
.particle {
    position: fixed;
    pointer-events: none;
    animation: particle-fly 0.65s ease-out forwards;
    z-index: 200;
}
@keyframes particle-fly {
    0%   { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

/* Score popup */
.score-popup {
    position: fixed;
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 20;
    animation: score-float 0.9s ease-out forwards;
    white-space: nowrap;
    transform: translateX(-50%);
}
.score-popup.big-combo {
    font-size: 26px;
    color: var(--fire-a);
    text-shadow: 0 0 10px rgba(255, 107, 107, 0.5);
}
@keyframes score-float {
    0%   { transform: translateX(-50%) translateY(0) scale(0.5); opacity: 0; }
    20%  { transform: translateX(-50%) translateY(-10px) scale(1.1); opacity: 1; }
    100% { transform: translateX(-50%) translateY(-60px) scale(0.9); opacity: 0; }
}

/* Combo / word popup */
.combo-popup {
    position: fixed;
    font-size: 28px;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 30;
    white-space: nowrap;
    animation: combo-burst 0.8s ease-out forwards;
}
@keyframes combo-burst {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    20%  { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    60%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
}

/* Screen shake */
.shake { animation: shake 0.3s ease-out; }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px) rotate(-0.5deg); }
    40% { transform: translateX(4px) rotate(0.5deg); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* ---- Game Over Screen ---- */
.gameover-title {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 8px;
}
#new-best-badge {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    background: rgba(255, 217, 61, 0.15);
    padding: 6px 20px;
    border-radius: 20px;
    margin-bottom: 16px;
    animation: badge-pop 0.5s ease-out;
}
@keyframes badge-pop {
    0%  { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}
.hidden { display: none !important; }

.final-score-block, .final-best-block { margin-bottom: 6px; }
.final-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.final-value {
    font-size: 52px;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.final-value-small {
    font-size: 26px;
    color: var(--text-secondary);
}
.final-stats {
    display: flex;
    gap: 24px;
    margin: 20px 0 16px;
}
.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.final-stat-num {
    font-size: 22px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.final-stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}
.motivation-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--fire-a);
    margin-bottom: 20px;
    animation: badge-pop 0.5s ease-out 0.3s both;
}

/* ---- Back to Games ---- */
.back-to-games-inline {
    display: inline-block;
    color: rgba(255, 255, 255, 0.35);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 10px;
    margin-bottom: 12px;
    transition: color 150ms, background 150ms;
}
.back-to-games-inline:active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
.gameover-back {
    margin-top: 12px;
    margin-bottom: 0;
}

/* ---- Overlays ---- */
.game-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.game-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.overlay-title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 20px;
}

/* ---- Help Modal ---- */
.help-content {
    max-width: 340px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
}
.help-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 24px;
    text-align: left;
}
.help-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}
.help-icon {
    font-size: 22px;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}
.help-item p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ---- Danger state ---- */
#grid-container.danger {
    animation: grid-danger-pulse 0.8s ease-in-out infinite;
}
@keyframes grid-danger-pulse {
    0%, 100% { box-shadow: 0 0 0 0 transparent; }
    50% { box-shadow: 0 0 20px rgba(255, 71, 87, 0.3); }
}

/* ---- Responsive ---- */
@media (max-width: 370px) {
    :root {
        --tile-size: 44px;
        --tile-gap: 3px;
    }
    .tile { font-size: 18px; border-radius: 10px; }
}

@media (min-width: 421px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: #080620;
    }
    #app {
        border-radius: 24px;
        box-shadow: 0 0 60px rgba(30, 20, 80, 0.5);
        border: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 900px;
    }
}

@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}
