:root {
    --cream: #f4ecdd;
    --cream-deep: #efe4cf;
    --card: #fffaf0;
    --ink: #2b2118;
    --accent: #c2451e;
    --muted: #5a4a3a;
    --tech: #8a7a64;
    --peach: #e8935c;
}

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

html, body {
    height: 100%;
}

body {
    background: var(--cream);
    color: var(--ink);
    font-family: 'Inter', -apple-system, 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overscroll-behavior: none;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.1rem;
    border-bottom: 2px solid var(--ink);
    background: var(--cream);
}

.topbar .back {
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9rem;
}

.topbar .back:hover { text-decoration: underline; }

.topbar .title {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    letter-spacing: 0.18em;
    font-size: 0.95rem;
}

.machine {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.2rem;
    padding: 1rem;
    min-height: 0;
}

/* --- HUD --- */

.hud {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    width: 10.5rem;
}

.price-tag {
    background: var(--card);
    border: 2px dashed var(--ink);
    box-shadow: 4px 4px 0 var(--ink);
    padding: 0.6rem 0.8rem;
    transform: rotate(-2deg);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.tag-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.tag-value {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    font-size: 1.55rem;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.hud-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--cream-deep);
    padding-bottom: 0.25rem;
}

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

.hud-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.hud-value.balls { color: var(--accent); letter-spacing: 0.2em; }

.combo {
    align-self: flex-start;
    background: var(--ink);
    color: var(--cream);
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    padding: 0.15rem 0.55rem;
    box-shadow: 3px 3px 0 var(--accent);
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.15s, transform 0.15s;
}

.combo.show { opacity: 1; transform: scale(1); }

/* --- Cabinet --- */

.cabinet {
    position: relative;
    width: min(calc(84dvh * 0.5556), 92vw, 25.6rem);
    aspect-ratio: 400 / 720;
    border: 3px solid var(--ink);
    box-shadow: 8px 8px 0 var(--ink);
    background: var(--cream-deep);
    touch-action: none;
}

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

.message {
    position: absolute;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    font-size: 1.6rem;
    letter-spacing: 0.08em;
    color: var(--accent);
    text-shadow: 2px 2px 0 var(--card);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    white-space: nowrap;
}

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

.pull-btn {
    position: absolute;
    left: 0.6rem;
    bottom: 0.6rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    padding: 0.55rem 0.7rem;
    background: var(--accent);
    color: var(--card);
    border: 2px solid var(--ink);
    box-shadow: 3px 3px 0 var(--ink);
    cursor: pointer;
    display: none;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.pull-btn.show { display: block; }

.pull-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--ink);
}

/* --- Overlays --- */

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(43, 33, 24, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.overlay.hidden { display: none; }

.overlay-card {
    background: var(--card);
    border: 2px solid var(--ink);
    box-shadow: 6px 6px 0 var(--ink);
    padding: 1.4rem 1.6rem;
    max-width: 20rem;
    text-align: center;
}

.overlay-card h1 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.accent { color: var(--accent); }

.overlay-card .lead {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 0.9rem;
}

.how {
    list-style: none;
    text-align: left;
    font-size: 0.8rem;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.9rem;
}

.key {
    display: inline-block;
    background: var(--ink);
    color: var(--cream);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-right: 0.15rem;
}

.tip {
    font-size: 0.78rem;
    font-style: italic;
    color: var(--tech);
    margin-bottom: 1rem;
}

.big-btn {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    font-size: 1.05rem;
    background: var(--ink);
    color: var(--cream);
    border: none;
    padding: 0.55rem 1.6rem;
    box-shadow: 4px 4px 0 var(--accent);
    cursor: pointer;
}

.big-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0 var(--accent);
}

.big-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 var(--accent);
}

.final-line { color: var(--muted); margin-bottom: 0.4rem; }

.final-line strong {
    font-family: 'Fraunces', Georgia, serif;
    color: var(--ink);
}

.new-high {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 900;
    color: var(--accent);
    margin: 0.5rem 0 0.6rem;
}

.new-high.hidden, #new-high.hidden { display: none; }

.foot {
    text-align: center;
    padding: 0.6rem;
    font-size: 0.75rem;
    color: var(--muted);
    border-top: 2px solid var(--ink);
    background: var(--cream);
}

/* --- Narrow screens: HUD moves above the cabinet --- */

@media (max-width: 44rem) {
    .machine {
        flex-direction: column;
        gap: 0.7rem;
        padding: 0.6rem;
    }

    .hud {
        width: 100%;
        max-width: 24rem;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 0.6rem;
    }

    .price-tag { padding: 0.35rem 0.6rem; }
    .tag-value { font-size: 1.15rem; }
    .hud-row { border-bottom: none; flex-direction: column; align-items: flex-end; gap: 0; }

    .cabinet { width: min(calc(74dvh * 0.5556), 94vw, 25.6rem); }

    .foot { display: none; }
}
