:root {
    --sky: #7dd3fc;
    --ink: #0f172a;
    --glass: rgba(15, 23, 42, 0.82);
    --glass-border: rgba(255, 255, 255, 0.16);
    --amber: #fbbf24;
    --emerald: #4ade80;
    --sky-text: #bae6fd;
    --text: #f8fafc;
    --muted: #94a3b8;
    --font: "Fredoka", "Segoe UI", system-ui, sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --hud-gap: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    font-family: var(--font);
    background: var(--sky);
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    overscroll-behavior: none;
    position: fixed;
    inset: 0;
}

canvas {
    display: block;
    width: 100vw;
    height: 100dvh;
    touch-action: none;
}

#canvasContainer {
    width: 100%;
    height: 100%;
}

#fxLayer,
#tapRipple {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 25;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(20px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
    background:
        radial-gradient(circle at 18% 18%, rgba(251, 191, 36, 0.32), transparent 42%),
        radial-gradient(circle at 86% 78%, rgba(56, 189, 248, 0.32), transparent 46%),
        rgba(15, 23, 42, 0.42);
}

.overlay-dim { background: rgba(15, 23, 42, 0.72); }

.overlay[hidden],
#gameHud[hidden],
.cash-banner[hidden],
#missionRow[hidden],
#islandFlash[hidden],
#winScreen[hidden] {
    display: none !important;
}

.start-card,
.modal-card {
    width: min(400px, 100%);
    max-height: 85dvh;
    overflow-y: auto;
    touch-action: pan-y;
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.94), rgba(15, 23, 42, 0.94));
    border: 2px solid rgba(250, 204, 21, 0.35);
    border-radius: 28px;
    padding: 22px 18px 18px;
    text-align: center;
    box-shadow: 0 18px 0 rgba(0, 0, 0, 0.28), 0 30px 50px rgba(0, 0, 0, 0.35);
}

.start-badge {
    display: inline-block;
    background: #f59e0b;
    color: #431407;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    padding: 4px 10px;
    border-radius: 999px;
}

.start-emoji {
    font-size: 72px;
    line-height: 1;
    margin: 10px 0 4px;
    animation: bob 1.8s ease-in-out infinite;
    filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.18));
}

@keyframes bob {
    0%, 100% { transform: translateY(0) rotate(-8deg) scale(1); }
    50% { transform: translateY(-12px) rotate(8deg) scale(1.06); }
}

h1, h2 {
    margin: 4px 0;
    letter-spacing: -0.03em;
}

h1 { font-size: clamp(1.7rem, 7vw, 2.2rem); }
h2 { font-size: 1.4rem; }

.start-sub {
    margin: 0 0 18px;
    color: var(--sky-text);
    font-weight: 600;
}

.start-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    font-family: inherit;
    font-weight: 700;
    font-size: 1.05rem;
    border: 0;
    border-radius: 18px;
    padding: 14px 16px;
    min-height: 52px;
    cursor: pointer;
    color: white;
    pointer-events: auto;
    touch-action: manipulation;
}

.btn-play {
    font-size: 1.25rem;
    letter-spacing: 0.08em;
    animation: play-pulse 1.4s ease-in-out infinite;
}

@keyframes play-pulse {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.btn:active,
.icon-btn:active,
.shop-card:active {
    transform: translateY(4px) scale(0.97);
    box-shadow: 0 2px 0 #0003 !important;
}

.btn-primary {
    background: linear-gradient(180deg, #fbbf24, #d97706);
    box-shadow: 0 7px 0 #92400e;
    color: #431407;
}

.btn-secondary {
    background: linear-gradient(180deg, #38bdf8, #0284c7);
    box-shadow: 0 7px 0 #075985;
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
}

.help-list {
    text-align: left;
    color: #e2e8f0;
    line-height: 1.5;
    padding-left: 1.15rem;
    font-size: 0.95rem;
}

.help-tip {
    color: var(--muted);
    font-size: 0.82rem;
}

#gameHud {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

#gameHud button { pointer-events: auto; touch-action: manipulation; }

.hud-top {
    display: flex;
    align-items: stretch;
    gap: 6px;
    padding: calc(8px + var(--safe-top)) 8px 0;
}

.money-bar {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, #1e293b, #0f172a);
    border: 2px solid #f59e0b;
    border-radius: 18px;
    padding: 6px 10px;
    box-shadow: 0 5px 0 #78350f;
}

.money-bar.pop { animation: money-pop 0.35s ease; }

@keyframes money-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.coin-spin {
    font-size: 36px;
    animation: spin-y 2.4s linear infinite;
}

@keyframes spin-y {
    0% { transform: rotateY(0); }
    100% { transform: rotateY(360deg); }
}

.money-copy { min-width: 0; }
#moneyDisplay {
    display: block;
    font-size: clamp(2.05rem, 5.6vw, 2.35rem);
    font-weight: 700;
    color: #fde68a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.onion-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    background: var(--glass);
    border: 1px solid rgba(74, 222, 128, 0.35);
    border-radius: 16px;
    padding: 4px 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--emerald);
}

#currentOnionBadge { font-size: 35px; line-height: 1; }
#currentOnionName {
    max-width: 58px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-tools {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 14px;
    color: white;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
}

.mission-row {
    padding: 8px 10px 0;
    display: flex;
    justify-content: center;
}

.mission-pill {
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: min(92vw, 420px);
    background: rgba(15, 23, 42, 0.78);
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 999px;
    padding: 6px 12px 6px 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--sky-text);
}

.mission-tag {
    background: #38bdf8;
    color: #0f172a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    padding: 3px 7px;
    border-radius: 999px;
    flex-shrink: 0;
}

.toast-container {
    position: absolute;
    top: calc(108px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    z-index: 20;
    width: min(90vw, 340px);
}

.toast {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid #fbbf24;
    color: white;
    font-weight: 700;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 999px;
    text-align: center;
    animation: toast-in 0.28s cubic-bezier(0.2, 1.4, 0.3, 1);
}

@keyframes toast-in {
    from { opacity: 0; transform: scale(0.7) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.cash-banner {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    font-weight: 800;
    font-size: clamp(1.5rem, 7vw, 2.2rem);
    color: #4ade80;
    pointer-events: none;
    z-index: 22;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
    animation: cash-burst 1s ease forwards;
}

@keyframes cash-burst {
    0% { transform: translate(-50%, -40%) scale(0.5); opacity: 0; }
    25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
    100% { transform: translate(-50%, -90%) scale(1); opacity: 0; }
}

.mid-stats {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(168px + var(--safe-bottom));
    display: flex;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
}

.stat-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 64px;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
}

.stat-chip b {
    font-size: 16px;
    color: white;
}

.shop-dock {
    margin-top: auto;
    pointer-events: auto;
    padding: 0 8px calc(8px + var(--safe-bottom));
}

.truck-meter {
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid var(--glass-border);
    border-radius: 14px 14px 0 0;
    padding: 6px 10px 8px;
}

.truck-meter-top {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 700;
    color: #7dd3fc;
    margin-bottom: 4px;
}

.truck-track {
    height: 10px;
    background: #1e293b;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid #334155;
}

.truck-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #38bdf8, #facc15);
    border-radius: 999px;
    transition: width 0.25s ease;
    box-shadow: 0 0 10px #facc15;
}

.shop-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    background: rgba(15, 23, 42, 0.92);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: 0;
    border-radius: 0 0 18px 18px;
    padding: 8px;
}

.shop-card {
    position: relative;
    overflow: hidden;
    font-family: inherit;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 14px;
    min-height: 118px;
    padding: 6px 4px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 1px;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.28);
}

.shop-card.can-buy {
    animation: can-buy 1.1s ease-in-out infinite;
    filter: saturate(1.15);
}

.shop-card.can-buy .shop-cta {
    background: #22c55e;
    color: #052e16;
}

.shop-card.locked {
    filter: grayscale(0.35) brightness(0.82);
}

.shop-card.is-max .shop-cta { background: #64748b; color: #e2e8f0; }
.shop-card.shake { animation: btn-shake 0.35s ease; }

@keyframes can-buy {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

@keyframes btn-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.shop-card::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.22), transparent 70%);
    transform: translateX(-120%);
}

.shop-card.can-buy::after { animation: shine 1.8s ease-in-out infinite; }

@keyframes shine {
    0% { transform: translateX(-120%); }
    40%, 100% { transform: translateX(120%); }
}

.shop-icon { font-size: 22px; line-height: 1; }
.shop-name {
    font-size: 10px;
    font-weight: 700;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.shop-lvl {
    font-size: 9px;
    color: #e2e8f0;
    opacity: 0.9;
}
.shop-effect {
    font-size: 8px;
    font-weight: 600;
    color: #bae6fd;
    line-height: 1.15;
    max-width: 100%;
    padding: 0 2px;
}
.shop-price {
    margin-top: auto;
    font-size: 11px;
    font-weight: 800;
    color: #fde68a;
}
.shop-cta {
    margin-top: 3px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.06em;
    background: #334155;
    border-radius: 999px;
    padding: 2px 8px;
}

.shop-tier { background: linear-gradient(180deg, #7e22ce, #3b0764); }
.shop-farm { background: linear-gradient(180deg, #059669, #064e3b); }
.shop-peel { background: linear-gradient(180deg, #ea580c, #7c2d12); }
.shop-truck { background: linear-gradient(180deg, #0369a1, #0c4a6e); }

.island-flash {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.72);
    pointer-events: none;
    animation: island-flash-in 1.35s ease forwards;
}

.island-flash-copy {
    text-align: center;
}

.island-flash-icon {
    font-size: 64px;
    line-height: 1;
    filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.25));
}

#islandFlashName {
    margin: 8px 0 0;
    color: #fde68a;
}

#islandFlashSub {
    margin: 4px 0 0;
    color: var(--sky-text);
    font-weight: 600;
}

@keyframes island-flash-in {
    0% { opacity: 0; }
    18% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

.world-label {
    position: absolute;
    font-weight: 700;
    font-size: 10px;
    pointer-events: none;
    text-align: center;
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid #38bdf8;
    color: var(--amber);
    padding: 4px 8px;
    border-radius: 12px;
    z-index: 12;
}

.world-label .label-title {
    color: var(--sky-text);
    font-size: 9px;
    font-weight: 600;
}

.tap-label {
    position: absolute;
    pointer-events: none;
    z-index: 12;
    background: #facc15;
    color: #431407;
    font-weight: 800;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 999px;
    box-shadow: 0 3px 0 #a16207;
    animation: tap-bob 0.7s ease-in-out infinite;
}

@keyframes tap-bob {
    0%, 100% { transform: translate(-50%, -120%) scale(1); }
    50% { transform: translate(-50%, -150%) scale(1.08); }
}

.float-text {
    position: absolute;
    font-weight: 800;
    font-size: 16px;
    pointer-events: none;
    z-index: 18;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.fly-coin {
    position: fixed;
    z-index: 30;
    font-size: 22px;
    pointer-events: none;
    transition: transform 0.7s cubic-bezier(0.15, 0.85, 0.25, 1), opacity 0.7s ease;
}

.confetti {
    position: fixed;
    width: 8px;
    height: 12px;
    pointer-events: none;
    z-index: 30;
    animation: confetti-fall 0.9s ease-in forwards;
}

@keyframes confetti-fall {
    to { transform: translateY(120px) rotate(220deg); opacity: 0; }
}

.ripple {
    position: fixed;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    border-radius: 50%;
    border: 3px solid rgba(250, 204, 21, 0.9);
    pointer-events: none;
    animation: ripple 0.4s ease-out forwards;
    z-index: 26;
}

@keyframes ripple {
    to { transform: scale(3.4); opacity: 0; }
}

body.shake .hud-top,
body.shake .shop-dock {
    animation: hud-shake 0.35s ease;
}

@keyframes hud-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(3px); }
}

@media (max-width: 360px) {
    .shop-card { min-height: 96px; }
    .onion-pill { display: none; }
}

@media (min-width: 640px) {
    .hud-top, .mission-row, .shop-dock { max-width: 520px; margin-left: auto; margin-right: auto; width: 100%; }
    .mid-stats { bottom: calc(176px + var(--safe-bottom)); }
    .shop-card { min-height: 118px; }
    .shop-icon { font-size: 26px; }
}

@media (orientation: landscape) and (max-height: 500px) {
    .start-emoji { font-size: 42px; }
    .shop-card { min-height: 72px; padding: 4px; }
    .shop-name, .shop-lvl, .shop-effect { display: none; }
    .mid-stats { display: none; }
    .mission-row { display: none; }
    .hud-top { padding-top: 4px; }
}
