/**
 * Calm Merge - Relaxing Merge 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.
 */

/* ---- 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;

    /* Calm palette */
    --calm-green: #7ec8a0;
    --calm-blue: #7ba7c9;
    --calm-purple: #b49fcc;
    --calm-rose: #d4a0a0;
    --calm-gold: #d4c07a;
    --calm-surface: rgba(255, 255, 255, 0.05);
    --calm-cell: rgba(255, 255, 255, 0.04);
    --calm-cell-hover: rgba(255, 255, 255, 0.08);
    --calm-selected: rgba(126, 200, 160, 0.25);
    --calm-selected-border: rgba(126, 200, 160, 0.6);
    --calm-match-glow: rgba(126, 200, 160, 0.4);

    --grid-size: 5;
    --cell-gap: 6px;
}

/* ---- 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, #1a2a1a 0%, #0f0c29 35%, #1a1640 70%, #0f1a2a 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: 8px;
    margin-bottom: 16px;
}
.logo-emoji {
    font-size: 48px;
    animation: calm-float 4s ease-in-out infinite;
    filter: drop-shadow(0 4px 12px rgba(126, 200, 160, 0.3));
}
.logo-emoji-1 { animation-delay: 0s; }
.logo-emoji-2 { animation-delay: 1.3s; }
.logo-emoji-3 { animation-delay: 2.6s; }

@keyframes calm-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.game-title {
    font-size: 52px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--calm-green), var(--calm-blue), var(--calm-purple));
    -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: 1px;
}

.menu-best {
    font-size: 16px;
    color: var(--calm-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(--calm-green), #5baf82);
    color: #0f1a12;
    box-shadow: 0 4px 24px rgba(126, 200, 160, 0.3);
}
.btn-primary:active {
    box-shadow: 0 2px 12px rgba(126, 200, 160, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    margin-top: 12px;
    font-size: 16px;
    padding: 12px 32px;
}

/* ---- Daily Challenge Button ---- */
.btn-accent {
    background: linear-gradient(135deg, var(--calm-blue), var(--calm-purple));
    color: #fff;
    box-shadow: 0 4px 24px rgba(123, 167, 201, 0.3);
    margin-top: 12px;
    font-size: 17px;
    padding: 14px 32px;
}
.btn-accent:active {
    box-shadow: 0 2px 12px rgba(123, 167, 201, 0.2);
}
.btn-accent.daily-done {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    box-shadow: none;
}

.daily-streak-label {
    font-size: 13px;
    color: var(--calm-gold);
    font-weight: 600;
    margin-top: 6px;
}

/* ---- 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; }

.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;
}

/* ---- Tier Display in HUD ---- */
#tier-display {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.tier-label {
    font-size: 9px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}
.tier-emoji {
    font-size: 28px;
    filter: drop-shadow(0 2px 6px rgba(126, 200, 160, 0.4));
    transition: transform 0.4s ease;
}
.tier-emoji.pop {
    animation: tier-pop 0.5s ease;
}
@keyframes tier-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* ---- Mode Indicator ---- */
.mode-indicator {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--calm-blue);
    padding: 2px 0;
}

/* ---- Merge Chain Display ---- */
#merge-chain {
    padding: 4px 12px;
    overflow: hidden;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chain-items {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: var(--text-secondary);
}
.chain-item {
    font-size: 18px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.chain-arrow {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
}
.chain-item.current {
    filter: drop-shadow(0 0 6px var(--calm-green));
    transform: scale(1.2);
}

/* ---- Game Board ---- */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    position: relative;
}

#board {
    display: grid;
    grid-template-columns: repeat(var(--grid-size), 1fr);
    grid-template-rows: repeat(var(--grid-size), 1fr);
    gap: var(--cell-gap);
    width: 100%;
    max-width: 360px;
    aspect-ratio: 1;
    padding: 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.04);
    position: relative;
}

/* ---- Cells ---- */
.cell {
    position: relative;
    border-radius: 14px;
    background: var(--calm-cell);
    border: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(24px, 7vw, 36px);
    cursor: pointer;
    transition: transform 0.2s ease,
                background 0.3s ease,
                border-color 0.3s ease,
                box-shadow 0.3s ease;
    aspect-ratio: 1;
    overflow: hidden;
}

.cell:active {
    transform: scale(0.92);
}

.cell.empty {
    cursor: default;
}
.cell.empty:active {
    transform: none;
}

/* Selected state */
.cell.selected {
    background: var(--calm-selected);
    border-color: var(--calm-selected-border);
    box-shadow: 0 0 16px var(--calm-match-glow),
                inset 0 0 12px rgba(126, 200, 160, 0.15);
    transform: scale(1.05);
    z-index: 2;
}

/* Matching hint */
.cell.match-hint {
    border-color: rgba(126, 200, 160, 0.35);
    animation: hint-pulse 1.5s ease-in-out infinite;
}

@keyframes hint-pulse {
    0%, 100% { box-shadow: 0 0 0 rgba(126, 200, 160, 0); }
    50% { box-shadow: 0 0 12px rgba(126, 200, 160, 0.2); }
}

/* ---- Cell Item (emoji wrapper) ---- */
.cell-item {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease, opacity 0.3s ease;
    will-change: transform, opacity;
}

/* ---- Merge Animations ---- */
.cell-item.merge-source {
    animation: merge-shrink 0.35s ease-in forwards;
}

@keyframes merge-shrink {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

.cell-item.merge-target {
    animation: merge-grow 0.45s ease-out;
}

@keyframes merge-grow {
    0% { transform: scale(0.3); opacity: 0.5; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

/* New item spawn */
.cell-item.spawn {
    animation: item-spawn 0.5s ease-out;
}

@keyframes item-spawn {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    60% { transform: scale(1.1) rotate(5deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Shake for no-merge */
.cell.shake {
    animation: cell-shake 0.4s ease;
}

@keyframes cell-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(2px); }
}

/* Drag styling */
.cell.dragging {
    opacity: 0.5;
    transform: scale(0.9);
    z-index: 5;
}
.cell.drag-over {
    background: var(--calm-selected);
    border-color: var(--calm-selected-border);
    transform: scale(1.08);
}
.cell.drag-over-invalid {
    border-color: rgba(255, 71, 87, 0.4);
}

/* ---- Game Tip ---- */
.game-tip {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 8px 16px 12px;
    opacity: 0.7;
    transition: opacity 0.5s ease;
}
.game-tip.hidden {
    opacity: 0;
}

/* ---- Sparkle Particles ---- */
#particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
    overflow: hidden;
}

.sparkle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: sparkle-drift 0.9s 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(--calm-green);
    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(--calm-green);
}

/* ---- 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, #1e2a1e, #150f35);
    border: 1px solid rgba(126, 200, 160, 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(--calm-green);
}

/* ---- Help Content ---- */
.help-section {
    margin-bottom: 16px;
    text-align: left;
}
.help-emoji-row {
    font-size: 22px;
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: 4px;
    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(--calm-green), var(--calm-blue));
    -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(--calm-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(--calm-green), var(--calm-blue));
    color: #0f1a12;
    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; }
}

/* ---- Daily Complete Badge (game over) ---- */
.daily-complete-badge {
    background: linear-gradient(135deg, var(--calm-blue), var(--calm-purple));
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    padding: 8px 24px;
    border-radius: 20px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    animation: badge-pop 0.5s ease;
}
.daily-streak-info {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.8;
}

/* ---- 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; }

/* ---- Sound muted indicator ---- */
.icon-btn.muted {
    opacity: 0.4;
}

/* ---- Ambient background glow ---- */
#app::before {
    content: '';
    position: absolute;
    top: 30%;
    left: 50%;
    width: 300px;
    height: 300px;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(126, 200, 160, 0.06) 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, 160, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.05);
        max-height: 900px;
    }
}

/* ---- Toast (no moves / shuffle) ---- */
.shuffle-toast {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(126, 200, 160, 0.9);
    color: #0f1a12;
    font-size: 16px;
    font-weight: 800;
    padding: 12px 28px;
    border-radius: 24px;
    z-index: 300;
    pointer-events: none;
    animation: toast-in 0.4s ease-out;
    transition: opacity 0.4s ease, transform 0.4s ease;
    box-shadow: 0 4px 20px rgba(126, 200, 160, 0.3);
}

@keyframes toast-in {
    0% { transform: translateX(-50%) scale(0.5); opacity: 0; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---- Safe Area ---- */
@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}

/* ---- Spawn Timer ---- */
.spawn-timer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 12px auto 0;
    max-width: 280px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.04);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
}

.spawn-timer-bar {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

.spawn-timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--calm-green), var(--calm-blue));
    border-radius: 3px;
    transition: width 0.1s linear;
    width: 100%;
}

.spawn-timer-text {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
    min-width: 85px;
    text-align: right;
}

.spawn-timer.daily-mode .spawn-timer-fill {
    background: linear-gradient(90deg, #ff6b6b, #ffa502);
}

.spawn-timer.daily-mode .spawn-timer-text {
    color: #ffa502;
}

/* ---- Daily Done Screen ---- */
#screen-daily-done .screen-content {
    gap: 8px;
}

#screen-daily-done h2 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--calm-green), var(--calm-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#screen-daily-done .daily-badge {
    background: linear-gradient(135deg, var(--calm-blue), var(--calm-purple));
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 16px;
    margin-bottom: 8px;
}

#screen-daily-done p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

#screen-daily-done .stats {
    display: flex;
    gap: 32px;
    margin-bottom: 20px;
}

#screen-daily-done .stats .stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#screen-daily-done .stats .stat span:first-child {
    font-size: 28px;
    font-weight: 800;
    color: #fff;
}

#screen-daily-done .stats .stat span:last-child {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
