@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@500;600;700;800&display=swap');

:root {
    --bg-base: #eef2f7;
    --bg-gradient: linear-gradient(160deg, #f8fafc 0%, #e8eef6 45%, #dfe8f4 100%);
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: #eff6ff;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --gold: #b45309;
    --gold-soft: #fff7ed;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 30px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.12);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
    --z-joystick: 40;
    --z-screen: 50;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100vh;
    margin: 0;
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: var(--font-body);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

.is-hidden { display: none !important; }

/* Game canvas */
#game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--bg-base);
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* HUD */
#game-hud {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    pointer-events: none;
}

.btn--home {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
    pointer-events: auto;
    z-index: calc(var(--z-screen) + 1);
}

.btn--home:hover {
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.98);
}

.btn--home i { color: var(--text-primary); font-size: 1rem; }

.hud-top {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    width: 100%;
    max-width: 52rem;
    margin: 0 auto;
    pointer-events: auto;
}

.hud-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.hud-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(10px);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.hud-chip__label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.hud-chip__value {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 800;
    color: var(--accent);
}

.hud-stat i { color: var(--text-secondary); font-size: 0.875rem; }
.hud-stat--credits i { color: var(--gold); }

.btn--hud-upgrade {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.btn--hud-upgrade:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}

.upgrade-badge {
    min-width: 1.25rem;
    padding: 0.125rem 0.375rem;
    background: var(--warning);
    color: #fff;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 700;
    text-align: center;
}

.bar-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.bar-track--hp { width: 10rem; }

.bar-fill {
    height: 100%;
    width: var(--bar-pct, 0%);
    border-radius: 999px;
    transition: width 150ms ease;
}

.bar-fill--xp {
    background: linear-gradient(90deg, #3b82f6, #0ea5e9);
}

.bar-fill--hp {
    background: linear-gradient(90deg, #ef4444, #f97316);
}

.hud-bottom {
    display: flex;
    justify-content: center;
    padding-bottom: 1.25rem;
    pointer-events: auto;
}

.hud-panel {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.25rem;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
}

.hull-icon {
    color: var(--danger);
    font-size: 1.25rem;
}

.hull-info { display: flex; flex-direction: column; gap: 0.375rem; }

.hull-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.hull-value {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--danger);
    min-width: 2.5rem;
    text-align: right;
}

/* Joystick */
#virtual-joystick-bg {
    position: absolute;
    left: var(--joy-x, 40px);
    top: var(--joy-y, 40px);
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    border: 2px solid rgba(148, 163, 184, 0.5);
    box-shadow: var(--shadow-md);
    display: none;
    touch-action: none;
    z-index: var(--z-joystick);
}

#virtual-joystick-bg.is-active { display: block; }

#virtual-joystick-knob {
    position: absolute;
    left: calc(50% + var(--knob-x, 0px));
    top: calc(50% + var(--knob-y, 0px));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(145deg, #3b82f6, #1d4ed8);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Screens */
.screen {
    position: absolute;
    inset: 0;
    z-index: var(--z-screen);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    overflow-y: auto;
    background: rgba(248, 250, 252, 0.88);
    backdrop-filter: blur(14px);
}

.screen--gameover {
    background: rgba(254, 242, 242, 0.9);
}

.screen-eyebrow,
.start-eyebrow {
    margin: 0 0 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

/* Start */
.start-card,
.hangar-card,
.deck-card,
.gameover-card {
    width: 100%;
    max-width: 32rem;
    padding: 2.5rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.deck-card { max-width: 56rem; text-align: left; }
.hangar-card { max-width: 36rem; text-align: left; }

.game-logo {
    margin: 0 0 0.75rem;
    line-height: 0;
}

.game-logo__img {
    display: block;
    width: min(100%, 15rem);
    height: auto;
    margin: 0 auto;
    object-fit: contain;
}

.game-subtitle {
    margin: 0 0 2rem;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-secondary);
    max-width: 26rem;
    margin-left: auto;
    margin-right: auto;
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.control-card {
    padding: 1rem 0.75rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, transform 0.15s;
}

.control-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.control-card i {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.control-card i.fa-crosshairs { color: var(--danger); }
.control-card i.fa-screwdriver-wrench { color: var(--warning); }

.control-label {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.control-value {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.start-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn--launch-full { width: 100%; }

/* Buttons */
.btn {
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    pointer-events: auto;
    transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.btn--primary {
    padding: 0.9375rem 1.5rem;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.btn--primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.btn--secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8125rem 1.5rem;
    background: var(--surface);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9375rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.btn--secondary:hover {
    background: var(--surface-muted);
    border-color: var(--accent);
}

.btn--back { margin-top: 1.25rem; width: 100%; }
.btn--resume { margin-top: 1.5rem; width: 100%; text-align: center; }

/* Hangar */
.hangar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.hangar-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.hangar-credits {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    background: var(--gold-soft);
    border: 1px solid #fed7aa;
    border-radius: 999px;
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 800;
    color: var(--gold);
    white-space: nowrap;
}

.hangar-credits i { color: var(--gold); }

.hangar-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 340px;
    overflow-y: auto;
}

.hangar-note {
    margin: 1rem 0 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-align: center;
}

/* Tech Deck */
.deck-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.deck-title {
    margin: 0 0 0.375rem;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.deck-subtitle {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.deck-columns {
    display: flex;
    gap: 1rem;
}

.deck-column {
    flex: 1;
    padding: 1.25rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.deck-column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.deck-column-title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.deck-counter {
    padding: 0.25rem 0.625rem;
    background: var(--accent-soft);
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
}

.deck-counter span {
    font-family: var(--font-display);
    font-weight: 800;
}

.deck-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    max-height: 360px;
    overflow-y: auto;
}

/* Game Over */
.gameover-card { max-width: 28rem; }

.gameover-icon {
    width: 4rem;
    height: 4rem;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--danger-soft);
    border-radius: 50%;
    color: var(--danger);
    font-size: 1.75rem;
}

.gameover-title {
    margin: 0 0 0.375rem;
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.gameover-subtitle {
    margin: 0 0 1.5rem;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.gameover-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.gameover-stat {
    padding: 1rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: left;
}

.gameover-stat__label {
    display: block;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.gameover-stat__value {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 800;
    color: var(--text-primary);
}

/* Tech Cards */
.tech-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.tech-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

.tech-card.is-disabled { opacity: 0.55; }
.tech-card.is-disabled:hover { box-shadow: none; }

.tech-card__info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.tech-card__icon {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.tech-card__name {
    font-weight: 700;
    font-size: 0.8125rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.tech-card__desc {
    margin: 0.125rem 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.35;
}

.icon-yellow { color: var(--warning); }
.icon-blue { color: var(--accent); }
.icon-purple { color: #7c3aed; }
.icon-cyan { color: #0891b2; }
.icon-emerald { color: var(--success); }
.icon-amber { color: var(--gold); }

.btn--install,
.btn--buy {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    font-weight: 700;
    font-size: 0.6875rem;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border: none;
    cursor: pointer;
}

.btn--install {
    background: var(--accent);
    color: #fff;
}

.btn--install:hover:not(:disabled) { background: var(--accent-hover); }
.btn--install:disabled { opacity: 0.35; cursor: not-allowed; }

.btn--buy {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--success);
    color: #fff;
}

.btn--buy:hover:not(:disabled) { background: #047857; }
.btn--buy:disabled { opacity: 0.35; cursor: not-allowed; }
.btn--buy .fa-coins { color: #fde68a; }

/* Animations */
@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.3); border-color: #fbbf24; }
    50% { box-shadow: 0 0 0 6px rgba(217, 119, 6, 0.15); border-color: #f59e0b; }
}

.pulse-warning { animation: pulseGlow 1.5s infinite; }

/* Responsive */
@media (max-width: 768px) {
    .start-card, .hangar-card, .deck-card, .gameover-card {
        padding: 1.75rem 1.25rem;
    }

    .game-logo__img {
        width: min(100%, 11rem);
    }

    .deck-columns { flex-direction: column; }
    .controls-grid { grid-template-columns: 1fr; }
    .gameover-stats { grid-template-columns: 1fr; }
    .hangar-header { flex-direction: column; align-items: stretch; }
}
