/**
 * Clear Mind - Zen Tile-Matching 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.
 */

/* ---- Design Tokens ---- */
: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;
    --success: #2ed573;
    --transition-fast: 150ms;
    --transition-normal: 300ms;

    /* Zen palette - soft pastels */
    --zen-teal: #7ec8c0;
    --zen-lavender: #b0a0d4;
    --zen-rose: #d4a0b0;
    --zen-sky: #7bb0d4;
    --zen-gold: #d4c88a;
    --zen-mint: #90d4a8;
    --zen-surface: rgba(255, 255, 255, 0.05);
    --zen-cell: rgba(255, 255, 255, 0.06);
    --zen-cell-hover: rgba(255, 255, 255, 0.10);
    --zen-selected: rgba(126, 200, 192, 0.30);
    --zen-selected-border: rgba(126, 200, 192, 0.7);
    --zen-hint-glow: rgba(176, 160, 212, 0.5);
    --zen-free-border: rgba(255, 255, 255, 0.08);
    --zen-blocked-bg: rgba(255, 255, 255, 0.02);

    --cols: 8;
    --rows: 6;
    --cell-gap: 4px;
}

/* ---- Reset ---- */
*, *::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, #141035 0%, #0f0c29 35%, #1a1640 70%, #0f1530 100%);
}

/* ---- Screen System ---- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s 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;
}

/* ---- Back Link ---- */
.back-to-games-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 10px;
    transition: color var(--transition-fast), background var(--transition-fast);
    margin-bottom: 12px;
}
.back-to-games-inline:active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
.gameover-back {
    margin-top: 12px;
}

/* ---- Menu Screen ---- */
.game-logo {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}
.logo-emoji {
    font-size: 46px;
    animation: zen-float 5s ease-in-out infinite;
    filter: drop-shadow(0 4px 12px rgba(126, 200, 192, 0.25));
}
.logo-emoji-1 { animation-delay: 0s; }
.logo-emoji-2 { animation-delay: 1.7s; }
.logo-emoji-3 { animation-delay: 3.3s; }

@keyframes zen-float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-6px) rotate(2deg); }
}

.game-title {
    font-size: 52px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--zen-teal), var(--zen-lavender), var(--zen-rose));
    -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: 20px;
    font-weight: 500;
    letter-spacing: 2px;
}

.menu-best {
    font-size: 16px;
    color: var(--zen-gold);
    font-weight: 700;
    margin-bottom: 24px;
    font-variant-numeric: tabular-nums;
}

/* ---- 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;
    font-family: inherit;
    text-decoration: none;
    text-align: center;
}
.btn:active { transform: scale(0.95); }

.btn-primary {
    background: linear-gradient(135deg, var(--zen-teal), #5aaca4);
    color: #0f1a1a;
    box-shadow: 0 4px 24px rgba(126, 200, 192, 0.3);
}
.btn-primary:active {
    box-shadow: 0 2px 12px rgba(126, 200, 192, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}

/* ---- Icon Buttons ---- */
.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: 14px; }
.icon-btn.muted { opacity: 0.4; }

.settings-row {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}
.pause-settings { margin-top: 16px; }

/* ---- Game Header / HUD ---- */
#game-header {
    display: flex;
    align-items: center;
    padding: 10px 12px 6px;
    gap: 8px;
    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;
    justify-content: center;
    align-items: center;
}

/* ---- Timer Bar ---- */
#timer-bar-container {
    position: relative;
    height: 22px;
    margin: 0 12px 4px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 11px;
    overflow: hidden;
}
#timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--zen-teal), var(--zen-lavender));
    border-radius: 11px;
    transition: width 1s linear;
}
#timer-bar.low {
    background: linear-gradient(90deg, var(--danger), #ff9f43);
}
#timer-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ---- Combo Display ---- */
#combo-display {
    text-align: center;
    padding: 2px 0;
    min-height: 24px;
}
#combo-text {
    font-size: 14px;
    font-weight: 800;
    color: var(--zen-gold);
    text-shadow: 0 0 10px rgba(212, 200, 138, 0.4);
    animation: combo-pulse 0.4s ease;
}
@keyframes combo-pulse {
    0% { transform: scale(0.6); opacity: 0; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Game Board ---- */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    position: relative;
}

#board {
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    grid-template-rows: repeat(var(--rows), 1fr);
    gap: var(--cell-gap);
    width: 100%;
    max-width: 390px;
    padding: 8px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.03);
    position: relative;
}

/* ---- Tiles ---- */
.tile {
    position: relative;
    border-radius: 10px;
    background: var(--zen-cell);
    border: 1.5px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(20px, 5.5vw, 30px);
    cursor: pointer;
    transition: transform 0.2s ease,
                background 0.25s ease,
                border-color 0.25s ease,
                box-shadow 0.25s ease,
                opacity 0.3s ease;
    aspect-ratio: 1;
    overflow: hidden;
}

.tile:active {
    transform: scale(0.92);
}

/* Empty tile (already cleared) */
.tile.empty {
    background: transparent;
    border-color: transparent;
    cursor: default;
    pointer-events: none;
}
.tile.empty:active {
    transform: none;
}

/* Blocked tile (not free) */
.tile.blocked {
    background: var(--zen-blocked-bg);
    border-color: rgba(255, 255, 255, 0.02);
    opacity: 0.55;
    cursor: not-allowed;
    filter: saturate(0.4);
}
.tile.blocked:active {
    transform: none;
}

/* Free tile glow */
.tile.free {
    border-color: var(--zen-free-border);
    background: var(--zen-cell);
}

/* Selected state */
.tile.selected {
    background: var(--zen-selected);
    border-color: var(--zen-selected-border);
    box-shadow: 0 0 16px rgba(126, 200, 192, 0.4),
                inset 0 0 10px rgba(126, 200, 192, 0.12);
    transform: scale(1.08);
    z-index: 2;
    opacity: 1 !important;
    filter: none !important;
}

/* Hint highlight */
.tile.hint {
    border-color: var(--zen-lavender);
    animation: hint-glow 1.2s ease-in-out infinite;
    opacity: 1 !important;
    filter: none !important;
}
@keyframes hint-glow {
    0%, 100% { box-shadow: 0 0 4px var(--zen-hint-glow); }
    50% { box-shadow: 0 0 18px var(--zen-hint-glow), inset 0 0 8px rgba(176, 160, 212, 0.15); }
}

/* ---- Tile Clearing Animation ---- */
.tile.clearing {
    animation: tile-clear 0.45s ease-in forwards;
    pointer-events: none;
}
@keyframes tile-clear {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(1.15); opacity: 0.9; }
    100% { transform: scale(0); opacity: 0; }
}

/* Tile settle/shift animation */
.tile.settling {
    animation: tile-settle 0.35s ease-out;
}
@keyframes tile-settle {
    0% { transform: translateY(-12px); opacity: 0.5; }
    60% { transform: translateY(2px); }
    100% { transform: translateY(0); opacity: 1; }
}

/* Spawn animation for new level */
.tile.spawn {
    animation: tile-spawn 0.4s ease-out;
}
@keyframes tile-spawn {
    0% { transform: scale(0) rotate(-10deg); opacity: 0; }
    70% { transform: scale(1.05) rotate(2deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Shuffle animation */
.tile.shuffling {
    animation: tile-shuffle 0.5s ease-in-out;
}
@keyframes tile-shuffle {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(0.7) rotate(10deg); opacity: 0.4; }
    70% { transform: scale(0.7) rotate(-10deg); opacity: 0.4; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Wrong match shake */
.tile.shake {
    animation: tile-shake 0.4s ease;
}
@keyframes tile-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* ---- Game Action Buttons ---- */
#game-actions {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 6px 16px 4px;
}
.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 20px;
    border: none;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    font-family: inherit;
    border: 1px solid rgba(255, 255, 255, 0.04);
}
.action-btn:active {
    transform: scale(0.93);
    background: rgba(255, 255, 255, 0.1);
}
.action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.action-icon {
    font-size: 20px;
}
.action-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ---- Game Tip ---- */
.game-tip {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 16px 10px;
    opacity: 0.6;
    transition: opacity 0.5s ease;
}

/* ---- Sparkle Particles ---- */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.sparkle {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    pointer-events: none;
    animation: sparkle-drift 0.8s ease-out forwards;
}
@keyframes sparkle-drift {
    0% { transform: translate(0, 0) scale(1); opacity: 0.9; }
    100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* Score popup */
.score-popup {
    position: absolute;
    font-size: 18px;
    font-weight: 800;
    color: var(--zen-teal);
    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%);
}
@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(-50px) scale(0.9); opacity: 0; }
}

/* ---- Overlays ---- */
.game-overlay {
    position: absolute;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.7);
    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.3s 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;
    color: var(--zen-teal);
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 20px;
}
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: linear-gradient(170deg, #1a1845, #150f35);
    border: 1px solid rgba(126, 200, 192, 0.1);
    border-radius: 20px;
    padding: 28px 24px;
    max-width: 360px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.9);
    transition: transform 0.25s ease;
}
.modal-overlay.active .modal-content {
    transform: scale(1);
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 20px;
    color: var(--zen-teal);
}

/* ---- Help Content ---- */
.help-section {
    margin-bottom: 16px;
    text-align: left;
}
.help-emoji-row {
    font-size: 22px;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 6px;
    line-height: 1.6;
}
.help-text {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ---- Game Over ---- */
.gameover-title {
    font-size: 32px;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--zen-teal), var(--zen-lavender));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.final-score-block,
.final-best-block {
    margin-bottom: 8px;
}
.final-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.final-value {
    font-size: 48px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.final-value-small {
    font-size: 28px;
    color: var(--zen-gold);
}

.final-stats {
    display: flex;
    gap: 24px;
    margin: 20px 0 24px;
}
.final-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.final-stat-num {
    font-size: 24px;
    font-weight: 800;
}
.final-stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#new-best-badge {
    background: linear-gradient(135deg, var(--zen-teal), var(--zen-lavender));
    color: #0f1a1a;
    font-size: 14px;
    font-weight: 800;
    padding: 6px 20px;
    border-radius: 20px;
    margin-bottom: 12px;
    animation: badge-pop 0.5s ease;
}
@keyframes badge-pop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ---- Footer ---- */
.game-footer {
    margin-top: 24px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    letter-spacing: 0.5px;
    font-weight: 500;
}
.game-footer a {
    color: inherit;
    text-decoration: none;
}

/* ---- Hidden Utility ---- */
.hidden { display: none !important; }

/* ---- Ambient Background Glow ---- */
#app::before {
    content: '';
    position: absolute;
    top: 35%;
    left: 50%;
    width: 320px;
    height: 320px;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(126, 200, 192, 0.05) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ---- Responsive: Desktop Frame ---- */
@media (min-width: 421px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        background: #060512;
    }
    #app {
        border-radius: 24px;
        box-shadow: 0 0 80px rgba(126, 200, 192, 0.06);
        border: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 900px;
    }
}

/* ---- Safe Area ---- */
@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}
