* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    width: 100%;
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: "Fredoka", Arial, Helvetica, sans-serif;
    color: #2b3a1e;
    background: #4f8f3c;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

canvas {
    display: block;
    width: 100vw;
    height: 100vh;
}

/* ---------- HUD ---------- */

.hud {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    display: grid;
    gap: 8px;
    pointer-events: none;
    max-width: calc(100vw - 24px);
    z-index: 5;
}

.brand,
.stat-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand {
    justify-content: space-between;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 0 rgba(43, 58, 30, 0.6);
}

.brand a {
    pointer-events: auto;
    color: #fff8dd;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 8px 12px;
    border: 3px solid rgba(90, 58, 30, 0.9);
    border-radius: 10px;
    background: linear-gradient(#b97932, #7d4519);
    box-shadow: 0 3px 0 rgba(62, 33, 14, 0.8);
    text-shadow: 0 1px 0 rgba(62, 33, 14, 0.8);
}

.stat-row {
    flex-wrap: wrap;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: 999px;
    border: 3px solid rgba(90, 58, 30, 0.85);
    background: rgba(255, 248, 224, 0.94);
    color: #4a3218;
    font-weight: 700;
    font-size: 0.92rem;
    box-shadow: 0 3px 0 rgba(62, 33, 14, 0.45);
}

.pill.carry.holding {
    background: #ffe9a8;
    border-color: #b8860b;
}

.pill.status.is-hidden {
    background: #cfe8c4;
    border-color: #3e7a34;
    color: #2b5a22;
}

.pill.status.is-sneaking {
    background: #e8f0d8;
    border-color: #6b8f3c;
    color: #3d5a1e;
}

.pill.status.is-spotted {
    background: #ffd2d2;
    border-color: #c0392b;
    color: #8e2419;
    animation: spotted-flash 0.5s ease-in-out infinite alternate;
}

@keyframes spotted-flash {
    from { transform: scale(1); }
    to { transform: scale(1.06); }
}

.hint {
    max-width: 480px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 3px solid rgba(90, 58, 30, 0.85);
    background: rgba(255, 248, 224, 0.95);
    color: #4a3218;
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.35;
    box-shadow: 0 3px 0 rgba(62, 33, 14, 0.45);
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(26px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 6;
    max-width: calc(100vw - 32px);
    padding: 12px 20px;
    border-radius: 16px;
    border: 3px solid rgba(90, 58, 30, 0.9);
    background: rgba(255, 248, 224, 0.97);
    color: #4a3218;
    font-weight: 700;
    font-size: 1rem;
    text-align: center;
    box-shadow: 0 4px 0 rgba(62, 33, 14, 0.5);
    pointer-events: none;
}

.toast.pop {
    animation: toast-pop 0.28s ease-out;
}

@keyframes toast-pop {
    from {
        transform: translateX(-50%) translateY(14px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0) scale(1);
        opacity: 1;
    }
}

/* ---------- Panels ---------- */

.panel {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(180deg, rgba(38, 74, 30, 0.25), rgba(38, 74, 30, 0.78));
}

.panel > div {
    width: 100%;
    max-width: 480px;
    padding: 26px;
    border: 5px solid #5a3218;
    border-radius: 18px;
    background: linear-gradient(#fffbe8, #f5e6bd);
    box-shadow: 0 8px 0 rgba(62, 33, 14, 0.55), 0 20px 44px rgba(20, 40, 16, 0.4);
    text-align: center;
}

.eyebrow {
    margin: 0 0 8px;
    color: #7d4519;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0 0 8px;
    line-height: 1;
    color: #7d4519;
    text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}

h1 {
    font-size: clamp(2.5rem, 9vw, 3.6rem);
}

h2 {
    font-size: clamp(2rem, 8vw, 3rem);
}

.credit {
    margin: 0 0 16px;
    color: #8a6a3e;
    font-weight: 600;
    font-size: 0.95rem;
}

.name-label {
    display: block;
    margin-bottom: 6px;
    color: #6a4a22;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: left;
}

#nameInput {
    width: 100%;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 3px solid #a9713c;
    border-radius: 12px;
    background: #fff;
    color: #4a3218;
    font: inherit;
    font-weight: 700;
    text-align: center;
}

#nameInput:focus {
    outline: none;
    border-color: #7d4519;
    box-shadow: 0 0 0 3px rgba(185, 121, 50, 0.3);
}

.tutorial {
    margin: 0 0 14px;
    padding: 12px 14px 12px 34px;
    border-radius: 12px;
    background: rgba(126, 200, 80, 0.18);
    color: #4a5a2e;
    font-weight: 600;
    font-size: 0.92rem;
    text-align: left;
    line-height: 1.5;
}

.tutorial li {
    margin-bottom: 3px;
}

.controls-note {
    margin: 0 0 16px;
    color: #8a6a3e;
    font-size: 0.82rem;
    font-weight: 600;
}

.panel p {
    color: #5a4a2e;
    line-height: 1.5;
}

button {
    width: 100%;
    min-height: 50px;
    padding: 12px 18px;
    border: 4px solid #3e7a34;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(#8fd34e, #4e9e38);
    font: inherit;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 5px 0 rgba(34, 66, 26, 0.8);
    text-shadow: 0 1px 0 rgba(34, 66, 26, 0.6);
    transition: transform 100ms ease;
}

button:hover,
button:focus-visible {
    outline: none;
    transform: translateY(-2px);
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(34, 66, 26, 0.8);
}

@media (max-width: 620px) {
    .panel {
        padding: 14px;
    }

    .panel > div {
        max-width: calc(100vw - 28px);
        padding: 20px;
    }

    h1 {
        font-size: clamp(2rem, 10vw, 2.6rem);
    }

    .hint {
        font-size: 0.82rem;
    }
}

/* ---------- Mobile Game Boy shell tweaks ---------- */

body.charliebear-mobile {
    background: #a8a8a8;
}

body.charliebear-mobile #gameboy-shell {
    z-index: 1;
}

body.charliebear-mobile #gameboy-screen-bezel {
    aspect-ratio: 10 / 9;
}

body.charliebear-mobile #gameboy-screen-bezel canvas {
    image-rendering: auto;
}

body.charliebear-mobile .gb-brand {
    color: #6b4423;
    font-size: 16px;
}

body.charliebear-mobile .action-btn {
    background: linear-gradient(145deg, #8a5a2c 0%, #6b4423 100%);
    border-color: #4a2f14;
    color: #f5d9a8;
}

body.charliebear-mobile .action-btn:active,
body.charliebear-mobile .action-btn.pressed {
    background: linear-gradient(145deg, #6b4423 0%, #4a2f14 100%);
}

body.charliebear-mobile .hud {
    z-index: 2;
    top: calc(58px + env(safe-area-inset-top));
    left: max(22px, calc((100vw - 400px) / 2 + 16px));
    right: max(22px, calc((100vw - 400px) / 2 + 16px));
    gap: 5px;
}

body.charliebear-mobile .brand {
    font-size: 0.74rem;
}

body.charliebear-mobile .brand a {
    padding: 5px 8px;
    font-size: 0.68rem;
}

body.charliebear-mobile .pill {
    padding: 4px 9px;
    font-size: 0.7rem;
    border-width: 2px;
}

body.charliebear-mobile .hint {
    padding: 7px 10px;
    font-size: 0.7rem;
    border-width: 2px;
}

body.charliebear-mobile .toast {
    z-index: 3;
    bottom: auto;
    top: calc(48vh);
    padding: 8px 14px;
    font-size: 0.82rem;
}

body.charliebear-mobile .panel {
    z-index: 4;
}

body.charliebear-mobile .panel > div {
    max-width: min(360px, calc(100vw - 34px));
    padding: 18px;
}

body.charliebear-mobile h1 {
    font-size: clamp(1.8rem, 9vw, 2.4rem);
}

body.charliebear-mobile .tutorial {
    font-size: 0.82rem;
    padding: 10px 10px 10px 30px;
}
