/* Space Intruders - the field page. The kit draws the cards, claim form and leaderboards (kit.css,
   "verified leaderboards"); this file is the stage: an 8:9 canvas with a heads-up display, the
   panels over it, the touch buttons under it and the side column. Sizes only from the kit scale. */

.si { max-width: 1180px; margin: 0 auto; padding: 16px var(--gutter) 24px; display: grid; gap: 16px; }
.si__stage {
    position: relative;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
    border-radius: 18px;
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line), var(--shadow-1);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
.si__stage[aria-busy="true"] { min-height: 420px; background: linear-gradient(110deg, var(--surface-2) 35%, var(--surface) 50%, var(--surface-2) 65%) 0 0 / 300% 100%; animation: skeleton 1.4s ease-in-out infinite; }
.si__hud { display: flex; flex-wrap: wrap; gap: 6px; min-height: 44px; padding-right: 52px; }
.hud-chip { display: inline-flex; flex-direction: column; min-width: 64px; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); color: var(--ink); line-height: 1.25; }
.hud-chip__label { font-size: var(--fs-xs); color: var(--ink-2); white-space: nowrap; }
.hud-chip strong { font-size: var(--fs-m); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hud-chip strong[data-hud="lives"] { color: var(--accent); letter-spacing: .1em; }
.si__pause { position: absolute; right: 10px; top: 10px; display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); cursor: pointer; }
.si__pause:hover { background: var(--surface-2); }
/* the field keeps the engine's 240 x 270 proportions and fits the screen height on desktops */
.si__field { position: relative; width: min(100%, calc((100svh - var(--header-h) - 150px) * 240 / 270), 560px); aspect-ratio: 240 / 270; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #0b1020; box-shadow: inset 0 0 0 2px #06091a; }
.si__canvas { display: block; width: 100%; height: 100%; }
.si[data-phase="play"] .si__field { cursor: crosshair; }

/* cards over the field */
.si__panel { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; padding: 16px; overflow-y: auto; overscroll-behavior: contain; border-radius: 18px; background: rgb(11 16 32 / .4); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); touch-action: pan-y; }
.end-badge[data-reason="destroyed"] { background: rgb(155 50 38 / .12); color: var(--accent); }
.end-badge[data-reason="invaded"] { background: rgb(155 50 38 / .12); color: var(--accent); }

/* touch buttons: on coarse pointers only - move left / right on the left, fire on the right */
.pad { display: none; grid-template-columns: 72px 72px 1fr 112px; gap: 8px; align-items: center; margin: -4px auto 0; width: min(100%, 560px); }
.pad__btn { display: grid; place-items: center; min-width: 44px; min-height: 60px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); cursor: pointer; touch-action: manipulation; font-size: var(--fs-s); font-weight: 600; }
.pad__btn:active { background: var(--surface-2); transform: translateY(1px); }
.pad__btn--fire { grid-column: 4; background: var(--primary-bg); color: var(--primary-ink); border-color: transparent; }
@media (pointer: coarse) {
    .si[data-phase="play"] .pad, .si[data-phase="countdown"] .pad, .si[data-phase="pause"] .pad { display: grid; }
}

/* beside the field */
.si__side { display: grid; gap: 16px; align-content: start; }

@media (min-width: 1024px) {
    .si { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; padding-top: 24px; }
    .pad { grid-column: 1; }
    .si__side { grid-column: 2; grid-row: 1 / span 2; position: sticky; top: calc(var(--header-h) + 24px); }
}

/* phones: the field as wide as the screen; buttons right under it, on screen while playing */
@media (max-width: 639px) {
    .si { padding: 0 0 16px; gap: 10px; }
    /* room for the menu / result cards over the field */
    .si__stage { min-height: min(560px, calc(100svh - var(--header-h) - 24px)); padding: 8px; border-radius: 0; box-shadow: none; border-bottom: 1px solid var(--line); }
    .si[data-phase="play"] .si__stage, .si[data-phase="countdown"] .si__stage, .si[data-phase="pause"] .si__stage { min-height: 0; }
    .si__field { width: min(100%, calc((100svh - var(--header-h) - 216px) * 240 / 270)); border-radius: 8px; }
    .si__hud { gap: 4px; }
    .hud-chip { min-width: 0; padding: 3px 8px; }
    .si__pause { right: 8px; top: 8px; }
    .si__panel { padding: 12px; place-items: start center; border-radius: 0; }
    .panel-card { padding: 18px 16px; }
    .end-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 10px 0; }
    .end-stats div { padding: 4px 6px; }
    .end-stats dt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .end-stats dd { font-size: var(--fs-s); }
    .si__side { padding: 0 var(--gutter); }
    .pad { width: calc(100% - 2 * var(--gutter)); grid-template-columns: 64px 64px 1fr 104px; }
}

/* phones on their side: the field fits the height, the buttons beside it */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
    .si { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding-top: 8px; }
    .si__stage { grid-column: 1; grid-row: 1; min-height: 0; }
    .si__field { width: min(100%, calc((100svh - var(--header-h) - 84px) * 240 / 270)); }
    .si .pad { grid-column: 2; grid-row: 1; grid-template-columns: 64px; grid-template-rows: 60px 60px 72px; width: auto; margin: 0; }
    .si .pad__btn--fire { grid-column: 1; }
    .si__side { grid-column: 1 / -1; }
}
