/**
 * Chain Pop - Mobile-First Chain Reaction Puzzle 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;
    --bg-board: rgba(255, 255, 255, 0.04);
    --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;
    --cell-size: 42px;
    --cell-gap: 3px;
    --cell-radius: 50%;
    --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: manipulation;
    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: 4px;
    margin-bottom: 16px;
    align-items: center;
}
.logo-bubble {
    font-size: 28px;
    animation: logo-float 2.5s ease-in-out infinite;
    filter: drop-shadow(0 2px 6px rgba(255, 255, 255, 0.15));
}
.logo-bubble-1 { animation-delay: 0s; }
.logo-bubble-2 { animation-delay: 0.2s; }
.logo-bubble-3 { animation-delay: 0.4s; }
.logo-bubble-4 { animation-delay: 0.6s; }
.logo-bubble-5 { animation-delay: 0.8s; }

@keyframes logo-float {
    0%, 100% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-8px) scale(1.1); }
    60% { transform: translateY(3px) scale(0.95); }
}

.game-title {
    font-size: 52px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #ffd93d 50%, #ff6b9d 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: 24px;
}
.menu-best {
    font-size: 18px;
    color: var(--accent);
    margin-bottom: 16px;
    font-weight: 600;
}

/* ---- Settings Row ---- */
.settings-row {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    align-items: 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;
}

/* ---- 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: 32px; height: 32px; font-size: 14px; }
.icon-btn.off { opacity: 0.4; }

/* ---- Game Header ---- */
#screen-game { display: flex; flex-direction: column; }

#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;
}

/* ---- Combo Display ---- */
#combo-display {
    text-align: center;
}
.combo-text {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent-glow);
    animation: combo-pulse 0.4s ease-out;
}
@keyframes combo-pulse {
    0% { transform: scale(1.6); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Board ---- */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    position: relative;
    overflow: hidden;
}

#board {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
    gap: var(--cell-gap);
    background: var(--bg-board);
    border-radius: 14px;
    padding: 6px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3);
    position: relative;
}

/* ---- Bubble Cells ---- */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    position: relative;
    overflow: hidden;
}
.cell:active {
    transform: scale(0.9);
}
.cell.empty {
    background: rgba(255, 255, 255, 0.03);
    cursor: default;
    pointer-events: none;
}

/* Bubble colors */
.cell.color-0 { background: radial-gradient(circle at 35% 35%, #ff6b6b, #e03131); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(224,49,49,0.3); }
.cell.color-1 { background: radial-gradient(circle at 35% 35%, #ffa94d, #e8590c); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(232,89,12,0.3); }
.cell.color-2 { background: radial-gradient(circle at 35% 35%, #ffe066, #f59f00); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(245,159,0,0.3); }
.cell.color-3 { background: radial-gradient(circle at 35% 35%, #69db7c, #2f9e44); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(47,158,68,0.3); }
.cell.color-4 { background: radial-gradient(circle at 35% 35%, #74c0fc, #1c7ed6); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(28,126,214,0.3); }
.cell.color-5 { background: radial-gradient(circle at 35% 35%, #da77f2, #9c36b5); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), 0 1px 4px rgba(156,54,181,0.3); }

/* Bubble highlight */
.cell:not(.empty):not(.powerup)::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 8px;
    width: 12px;
    height: 8px;
    background: radial-gradient(ellipse, rgba(255,255,255,0.6) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

/* Power-up cells */
.cell.powerup {
    animation: powerup-glow 1.5s ease-in-out infinite;
    font-size: 22px;
    background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.15), rgba(255,255,255,0.05));
    box-shadow: 0 0 12px rgba(255, 217, 61, 0.4);
}
@keyframes powerup-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 217, 61, 0.3); }
    50% { box-shadow: 0 0 18px rgba(255, 217, 61, 0.6); }
}

/* Pop animation */
.cell.popping {
    animation: bubble-pop 0.3s ease-out forwards;
    pointer-events: none;
}
@keyframes bubble-pop {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(1.2); opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

/* Fall animation */
.cell.falling {
    transition: none;
    animation: bubble-fall 0.25s ease-in;
}
@keyframes bubble-fall {
    0% { transform: translateY(calc(-1 * (var(--cell-size) + var(--cell-gap)))); }
    100% { transform: translateY(0); }
}

/* New row slide-in */
.cell.slide-in {
    animation: slide-up 0.3s ease-out;
}
@keyframes slide-up {
    0% { transform: translateY(calc(var(--cell-size) + var(--cell-gap))); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Highlight valid clusters on hover */
.cell.highlight {
    filter: brightness(1.3);
    transform: scale(1.05);
}

/* Can't pop indicator */
.cell.invalid-tap {
    animation: shake 0.3s ease;
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* ---- Tap Counter ---- */
#tap-counter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}
.tap-label {
    font-weight: 500;
}
.tap-count {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
#tap-counter.warning .tap-count {
    color: var(--danger);
    animation: pulse-warn 0.5s ease-in-out infinite;
}
@keyframes pulse-warn {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ---- Score Popups ---- */
.score-popup {
    position: absolute;
    pointer-events: none;
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    z-index: 30;
    animation: float-up 1s ease-out forwards;
    white-space: nowrap;
}
@keyframes float-up {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    70% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-50px) scale(0.7); }
}

/* ---- Center Combo Text ---- */
.center-combo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 36px;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.5);
    z-index: 40;
    pointer-events: none;
    animation: combo-appear 0.8s ease-out forwards;
    white-space: nowrap;
}
@keyframes combo-appear {
    0% { transform: translate(-50%, -50%) scale(0) rotate(-5deg); opacity: 0; }
    30% { transform: translate(-50%, -50%) scale(1.3) rotate(2deg); opacity: 1; }
    60% { transform: translate(-50%, -50%) scale(1) rotate(0deg); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8) rotate(0deg); opacity: 0; }
}

/* ---- Particles ---- */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
}
.particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: particle-fly 0.6s ease-out forwards;
}
@keyframes particle-fly {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--px), var(--py)) scale(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;
}

/* ---- Modal ---- */
.modal-overlay {
    position: absolute;
    inset: 0;
    z-index: 60;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 20px;
}
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: linear-gradient(170deg, #251e5a 0%, #1a1640 100%);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 340px;
    width: 100%;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-height: 80vh;
    overflow-y: auto;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 16px;
    text-align: center;
}
.help-section {
    margin-bottom: 14px;
}
.help-emoji-row {
    font-size: 24px;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 4px;
}
.help-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    text-align: center;
}
.help-text strong {
    color: var(--text-primary);
}

/* ---- Game Over Screen ---- */
.gameover-title {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #fff 0%, #ffd93d 50%, #ff6b9d 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
#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: 20px;
    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;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 12px;
}

/* ---- 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;
}

/* ---- Danger indicator ---- */
#board.danger-zone {
    animation: danger-flash 0.5s ease-in-out infinite;
}
@keyframes danger-flash {
    0%, 100% { box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3); }
    50% { box-shadow: inset 0 0 30px rgba(255, 71, 87, 0.3), 0 0 20px rgba(255, 71, 87, 0.2); }
}

/* ---- Shuffle ---- */
#board.shuffle-flash {
    animation: shuffle-flash 0.5s ease-out;
}
@keyframes shuffle-flash {
    0%   { filter: brightness(1.8) saturate(0.3); }
    50%  { filter: brightness(1.2) saturate(0.8); }
    100% { filter: brightness(1) saturate(1); }
}

/* ---- Responsive ---- */
@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;
    }
}

@media (max-width: 380px) {
    :root {
        --cell-size: 36px;
        --cell-gap: 2px;
    }
}

@media (max-height: 650px) {
    :root {
        --cell-size: 34px;
        --cell-gap: 2px;
    }
    .screen-content { padding: 24px 16px; }
    .game-title { font-size: 40px; }
}

@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}
