html, body {
    margin: 0;
    padding: 0;
    background: #000;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    font-family: 'Pixelify Sans', monospace;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Stage = the 1600x720 game scaled uniformly to fit (js/layout.js sets
   left/top/width/height and the wrapper's scale). Everything inside the
   wrapper keeps its original 1600x720 coordinates. */
#stage {
    position: fixed;
    left: 0;
    top: 0;
    width: 1600px;
    height: 720px;
    overflow: hidden;
}

#game-wrapper {
    position: absolute;
    left: 0;
    top: 0;
    width: 1600px;
    height: 720px;
    transform-origin: 0 0;
    image-rendering: pixelated;
}

#game {
    image-rendering: pixelated;
    background: #000;
    display: block;
    width: 100%;
    height: 100%;
}

#demo-toggle, #music-toggle {
    position: absolute;
    top: 12px;
    left: auto;
    right: auto;
    font-family: 'Pixelify Sans', monospace;
    font-size: 13px;
    padding: 4px 10px;
    background: rgba(21, 21, 28, 0.95);
    color: #ddd;
    border: 2px solid #9aa0aa;
    cursor: pointer;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    image-rendering: pixelated;
    box-shadow: 0 2px 0 #000;
    /* --ui-boost > 1 only when the stage is scaled down (phones) so the
       buttons stay tappable/readable; 1 on desktop = unchanged */
    transform: scale(var(--ui-boost, 1));
    transform-origin: top center;
}

#demo-toggle {
    top: 8px;
    right: 340px; /* adjusted for map area ~ top-right of map */
}

#music-toggle {
    top: 8px;
    right: 160px;
}

#demo-toggle:hover, #music-toggle:hover {
    background: rgba(50, 50, 65, 0.95);
    border-color: #ddd;
}

#demo-toggle:active, #music-toggle:active {
    transform: scale(var(--ui-boost, 1)) translateY(1px);
}

/* Portrait panel (HUD strip + PARTY), only shown in portrait layout */
#portrait-panel {
    display: none;
}

#panel-canvas {
    display: block;
    width: 100%;
    image-rendering: auto;
}

/* View toggle (AUTO / DESKTOP / MOBILE): bottom-right corner of the PARTY
   panel, beside the footer line. Gold pixel border to match the panel. */
#view-toggle {
    position: absolute;
    right: 12px;
    bottom: 10px;
    font-family: 'Pixelify Sans', monospace;
    font-size: 10px;
    line-height: 12px;
    padding: 3px 5px;
    background: #15151c;
    color: #d8b070;
    border: 2px solid #d8b070;
    cursor: pointer;
    z-index: 10;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 2px 0 #000;
    transform: scale(var(--ui-boost, 1));
    transform-origin: bottom right;
}

/* invisible enlarged hit area (>= 40 CSS px when the stage is scaled down);
   grows up/left so it stays inside the stage */
#view-toggle::after {
    content: '';
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: max(calc(100% + 4px), var(--hit, 0px));
    height: max(calc(100% + 4px), var(--hit, 0px));
}

#view-toggle:hover {
    background: #2a2418;
    color: #f0d090;
}

#view-toggle:active {
    transform: scale(var(--ui-boost, 1)) translateY(1px);
}

/* ---------- Stacked ("mobile") layout ---------- */
body.stacked {
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    box-sizing: border-box;
}

body.stacked #stage {
    position: relative;
    margin: 0 auto;
    z-index: 5;
    box-shadow: 0 2px 0 #000, 0 3px 0 #d8b070;
}

body.stacked.stacked-sticky #stage {
    position: sticky;
    top: env(safe-area-inset-top, 0px);
}

body.stacked #portrait-panel {
    display: block;
    position: relative;
    margin: 3px auto 0;
    background: #15151c;
}

body.stacked #music-toggle,
body.stacked #demo-toggle,
body.stacked #view-toggle {
    top: 6px;
    bottom: auto;
    transform: none;
    font-size: 14px;
    line-height: 16px;
    min-height: 40px;
    min-width: 40px;
    padding: 10px 10px;
    box-sizing: border-box;
}

body.stacked #view-toggle { right: 8px; width: 84px; }
body.stacked #music-toggle { right: 98px; }
body.stacked #demo-toggle { right: 176px; }

body.stacked #demo-toggle:active,
body.stacked #music-toggle:active,
body.stacked #view-toggle:active {
    transform: translateY(1px);
}
