/* ============================================
   BUILD & BREAK - Physics Game Styles
   ============================================ */

:root {
    --bg: #0a0a1a;
    --surface: #141428;
    --surface-el: #1e1e3a;
    --surface-hi: #2a2a4a;
    --primary: #ff6b35;
    --primary-glow: rgba(255, 107, 53, 0.3);
    --secondary: #00b4d8;
    --secondary-glow: rgba(0, 180, 216, 0.3);
    --accent: #ffd60a;
    --accent-glow: rgba(255, 214, 10, 0.3);
    --success: #06d6a0;
    --danger: #ef476f;
    --text: #ffffff;
    --text-dim: #ccccdd;
    --text-muted: #8888aa;
    --wood: #a0782c;
    --steel: #8d9397;
    --glass: #88d5f0;
    --concrete: #999999;
    --radius: 8px;
    --radius-lg: 16px;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
    --transition: 0.25s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    user-select: none;
    -webkit-user-select: none;
}

/* ---- SCREENS ---- */
.screen {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
}
.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- MAIN MENU ---- */
#screen-menu {
    background: radial-gradient(ellipse at 50% 30%, #1a1a3e 0%, var(--bg) 70%);
}

.menu-container {
    text-align: center;
}

.game-title {
    font-size: clamp(3rem, 8vw, 6rem);
    font-weight: 900;
    letter-spacing: 0.03em;
    line-height: 1.1;
    margin-bottom: 0.1em;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 0 30px var(--primary-glow));
}

.game-title span {
    background: linear-gradient(135deg, var(--secondary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 2.5rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

/* ---- BUTTONS ---- */
.btn {
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 0.85em 2.5em;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    min-width: 220px;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #ff8c5a);
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--primary-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface-el);
    color: var(--text);
    border: 2px solid var(--surface-hi);
}
.btn-secondary:hover {
    border-color: var(--secondary);
    box-shadow: 0 0 15px var(--secondary-glow);
    transform: translateY(-2px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
}
.btn-ghost:hover {
    color: var(--text);
    border-color: var(--surface-hi);
}

.btn-small {
    font-size: 0.85rem;
    padding: 0.5em 1.5em;
    min-width: auto;
}

/* ---- MODE SELECT ---- */
#screen-modes {
    background: radial-gradient(ellipse at 50% 40%, #1a1a3e 0%, var(--bg) 70%);
    gap: 2rem;
}

#screen-modes h2 {
    font-size: 1.5rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
}

.mode-cards {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.mode-card {
    width: 240px;
    padding: 2rem 1.5rem;
    background: var(--surface);
    border: 2px solid var(--surface-el);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

.mode-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow);
}

.mode-card.destruction:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 30px var(--primary-glow);
}
.mode-card.survival:hover {
    border-color: var(--secondary);
    box-shadow: 0 8px 30px var(--secondary-glow);
}
.mode-card.precision:hover {
    border-color: var(--accent);
    box-shadow: 0 8px 30px var(--accent-glow);
}

.mode-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.mode-card h3 {
    font-size: 1.2rem;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.mode-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ---- LEVEL SELECT ---- */
#screen-levels {
    background: radial-gradient(ellipse at 50% 40%, #1a1a3e 0%, var(--bg) 70%);
    gap: 2rem;
}

#screen-levels h2 {
    font-size: 1.5rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
}

.level-grid {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 700px;
}

.level-card {
    width: 180px;
    padding: 1.25rem;
    background: var(--surface);
    border: 2px solid var(--surface-el);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
}

.level-card:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: 0 4px 20px var(--primary-glow);
}

.level-card.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.level-card .level-num {
    font-size: 2rem;
    font-weight: 900;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.level-card .level-name {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
}

.level-card .level-stars {
    color: var(--accent);
    font-size: 1rem;
    letter-spacing: 0.2em;
}

/* ---- GAME SCREEN ---- */
#screen-game {
    z-index: 5;
    justify-content: flex-start;
    align-items: stretch;
}

#game-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: crosshair;
}

/* ---- HUD ---- */
#hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50px;
    background: linear-gradient(180deg, rgba(10,10,26,0.95), rgba(10,10,26,0.7));
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
    z-index: 20;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.hud-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.hud-value {
    font-size: 1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

#hud-budget { color: var(--success); }
#hud-mode { color: var(--primary); }

.phase-indicator {
    margin-left: auto;
}

#hud-phase {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    padding: 0.25em 0.75em;
    border-radius: 4px;
    background: var(--surface-el);
    color: var(--secondary);
}

#hud-phase.testing {
    background: rgba(255, 107, 53, 0.15);
    color: var(--primary);
    animation: pulseBorder 1s ease infinite;
}

@keyframes pulseBorder {
    0%, 100% { box-shadow: 0 0 0 0 var(--primary-glow); }
    50% { box-shadow: 0 0 10px 2px var(--primary-glow); }
}

/* ---- PALETTE ---- */
#palette {
    position: absolute;
    top: 55px;
    left: 8px;
    width: 130px;
    background: rgba(14, 14, 28, 0.92);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.06);
    z-index: 20;
    padding: 0.5rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    overflow-x: hidden;
}

#palette::-webkit-scrollbar { width: 4px; }
#palette::-webkit-scrollbar-track { background: transparent; }
#palette::-webkit-scrollbar-thumb { background: var(--surface-hi); border-radius: 2px; }

.palette-section {
    margin-bottom: 0.5rem;
}

.palette-section h4 {
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    padding: 0 0.25rem;
    text-transform: uppercase;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    border: 1px solid transparent;
}

.palette-item:hover {
    background: var(--surface-el);
}

.palette-item.selected {
    background: var(--surface-hi);
    border-color: var(--secondary);
    color: var(--text);
    box-shadow: 0 0 8px var(--secondary-glow);
}

.palette-swatch {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.1);
}

.palette-icon {
    width: 22px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.palette-cost {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* ---- BOTTOM CONTROLS ---- */
#controls {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    z-index: 20;
    padding: 0.4rem;
    background: rgba(14, 14, 28, 0.92);
    backdrop-filter: blur(10px);
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.06);
}

.ctrl-btn {
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.5em 1em;
    border: 1px solid var(--surface-hi);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.ctrl-btn:hover {
    background: var(--surface-el);
    color: var(--text);
    border-color: var(--text-muted);
}

.ctrl-btn.active {
    background: var(--secondary);
    color: #fff;
    border-color: var(--secondary);
}

.ctrl-btn.btn-action {
    background: linear-gradient(135deg, var(--primary), #ff8c5a);
    color: #fff;
    border-color: var(--primary);
    min-width: 130px;
}

.ctrl-btn.btn-action:hover {
    box-shadow: 0 0 15px var(--primary-glow);
}

.ctrl-btn.btn-action.testing {
    background: linear-gradient(135deg, var(--danger), #ff6b8a);
    border-color: var(--danger);
}

/* ---- SCORE SCREEN ---- */
#screen-score {
    background: rgba(10, 10, 26, 0.95);
    backdrop-filter: blur(20px);
}

.score-container {
    text-align: center;
    max-width: 420px;
}

.score-container h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--accent), var(--primary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-details {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--surface-el);
}

.score-row {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem 0;
    font-size: 1rem;
    border-bottom: 1px solid var(--surface-el);
}

.score-row:last-child { border-bottom: none; }

.score-row span:first-child {
    color: var(--text-muted);
}

.score-row span:last-child {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.score-row.total {
    padding-top: 0.8rem;
    margin-top: 0.4rem;
    border-top: 2px solid var(--surface-hi);
    border-bottom: none;
    font-size: 1.3rem;
}

.score-row.total span:last-child {
    color: var(--accent);
}

.stars {
    font-size: 2.5rem;
    letter-spacing: 0.3em;
    margin-top: 1rem;
    animation: starPop 0.5s ease;
}

@keyframes starPop {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.score-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* ---- TUTORIAL ---- */
.overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(10, 10, 26, 0.9);
    backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.tutorial-content {
    max-width: 500px;
    padding: 2.5rem;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--surface-el);
    text-align: center;
}

.tutorial-content h2 {
    font-size: 1.5rem;
    letter-spacing: 0.15em;
    margin-bottom: 1.5rem;
    color: var(--secondary);
}

.tutorial-steps {
    text-align: left;
    margin-bottom: 1.5rem;
}

.tutorial-step {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.step-num {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    font-weight: 900;
    font-size: 0.85rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tutorial-step p {
    color: var(--text-dim);
    font-size: 0.9rem;
    line-height: 1.5;
    padding-top: 3px;
}

.tutorial-controls {
    text-align: left;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--surface-el);
    border-radius: var(--radius);
}

.tutorial-controls h3 {
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
}

.control-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}

kbd {
    display: inline-block;
    padding: 0.15em 0.5em;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--surface);
    border: 1px solid var(--surface-hi);
    border-radius: 3px;
    color: var(--text);
    margin-right: 0.3em;
}

/* ---- NOTIFICATION TOAST ---- */
.toast {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--surface-el);
    color: var(--text);
    padding: 0.6em 1.5em;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid var(--surface-hi);
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    border-color: var(--danger);
    color: var(--danger);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .mode-cards { flex-direction: column; align-items: center; }
    .mode-card { width: 90%; max-width: 300px; }

    #palette {
        width: 100px;
        font-size: 0.7rem;
    }

    .palette-item {
        padding: 0.3rem 0.4rem;
        font-size: 0.7rem;
    }

    .palette-swatch { width: 14px; height: 14px; }

    #controls { gap: 0.3rem; padding: 0.3rem; }
    .ctrl-btn { font-size: 0.65rem; padding: 0.4em 0.6em; }

    .game-title { font-size: clamp(2.5rem, 10vw, 4rem); }
}

@media (max-width: 480px) {
    #palette {
        top: auto;
        bottom: 55px;
        left: 4px;
        width: auto;
        max-height: 200px;
        flex-direction: row;
        display: flex;
        gap: 0.25rem;
    }

    .palette-section { margin-bottom: 0; }
}

/* ---- ANIMATED BACKGROUND (Menu) ---- */
#menu-bg-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    opacity: 0.15;
}
