:root {
    --cream: #f6efe4;
    --paper: #fffaf3;
    --ink: #3a2a22;
    --muted: #7a5a3a;
    --gold: #c9a46a;
    --gold-deep: #8d6a3a;
    --coral: #e07a5f;
    --wood: #c4a06a;
    --slot: #ead9c4;
    --shadow: rgba(90, 50, 20, 0.18);
    --phone-w: 430px;
    --ui: system-ui, "Segoe UI", sans-serif;
    --serif: Georgia, "Times New Roman", serif;
}

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

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

body {
    font-family: var(--ui);
    color: var(--ink);
    background:
        radial-gradient(1200px 700px at 50% -8%, #fff6ea, transparent 55%),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 18px,
            rgba(201, 164, 106, 0.05) 18px,
            rgba(201, 164, 106, 0.05) 19px
        ),
        var(--cream);
}

#app {
    width: min(var(--phone-w), 100%);
    height: 100%;
    height: 100dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding: max(10px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
    position: relative;
    container-type: inline-size;
    --tile: clamp(36px, 12.2cqi, 54px);
}

.screen {
    display: none;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

.screen.active { display: flex; }

.hud-spacer { width: 44px; }

.menu-hero {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 12px 8px;
}

.mark {
    display: inline-block;
    margin-bottom: 16px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 11px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #7a5a3a;
    background: #f3e6d2;
    cursor: default;
}

.mark.dev-on {
    background: #e07a5f;
    color: #fff8ee;
}

.dev-panel {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px dashed rgba(201, 164, 106, 0.45);
}

.dev-label {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--coral);
    margin-bottom: 8px;
    text-align: center;
}

.dev-meta {
    font-size: 12px;
    letter-spacing: 0;
    text-transform: none;
    color: var(--muted);
    margin-bottom: 8px;
    text-align: center;
}

.menu-hero h1 {
    font-family: var(--serif);
    font-weight: 600;
    font-size: clamp(40px, 11cqi, 52px);
    letter-spacing: 0.02em;
}

.menu-lead {
    margin-top: 12px;
    max-width: 28em;
    font-size: 15px;
    line-height: 1.55;
    color: #6b5346;
}

.menu-progress {
    margin-top: 22px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.platform-chip {
    margin-top: 10px;
    font-size: 12px;
    font-weight: 700;
    color: var(--coral);
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px 4px 6px;
}

.secondary {
    appearance: none;
    border: 1px solid rgba(201, 164, 106, 0.55);
    cursor: pointer;
    width: 100%;
    height: 48px;
    border-radius: 16px;
    background: #fff8ee;
    color: var(--ink);
    font: 700 15px var(--ui);
}

.secondary:active { transform: translateY(1px); }

.howto {
    list-style: none;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    padding: 12px 4px 18px;
}

.howto li {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 12px;
    align-items: start;
    text-align: left;
}

.howto-n {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #fff8ee, #efd8b6);
    box-shadow: 0 3px 0 rgba(141, 106, 58, 0.25);
    font-weight: 800;
    color: var(--coral);
}

.howto strong { font-size: 16px; }
.howto p { margin-top: 4px; color: var(--muted); font-size: 14px; line-height: 1.4; }

#screen-howto .primary { margin-top: auto; }

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 10px 2px 8px;
    overflow: auto;
    overscroll-behavior: contain;
}

.gallery-card {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 0;
    text-align: center;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.gallery-card:disabled {
    cursor: default;
    opacity: 0.55;
}

.gallery-frame {
    background: linear-gradient(160deg, #f0ddb0, var(--gold) 50%, #8d6a3a);
    padding: 6px;
    border-radius: 12px;
    box-shadow: 0 6px 14px var(--shadow);
}

.gallery-mosaic {
    display: grid;
    gap: 2px;
    background: #23160f;
    padding: 3px;
    border-radius: 6px;
}

.gallery-cell {
    aspect-ratio: 1;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--c), var(--d));
}

.gallery-card.locked .gallery-cell { filter: grayscale(1) brightness(0.45); }
.gallery-card .gallery-title {
    margin-top: 6px;
    font-size: 11px;
    color: var(--muted);
    line-height: 1.2;
}


.hud {
    display: grid;
    grid-template-columns: 44px 1fr auto;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.hud-end {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn,
.booster {
    appearance: none;
    border: 0;
    cursor: pointer;
    font-family: inherit;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(180deg, #fff8ee, #f0dfc8);
    box-shadow: 0 2px 0 rgba(141, 106, 58, 0.25), 0 6px 14px var(--shadow);
    color: var(--muted);
    display: grid;
    place-items: center;
}

.icon-btn:active,
.booster:active { transform: translateY(1px); }

.icon-btn:disabled,
.booster:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}

.titles {
    text-align: center;
    min-width: 0;
}

.brand {
    font-family: var(--serif);
    font-size: 22px;
    letter-spacing: 0.02em;
    line-height: 1;
}

.level-name {
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
}

.coins {
    height: 36px;
    padding: 0 10px 0 8px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    background: #fff6ea;
    border: 1px solid rgba(201, 164, 106, 0.45);
    font-weight: 700;
    font-size: 14px;
}

.coin-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffe9a8, #e2b84c 45%, #b8862a);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.hint {
    text-align: center;
    font-size: 12px;
    color: #9a7a62;
    margin: 8px 0 6px;
    min-height: 16px;
}

.stage {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.frame-wrap {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 4px 8px 10px;
}

.frame {
    width: min(100%, 360px);
    background:
        linear-gradient(160deg, #f0ddb0, var(--gold) 38%, #a07840 78%, #7a5528);
    padding: 12px;
    border-radius: 20px;
    box-shadow:
        0 12px 28px var(--shadow),
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        inset 0 -2px 0 rgba(80, 40, 10, 0.28);
    transition: box-shadow 0.4s ease, transform 0.4s ease;
}

.frame.complete {
    box-shadow:
        0 0 0 3px rgba(255, 232, 170, 0.9),
        0 16px 40px rgba(201, 164, 106, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.frame-inner {
    background: #2c1d16;
    padding: 5px;
    border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgba(255, 220, 160, 0.18);
}

.mosaic {
    display: grid;
    gap: 3px;
    background: #23160f;
}

.cell {
    aspect-ratio: 1;
    border-radius: 6px;
    background: #1a100c;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.45);
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: "";
    position: absolute;
    inset: 22%;
    border-radius: 4px;
    background: linear-gradient(180deg, var(--c), var(--d));
    opacity: 0.55;
}

.cell.filled {
    background:
        radial-gradient(circle at 28% 24%, color-mix(in srgb, var(--c) 70%, white), var(--c) 46%, var(--d));
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.45),
        0 1px 0 rgba(0, 0, 0, 0.25);
}

.cell.filled::before { display: none; }

.cell.filled::after {
    content: "";
    position: absolute;
    inset: 10% 18% 55% 12%;
    border-radius: 40%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent);
    pointer-events: none;
}

.cell.pop { animation: pop 0.35s ease; }

@keyframes pop {
    0% { transform: scale(0.4); }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.board {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-height: 0;
    padding-bottom: 4px;
}

.stacks {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
    min-height: 170px;
}

.stack {
    width: var(--tile);
    min-height: 72px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 2px;
    cursor: pointer;
    border: 0;
    background: transparent;
    font: inherit;
}

.stack-empty {
    width: var(--tile);
    height: var(--tile);
    border-radius: 15px;
    border: 2px dashed rgba(201, 164, 106, 0.8);
    background: rgba(255, 248, 238, 0.45);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.stack.can-drop .stack-empty {
    border-color: var(--coral);
    background: color-mix(in srgb, var(--coral) 16%, #fff8ee);
    animation: pulse-drop 1.1s ease-in-out infinite;
}

.stack.can-drop .tile:last-child {
    box-shadow:
        0 0 0 3px color-mix(in srgb, var(--coral) 45%, transparent),
        0 3px 0 color-mix(in srgb, var(--d) 80%, #000),
        0 8px 14px var(--shadow),
        inset 0 2px 0 rgba(255, 255, 255, 0.5);
}

@keyframes pulse-drop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.stack .tile {
    margin-top: -28px;
    pointer-events: none;
}

.stack .tile:first-child { margin-top: 0; }

.stack:active .tile:last-child { transform: translateY(2px) scale(0.97); }

.draw-row {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 18px;
    width: 100%;
    padding-top: 8px;
}

.hand {
    appearance: none;
    border: 2px dashed rgba(201, 164, 106, 0.7);
    background: rgba(255, 248, 238, 0.5);
    cursor: pointer;
    width: var(--tile);
    height: var(--tile);
    border-radius: 15px;
    display: grid;
    place-items: center;
    padding: 0;
    flex: 0 0 auto;
}

.hand.has-tile {
    border-style: solid;
    border-color: transparent;
    background: transparent;
    animation: pulse-drop 1.1s ease-in-out infinite;
}

.hand.has-tile .tile {
    width: 100%;
    height: 100%;
}

.hand.shake { animation: shake 0.38s ease; }

.deck {
    appearance: none;
    border: 0;
    cursor: pointer;
    width: 72px;
    height: 76px;
    position: relative;
    background: transparent;
    flex: 0 0 auto;
}

.deck-card {
    position: absolute;
    inset: 8px 10px 12px;
    border-radius: 12px;
    background:
        repeating-linear-gradient(135deg, #d7b07a 0 8px, #c89a5e 8px 16px);
    box-shadow: 0 4px 0 #8d6a3a, 0 8px 16px var(--shadow);
    border: 2px solid #f3e2c0;
}

.deck-card:nth-child(1) { transform: translate(0, 0); }
.deck-card:nth-child(2) { transform: translate(3px, -3px); }
.deck-card:nth-child(3) { transform: translate(6px, -6px); }

.deck.empty .deck-card { background: #ead9c4; box-shadow: none; border-style: dashed; }

.deck-count {
    position: absolute;
    left: 50%;
    bottom: -2px;
    transform: translateX(-50%);
    min-width: 28px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--ink);
    color: #fff8ee;
    font-size: 11px;
    font-weight: 700;
}

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

.tile {
    width: var(--tile);
    height: var(--tile);
    border-radius: 15px;
    border: 0;
    background:
        radial-gradient(circle at 30% 24%, color-mix(in srgb, var(--c) 72%, white), var(--c) 44%, var(--d));
    box-shadow:
        0 3px 0 color-mix(in srgb, var(--d) 80%, #000),
        0 8px 14px var(--shadow),
        inset 0 2px 0 rgba(255, 255, 255, 0.5);
    position: relative;
    flex-shrink: 0;
}

.tile::after {
    content: "";
    position: absolute;
    top: 6px;
    left: 8px;
    right: 16px;
    height: 36%;
    border-radius: 12px 12px 40% 40%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), transparent);
    pointer-events: none;
}

.tile.ghost { opacity: 0; }

.boosters {
    display: flex;
    justify-content: center;
    gap: 18px;
    padding: 12px 8px 4px;
    flex: 0 0 auto;
}

.booster {
    width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
}

.booster-face {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #fff8ee, #efd8b6);
    box-shadow: 0 3px 0 rgba(141, 106, 58, 0.3), 0 8px 16px var(--shadow);
    font-size: 20px;
    position: relative;
}

.booster .uses {
    position: absolute;
    right: -2px;
    top: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--coral);
    color: white;
    font-size: 10px;
    font-weight: 800;
    display: grid;
    place-items: center;
}

.overlay {
    position: absolute;
    inset: 0;
    z-index: 8;
    background: rgba(42, 24, 16, 0.45);
    display: grid;
    align-items: end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    padding: 16px;
}

.overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.sheet {
    background: var(--paper);
    border-radius: 28px 28px 22px 22px;
    padding: 28px 22px 22px;
    text-align: center;
    box-shadow: 0 -12px 40px rgba(42, 24, 16, 0.25);
    transform: translateY(24px);
    transition: transform 0.35s ease;
}

.overlay.show .sheet { transform: translateY(0); }

.ad-overlay {
    position: fixed;
    z-index: 100;
    align-items: center;
    background: rgba(42, 24, 16, 0.72);
}

.ad-kicker {
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--coral);
    font-weight: 800;
}

.ad-bar {
    margin-top: 18px;
    height: 8px;
    border-radius: 999px;
    background: #ead9c4;
    overflow: hidden;
}

.ad-bar-fill {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #f0a07f, var(--coral));
}

.ad-overlay.show .ad-bar-fill {
    animation: ad-fill 1.6s linear forwards;
}

@keyframes ad-fill {
    from { width: 0; }
    to { width: 100%; }
}

.booster.booster-ad .uses {
    background: #4a8fbd;
}

.stars {
    letter-spacing: 8px;
    font-size: 28px;
    color: #e2b84c;
    text-shadow: 0 2px 0 #b8862a;
}

.sheet h2 {
    font-family: var(--serif);
    font-size: 28px;
    margin: 10px 0 6px;
}

.sheet p { color: var(--muted); font-size: 15px; }

.reward {
    margin: 14px 0 18px;
    font-weight: 800;
    color: #b8862a;
}

.primary {
    appearance: none;
    border: 0;
    cursor: pointer;
    width: 100%;
    height: 52px;
    border-radius: 16px;
    background: linear-gradient(180deg, #f0a07f, var(--coral));
    color: white;
    font: 700 16px var(--ui);
    box-shadow: 0 4px 0 #b85a42;
}

.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #b85a42; }

.ghost-btn {
    margin-top: 10px;
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: 600 14px var(--ui);
    cursor: pointer;
}

.fx {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 20;
}

.fx-tile {
    position: fixed;
    border-radius: 15px;
    z-index: 21;
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s ease;
}

.toast {
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, 8px);
    background: rgba(42, 24, 16, 0.88);
    color: #fff8ee;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    white-space: nowrap;
}

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

@media (min-width: 520px) {
    body { display: grid; place-items: center; }
    #app {
        height: min(900px, 100dvh);
        border-radius: 32px;
        background: color-mix(in srgb, var(--cream) 70%, white);
        box-shadow: 0 24px 60px var(--shadow);
        border: 1px solid rgba(201, 164, 106, 0.4);
        overflow: hidden;
    }
}
