:root {
    color-scheme: light;
    --ink: #2a2340;
    --muted: #6d6882;
    --paper: rgba(255, 255, 255, 0.92);
    --line: rgba(42, 35, 64, 0.14);
    --blue: #76c7ff;
    --mint: #7ee0b3;
    --yellow: #ffd166;
    --coral: #ff6f61;
    --shadow: 0 18px 44px rgba(54, 68, 92, 0.24);
    --desktop-ad-height: min(72vh, 520px);
    --desktop-game-max-width: 1360px;
    --mobile-banner-height: 68px;
    --mobile-landscape-ad-width: 118px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: "Trebuchet MS", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
    background: #aee2ff;
    color: var(--ink);
}

button {
    font: inherit;
}

.experience-shell {
    width: 100vw;
    height: 100svh;
    min-height: 480px;
    display: grid;
    grid-template-columns: max-content minmax(0, var(--desktop-game-max-width)) max-content;
    justify-content: center;
    align-items: stretch;
    gap: clamp(6px, 0.8vw, 14px);
    padding: clamp(8px, 1.2vh, 16px) clamp(8px, 1vw, 16px);
    background:
        linear-gradient(180deg, rgba(174, 226, 255, 0.95), rgba(147, 217, 126, 0.92)),
        #aee2ff;
}

.ad-slot {
    color: inherit;
    text-decoration: none;
}

.ad-slot[hidden] {
    display: none !important;
}

.ad-slot-desktop {
    align-self: center;
    display: flex;
    width: min(126px, calc(var(--desktop-ad-height) * 126 / 520));
    height: var(--desktop-ad-height);
    max-height: calc(100svh - 36px);
}

.ad-slot-mobile {
    display: none;
}

.ad-image {
    display: block;
    width: 100%;
    height: auto;
}

.ad-image-vertical {
    width: 100%;
    height: 100%;
    aspect-ratio: 126 / 520;
    object-fit: contain;
}

.ad-image-horizontal {
    width: min(320px, calc(100vw - 16px));
    aspect-ratio: 32 / 5;
    object-fit: cover;
}

.game-shell {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 18px 50px rgba(54, 68, 92, 0.22);
    background:
        radial-gradient(circle at 16% 18%, rgba(255, 255, 255, 0.9) 0 4%, transparent 4.5%),
        radial-gradient(circle at 83% 13%, rgba(255, 255, 255, 0.86) 0 5%, transparent 5.5%),
        linear-gradient(180deg, #9fdbff 0%, #dff6ff 56%, #98d970 56.5%, #66b85e 100%);
}

#gameCanvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

.screen {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    pointer-events: none;
    opacity: 0;
    transform: scale(1.015);
    transition: opacity 220ms ease, transform 220ms ease;
}

.screen.is-active {
    pointer-events: auto;
    opacity: 1;
    transform: scale(1);
}

.screen-game {
    display: block;
    padding: 0;
}

.screen-game.is-active {
    pointer-events: none;
}

.panel {
    width: min(92vw, 560px);
    border: 3px solid rgba(42, 35, 64, 0.12);
    border-radius: 8px;
    background: var(--paper);
    box-shadow: var(--shadow);
    text-align: center;
    backdrop-filter: blur(12px);
}

.start-panel,
.over-panel {
    padding: clamp(22px, 4vw, 36px);
}

.eyebrow {
    margin: 0 0 8px;
    color: #2a8e82;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.08;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(2.15rem, 5.4vw, 4rem);
    color: #ff6b35;
    text-shadow: 0 4px 0 #ffe083, 0 8px 20px rgba(98, 57, 20, 0.18);
    white-space: nowrap;
}

h2 {
    font-size: clamp(1.7rem, 4.6vw, 2.85rem);
    color: #e85543;
    white-space: nowrap;
}

.lead {
    width: min(100%, 430px);
    margin: 18px auto 22px;
    color: var(--muted);
    font-size: clamp(1rem, 2.6vw, 1.15rem);
    line-height: 1.55;
}

.how-to-play {
    display: grid;
    gap: 10px;
    margin: 0 auto 24px;
    text-align: left;
}

.how-to-play div,
.result-grid div,
.hud-card {
    border: 2px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.how-to-play div {
    display: grid;
    grid-template-columns: 84px 1fr;
    gap: 10px;
    align-items: center;
    padding: 12px 14px;
}

.how-to-play strong {
    color: #277f75;
}

.how-to-play span {
    color: #514c67;
    line-height: 1.35;
}

.primary-button {
    width: min(100%, 260px);
    min-height: 54px;
    border: 0;
    border-radius: 8px;
    background: linear-gradient(180deg, #ffcf5c 0%, #ff9d3d 100%);
    color: #422911;
    font-size: 1.2rem;
    font-weight: 900;
    box-shadow: 0 6px 0 #c96c20, 0 14px 24px rgba(139, 69, 19, 0.22);
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.primary-button:hover {
    filter: brightness(1.04);
    transform: translateY(-2px);
    box-shadow: 0 8px 0 #c96c20, 0 16px 26px rgba(139, 69, 19, 0.22);
}

.primary-button:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 #c96c20, 0 8px 18px rgba(139, 69, 19, 0.18);
}

.hud {
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    pointer-events: none;
}

.hud-card {
    min-width: 0;
    padding: 10px 12px;
    box-shadow: 0 8px 20px rgba(54, 68, 92, 0.12);
    text-align: center;
}

.hud-card span,
.result-grid span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: clamp(0.72rem, 2vw, 0.86rem);
    font-weight: 800;
}

.hud-card strong,
.result-grid strong {
    display: block;
    color: var(--ink);
    font-size: clamp(1.1rem, 3.4vw, 1.55rem);
    line-height: 1.1;
}

.level-notice {
    position: absolute;
    top: 18%;
    left: 50%;
    z-index: 4;
    min-width: 180px;
    padding: 12px 18px;
    border: 3px solid rgba(42, 35, 64, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: #e85543;
    font-size: clamp(1.05rem, 4vw, 1.55rem);
    font-weight: 900;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -8px) scale(0.96);
}

.level-notice.is-visible {
    animation: noticePop 1100ms ease forwards;
}

.damage-flash {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(255, 35, 50, 0.24);
    opacity: 0;
    pointer-events: none;
}

.damage-flash.is-active {
    animation: flashHit 280ms ease;
}

.game-shell.is-shaking {
    animation: screenShake 300ms ease;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 24px 0;
}

.result-grid div {
    padding: 14px 12px;
}

.screen-over.is-active .over-panel {
    animation: overPop 340ms cubic-bezier(0.18, 0.9, 0.24, 1.15);
}

@keyframes noticePop {
    0% {
        opacity: 0;
        transform: translate(-50%, 8px) scale(0.95);
    }
    18%,
    72% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -12px) scale(0.98);
    }
}

@keyframes flashHit {
    0%,
    100% {
        opacity: 0;
    }
    28%,
    65% {
        opacity: 1;
    }
}

@keyframes screenShake {
    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }
    20% {
        transform: translate3d(-7px, 3px, 0);
    }
    40% {
        transform: translate3d(7px, -2px, 0);
    }
    60% {
        transform: translate3d(-5px, -3px, 0);
    }
    80% {
        transform: translate3d(5px, 2px, 0);
    }
}

@keyframes overPop {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 620px) {
    .game-shell {
        min-height: 430px;
    }

    h1 {
        font-size: clamp(1.72rem, 9vw, 2.7rem);
    }

    h2 {
        font-size: clamp(1.45rem, 7.4vw, 2.35rem);
    }

    .panel {
        width: min(94vw, 500px);
    }

    .start-panel,
    .over-panel {
        padding: 20px 16px;
    }

    .how-to-play div {
        grid-template-columns: 72px 1fr;
        padding: 10px 12px;
    }

    .hud {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .hud-card {
        padding: 8px 10px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {
    .screen {
        align-items: start;
        overflow-y: auto;
    }

    .panel {
        margin: 8px 0;
        width: min(760px, 94vw);
    }

    .start-panel,
    .over-panel {
        padding: 16px;
    }

    h1 {
        font-size: clamp(1.8rem, 8vw, 3rem);
    }

    h2 {
        font-size: clamp(1.35rem, 6vw, 2.15rem);
    }

    .lead {
        margin: 10px auto 12px;
    }

    .how-to-play,
    .result-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 14px;
    }

    .how-to-play div {
        display: block;
    }

    .how-to-play strong {
        display: block;
        margin-bottom: 4px;
    }

    .result-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .primary-button {
        min-height: 46px;
    }
}

@media (max-width: 900px) {
    html,
    body {
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
    }

    body {
        position: fixed;
        inset: 0;
        width: 100%;
    }

    .experience-shell {
        display: block;
        width: 100vw;
        height: 100svh;
        min-height: 0;
        padding: 0;
        background: #aee2ff;
    }

    .ad-slot-desktop {
        display: none !important;
    }

    .ad-slot-mobile {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        display: flex;
        justify-content: stretch;
        width: 100vw;
        height: max(var(--mobile-banner-height), calc(var(--mobile-banner-height) + env(safe-area-inset-bottom)));
        padding-bottom: env(safe-area-inset-bottom);
        background: #0f1624;
        overflow: hidden;
    }

    .ad-image-horizontal {
        width: 100%;
        height: 100%;
        object-fit: fill;
    }

    .game-shell {
        position: fixed;
        inset: 0 0 var(--mobile-banner-height) 0;
        width: 100vw;
        height: auto;
        min-height: 0;
        border-radius: 0;
        box-shadow: none;
    }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 560px) {
    .ad-slot-mobile {
        display: none !important;
    }

    .ad-slot-left {
        display: none !important;
    }

    .ad-slot-right {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        display: flex !important;
        width: var(--mobile-landscape-ad-width);
        height: 100svh;
        max-height: none;
        padding: 4px;
        background: #0f1624;
    }

    .ad-image-vertical {
        width: 100%;
        height: 100%;
        max-height: none;
        object-fit: contain;
    }

    .game-shell {
        inset: 0 var(--mobile-landscape-ad-width) 0 0;
        width: auto;
        height: 100svh;
    }
}
