/**
 * Magnet Puzzle - 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;
    --success-glow: rgba(46, 213, 115, 0.4);
    --magnet-red: #ff4757;
    --magnet-red-glow: rgba(255, 71, 87, 0.5);
    --magnet-blue: #4a9eff;
    --magnet-blue-glow: rgba(74, 158, 255, 0.5);
    --fire-a: #ff6b6b;
    --fire-b: #ff9f43;
    --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: 8px;
    margin-bottom: 16px;
}
.logo-emoji {
    font-size: 56px;
    animation: logo-pulse 2.5s ease-in-out infinite;
}

@keyframes logo-pulse {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-10deg); }
    75% { transform: scale(1.1) rotate(10deg); }
}

.game-title {
    font-size: 52px;
    font-weight: 800;
    letter-spacing: -1px;
    line-height: 1;
    background: linear-gradient(135deg, #fff 0%, #ff4757 40%, #4a9eff 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: 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; }

#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;
}

/* ---- Game Area ---- */
#game-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0 8px;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 12px;
}

/* ---- Game Toolbar ---- */
#game-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    min-height: 64px;
}

.toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 14px;
    padding: 8px 14px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    min-width: 68px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}
.toolbar-btn:active { transform: scale(0.93); }

.toolbar-icon {
    font-size: 20px;
    line-height: 1;
}
.toolbar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* Magnet type buttons */
.magnet-btn-red.active {
    background: rgba(255, 71, 87, 0.25);
    color: var(--magnet-red);
    box-shadow: 0 0 16px var(--magnet-red-glow);
    border: 1px solid rgba(255, 71, 87, 0.4);
}
.magnet-btn-blue.active {
    background: rgba(74, 158, 255, 0.25);
    color: var(--magnet-blue);
    box-shadow: 0 0 16px var(--magnet-blue-glow);
    border: 1px solid rgba(74, 158, 255, 0.4);
}

.toolbar-btn-go {
    background: rgba(46, 213, 115, 0.2);
    color: var(--success);
    min-width: 76px;
    border: 1px solid rgba(46, 213, 115, 0.3);
}
.toolbar-btn-go:active {
    box-shadow: 0 0 16px var(--success-glow);
}
.toolbar-btn-go.simulating {
    background: rgba(255, 159, 67, 0.25);
    color: var(--fire-b);
    border-color: rgba(255, 159, 67, 0.4);
    animation: go-pulse 1s ease-in-out infinite;
}
@keyframes go-pulse {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 159, 67, 0.3); }
    50% { box-shadow: 0 0 20px rgba(255, 159, 67, 0.6); }
}

.toolbar-btn-clear {
    background: rgba(255, 255, 255, 0.06);
}

/* ---- Level Complete Screen ---- */
.level-complete-title {
    font-size: 32px;
    font-weight: 800;
    color: var(--success);
    margin-bottom: 20px;
    animation: badge-pop 0.5s ease-out;
}

.score-breakdown {
    width: 100%;
    max-width: 260px;
    margin-bottom: 20px;
}
.breakdown-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.breakdown-label {
    font-size: 14px;
    color: var(--text-secondary);
}
.breakdown-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}
.breakdown-total {
    border-bottom: none;
    padding-top: 12px;
    margin-top: 4px;
    border-top: 2px solid rgba(255, 217, 61, 0.2);
}
.breakdown-total .breakdown-label {
    font-weight: 700;
    color: var(--text-primary);
}
.breakdown-total .breakdown-value {
    font-size: 18px;
}

/* ---- Game Over Screen ---- */
.gameover-title {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 8px;
}
.gameover-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    max-width: 280px;
    line-height: 1.4;
}
#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;
}

/* ---- 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;
}

/* ---- Pause Overlay ---- */
.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: 320px;
    padding: 0 20px;
}
.help-steps {
    width: 100%;
    margin-bottom: 24px;
}
.help-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    text-align: left;
    padding: 10px 0;
}
.help-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 217, 61, 0.15);
    color: var(--accent);
    font-size: 14px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}
.help-step p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 3px;
}

/* ---- 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%);
}
@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; }
}

/* ---- 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;
    }
}

@supports (padding-top: env(safe-area-inset-top)) {
    #game-header {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
}
