:root {
    --bg: #0d1117;
    --bg-alt: #10141c;
    --surface: #161b26;
    --surface-hover: #1d2433;
    --fg: #f5f7fb;
    --muted: #8b94a7;
    --border: #262d3d;
    --accent: #4fd1c5;
    --accent-fg: #06251f;
    --accent-strong: #38bdf3;
    --radius: 12px;
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

    --shield-fill: #2a3550;
    --shield-stroke: #f5c344;
    --shield-grad-top: #3a6ff0;
    --shield-grad-bottom: #1c2a5e;
    --shield-inner-stroke: #cfe0ff;
    --star-fill: #ffd54f;
    --star-stroke: #b8860b;

    --shield-rim-hi: #f2f4f6;
    --shield-rim-mid: #c7ccd3;
    --shield-rim-lo: #7d838c;
    --shield-red: #b1191d;
    --shield-white: #f5f6f8;
    --shield-blue: #1e3a8a;
    --shield-star: #f5f6f8;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    /* Comic-book backdrop: subtle speed-lines radiating from center, a fine
       halftone dot grid, faint red/blue accent glows, all sitting on top of
       the original dark navy vignette. Pure CSS gradients — no image assets —
       kept low-opacity so it stays behind UI panels without adding noise. */
    background-color: var(--bg);
    background-image:
        repeating-conic-gradient(
            from 0deg at 50% 42%,
            rgba(245, 246, 248, 0.05) 0deg 0.6deg,
            transparent 0.6deg 7deg
        ),
        radial-gradient(circle, rgba(245, 246, 248, 0.07) 1px, transparent 1.4px),
        radial-gradient(circle at 50% 45%, rgba(177, 25, 29, 0.16), transparent 42%),
        radial-gradient(circle at 50% 45%, rgba(30, 58, 138, 0.18), transparent 60%),
        radial-gradient(circle at 50% 0%, var(--bg-alt), var(--bg) 60%);
    background-size: auto, 8px 8px, auto, auto, auto;
    background-position: center, 0 0, center, center, center;
    background-repeat: no-repeat, repeat, no-repeat, no-repeat, no-repeat;
    background-attachment: fixed, fixed, fixed, fixed, fixed;
    color: var(--fg);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.9rem 1.5rem;
    background: rgba(15, 20, 30, 0.85);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand-icon {
    width: 34px;
    height: 38px;
    flex-shrink: 0;
}

.brand h1 {
    font-size: 1.25rem;
    margin: 0;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.stats {
    display: flex;
    gap: 1.75rem;
    margin-left: auto;
    align-items: baseline;
}

.stat-block {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.stat-block.secondary .stat-value {
    font-size: 1.2rem;
    color: var(--accent-strong);
}

.stat-label {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.reset-btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.9rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.reset-btn:hover {
    color: #ff6b6b;
    border-color: #ff6b6b;
}

/* ---------- Orbiting Active Generators ---------- */
/* Icons for owned generators orbit around the shield's rim. They must never
   intercept pointer/click events -- only the shield button itself is
   clickable -- so the whole layer and every descendant is pointer-events:none. */
.orbit-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
    --orbit-radius: 150px;
}

.gen-orbit {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    animation-name: orbitSpin;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-duration: var(--orbit-duration, 16s);
    will-change: transform;
}

.gen-orbit-inner {
    position: absolute;
    top: 0;
    left: 0;
    transform: translate(var(--orbit-radius, 150px), 0);
    pointer-events: none;
}

.gen-orbit-icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--accent);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    animation-name: orbitCounterSpin;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    animation-duration: var(--orbit-duration, 16s);
    will-change: transform;
}

.gen-orbit-icon svg {
    width: 17px;
    height: 17px;
    pointer-events: none;
}

@keyframes orbitSpin {
    from { transform: rotate(var(--orbit-offset, 0deg)); }
    to { transform: rotate(calc(var(--orbit-offset, 0deg) + 360deg)); }
}

@keyframes orbitCounterSpin {
    from { transform: translate(-50%, -50%) rotate(calc(-1 * var(--orbit-offset, 0deg))); }
    to { transform: translate(-50%, -50%) rotate(calc(-1 * var(--orbit-offset, 0deg) - 360deg)); }
}

@media (max-width: 480px) {
    .gen-orbit-icon {
        width: 24px;
        height: 24px;
    }

    .gen-orbit-icon svg {
        width: 14px;
        height: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gen-orbit,
    .gen-orbit-icon {
        animation: none;
        transform: rotate(var(--orbit-offset, 0deg));
    }
}

/* ---------- Layout ---------- */
.layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.clicker-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2rem 1rem;
    width: 100%;
}

.click-wrap {
    position: relative;
    width: min(340px, 70vw);
    aspect-ratio: 200 / 220;
    display: grid;
    place-items: center;
}

.shield-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
    display: block;
    transition: transform 0.08s ease;
    filter: drop-shadow(0 10px 30px rgba(120, 130, 145, 0.5));
}

.shield-btn:active {
    transform: scale(0.94);
}

.shield-btn.pulse {
    animation: pulse 0.22s ease;
}

@keyframes pulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.shield-svg {
    width: 100%;
    height: 100%;
}

.hint {
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0;
}

.click-power-display {
    color: var(--accent-strong);
    font-weight: 700;
    font-size: 0.95rem;
}

.floater {
    position: absolute;
    pointer-events: none;
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--star-fill);
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    animation: floatUp 0.9s ease-out forwards;
    z-index: 20;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translate(-50%, 0);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -70px);
    }
}

/* ---------- Falling emblem click "pop" ---------- */
.emblem-pop {
    position: absolute;
    width: 34px;
    height: 34px;
    margin-left: -17px;
    margin-top: -17px;
    pointer-events: none;
    z-index: 21;
    opacity: 0;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.5));
    animation: emblemPop 1.15s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    will-change: transform, opacity;
}

.emblem-pop svg {
    width: 100%;
    height: 100%;
    display: block;
}

@keyframes emblemPop {
    0% {
        opacity: 0;
        transform: translate(0, 0) rotate(0deg) scale(0.4);
    }
    12% {
        opacity: 1;
        transform: translate(calc(var(--pop-drift, 0px) * 0.15), -34px) rotate(var(--pop-rise-rot, 0deg)) scale(1);
    }
    30% {
        opacity: 1;
        transform: translate(calc(var(--pop-drift, 0px) * 0.4), -20px) rotate(calc(var(--pop-rise-rot, 0deg) * 1.4)) scale(0.96);
    }
    100% {
        opacity: 0;
        transform: translate(var(--pop-drift, 0px), 260px) rotate(var(--pop-rot, 260deg)) scale(0.8);
    }
}

@media (prefers-reduced-motion: reduce) {
    .emblem-pop {
        animation-duration: 0.6s;
    }
}

/* ---------- Shop ---------- */
.shop-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    max-height: 60vh;
    margin: 0 auto;
}

.shop-panel h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.shop-tabs {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.6rem;
}

.shop-tab {
    flex: 1;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 0.45rem 0.6rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.shop-tab:hover {
    color: var(--fg);
    border-color: var(--accent);
}

.shop-tab.active {
    background: var(--accent);
    color: var(--accent-fg);
    border-color: var(--accent);
}

.shop-scroll {
    overflow-y: auto;
    padding-right: 0.25rem;
}

.shop-section h3 {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin: 1rem 0 0.5rem;
}

.shop-section:first-child h3 {
    margin-top: 0;
}

.upgrade-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.upgrade-card {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    text-align: left;
    color: var(--fg);
    font-family: inherit;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.upgrade-card:hover:not(:disabled) {
    background: var(--surface-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.upgrade-card:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.upgrade-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.upgrade-name {
    font-weight: 700;
    font-size: 0.92rem;
}

.upgrade-owned {
    font-size: 0.75rem;
    color: var(--accent-strong);
    background: rgba(79, 209, 197, 0.12);
    padding: 0.05rem 0.45rem;
    border-radius: 999px;
}

.upgrade-desc {
    font-size: 0.75rem;
    color: var(--muted);
}

.upgrade-cost {
    font-size: 0.82rem;
    color: var(--star-fill);
    font-weight: 600;
}

/* ---------- Shield skins ---------- */
.skin-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.skin-swatch {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.skin-swatch-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Cap's original kite-shaped shield swatch: the circular clip on
   .skin-swatch is meant for round shields, so relax it to let the
   triangular/kite silhouette read correctly instead of being cropped
   into a circle. */
.skin-swatch-kite {
    border-radius: 8px;
    background: transparent;
    box-shadow: none;
}

.skin-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex: 1;
    min-width: 0;
}

.skin-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.skin-name {
    font-weight: 700;
    font-size: 0.92rem;
}

.skin-status {
    font-size: 0.75rem;
    color: var(--muted);
}

.skin-action {
    flex-shrink: 0;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-alt);
    color: var(--fg);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.skin-action:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.skin-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.skin-action.equip {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-fg);
}

.skin-action.equipped {
    background: transparent;
    border-color: var(--accent-strong);
    color: var(--accent-strong);
    cursor: default;
}

/* ---------- Toast notification ---------- */
.app-toast {
    position: fixed;
    left: 50%;
    bottom: 2rem;
    transform: translate(-50%, 20px);
    background: var(--surface);
    border: 1px solid var(--accent);
    color: var(--fg);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

.app-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .shop-panel {
        max-height: none;
        max-width: 100%;
    }

    .stats {
        margin-left: 0;
        gap: 1.25rem;
    }

    .topbar {
        justify-content: space-between;
    }
}

@media (max-width: 480px) {
    .brand h1 {
        font-size: 1.05rem;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .stat-block.secondary .stat-value {
        font-size: 1rem;
    }
}
