/* ==========================================================================
   Game Boy (app/commands/gameboy.js)
   Library on the Orbit UI kit; the player (.gb-play) is a dark handheld with
   the screen on top and the buttons below (side by side in landscape).
   Motion lives in the "Game Boy" section at the end of css/motion.css.
   ========================================================================== */

.gb-app { container-type: inline-size; container-name: gbwin; }

/* ---------- Library ---------- */
.gb-app .gb-hero { overflow: hidden; }
.gb-app .gb-hero-art { position: absolute; right: -14px; top: -10px; opacity: 0.16; transform: rotate(-14deg); pointer-events: none; }
.gb-app .gb-hero-art svg { width: 150px; height: 150px; stroke: #ffffff; }

.gb-app .gb-continue {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-radius: 28px;
    color: #ffffff;
    cursor: pointer;
    overflow: hidden;
    background: linear-gradient(150deg, color-mix(in srgb, var(--hue) 55%, #000000), var(--hue) 70%, color-mix(in srgb, var(--hue) 70%, #ffffff));
}
.gb-app .gb-continue-text { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.gb-app .gb-continue-text .ok-hero-label { color: #ffffff; }
.gb-app .gb-continue-text strong { font-size: 1.3rem; font-weight: 700; color: #ffffff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-app .gb-continue-text > span:last-child { font-size: 0.82rem; opacity: 0.85; }
.gb-app .gb-continue-play { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%; background: #ffffff; color: #1a2e05; flex-shrink: 0; }
.gb-app .gb-continue-play svg { margin-left: 3px; }

/* A cartridge: the screenshot as its label, or a colored one with the title */
.gb-cart {
    position: relative;
    display: flex;
    align-items: flex-end;
    width: 100%;
    aspect-ratio: 10 / 9;
    border-radius: 12px 12px 6px 6px;
    overflow: hidden;
    background: linear-gradient(160deg, hsl(var(--h, 90) 45% 40%), hsl(calc(var(--h, 90) + 40) 50% 22%));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.gb-cart.is-big { width: 86px; flex-shrink: 0; border-radius: 14px 14px 8px 8px; }
.gb-cart img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.gb-cart-label { position: relative; width: 100%; padding: 6px 8px; font: 800 0.72rem/1.15 var(--font-main); letter-spacing: 0.02em; color: #ffffff; text-transform: uppercase; background: linear-gradient(transparent, rgba(0, 0, 0, 0.55)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-cart img ~ .gb-cart-label { display: none; }
.gb-cart-cgb { position: absolute; top: 6px; right: 6px; padding: 2px 6px; border-radius: 999px; font: 800 0.55rem var(--font-main); letter-spacing: 0.08em; color: #ffffff; background: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e, #3b82f6, #a855f7); }

.gb-app .gb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.gb-app .gb-game {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid var(--ok-line);
    background: var(--ok-card);
    color: var(--on-surface);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
.gb-app .gb-game-name { margin-top: 4px; font-size: 0.9rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 26px; }
.gb-app .gb-game-meta { font-size: 0.74rem; color: var(--ok-muted); }
.gb-app .gb-more { position: absolute; right: 6px; bottom: 10px; width: 28px; height: 28px; }

.gb-app .gb-own {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    border-radius: 22px;
    border: 1px dashed var(--ok-line-strong);
    background: transparent;
    color: var(--on-surface);
    font-family: var(--font-main);
    text-align: left;
    cursor: pointer;
}
.gb-app .gb-own-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.gb-app .gb-own-text strong { font-size: 0.95rem; }
.gb-app .gb-own-text span { font-size: 0.8rem; color: var(--ok-muted); }

.gb-app .gb-shelf { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@container gbwin (min-width: 620px) { .gb-app .gb-shelf { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.gb-app .gb-hb {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
    min-height: 0;
    padding: 8px 8px 10px;
    border-radius: 20px;
    border: 1px solid var(--ok-line);
    background: var(--ok-card);
    color: var(--on-surface);
    font-family: var(--font-main);
    text-align: left;
    cursor: pointer;
}
.gb-app .gb-hb-shot { position: relative; display: block; aspect-ratio: 10 / 9; border-radius: 14px; overflow: hidden; background: #0f1a07; margin-bottom: 5px; }
.gb-app .gb-hb-shot img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; display: block; }
.gb-app .gb-hb-owned { position: absolute; left: 6px; bottom: 6px; display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 999px; background: rgba(0, 0, 0, 0.65); color: #ffffff; font: 700 0.64rem var(--font-main); font-style: normal; }
.gb-app .gb-hb-name { font-size: 0.88rem; font-weight: 700; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-app .gb-hb-meta { font-size: 0.72rem; color: var(--ok-muted); padding: 0 4px; }

/* ---------- Sheets ---------- */
.gb-app .gb-sheet .xa-sheet-card { gap: 12px; max-height: 88%; overflow-y: auto; overscroll-behavior: contain; }
.gb-app .gb-grab { align-self: center; width: 38px; height: 4px; border-radius: 2px; background: var(--ok-line-strong); flex-shrink: 0; }
.gb-app .gb-hb-cover { border-radius: 18px; overflow: hidden; aspect-ratio: 10 / 9; max-height: 240px; align-self: center; background: #0f1a07; }
.gb-app .gb-hb-cover img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; }
.gb-app .gb-sheet-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gb-app .gb-sheet-title strong { font-size: 1.2rem; }
.gb-app .gb-sheet-title span { font-size: 0.82rem; color: var(--ok-muted); }
.gb-app .gb-sheet-text { margin: 0; font-size: 0.9rem; line-height: 1.5; }
.gb-app .gb-sheet-note { margin: 0; font-size: 0.76rem; color: var(--ok-muted); line-height: 1.45; }
.gb-app .gb-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-radius: 18px; border: 1px solid var(--ok-line); overflow: hidden; }
.gb-app .gb-facts span { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; font-size: 0.72rem; color: var(--ok-muted); text-align: center; }
.gb-app .gb-facts span + span { border-left: 1px solid var(--ok-line); }
.gb-app .gb-facts b { font-size: 0.9rem; color: var(--on-surface); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.gb-app .gb-sheet-actions { display: flex; gap: 10px; }
.gb-app .gb-sheet-actions .ok-btn { flex: 1; height: 48px; gap: 8px; font-size: 0.92rem; }
.gb-app .gb-spin { width: 16px; height: 16px; }
.gb-app .gb-progress { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--hue) 18%, transparent); overflow: hidden; }
.gb-app .gb-progress[hidden] { display: none; }
.gb-app .gb-progress i, .gb-app .gb-progress-bar i { display: block; height: 8px; width: 0; border-radius: 4px; background: var(--hue); }
.gb-app .gb-info-head { display: flex; align-items: center; gap: 14px; }
.gb-app .gb-slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gb-app .gb-slot { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 16px; border: 1px solid var(--ok-line-strong); background: transparent; color: var(--on-surface); font-family: var(--font-main); text-align: left; cursor: pointer; }
.gb-app .gb-slot:disabled { opacity: 0.45; cursor: default; }
.gb-app .gb-slot-shot { display: flex; align-items: center; justify-content: center; aspect-ratio: 10 / 9; border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--hue) 14%, transparent); }
.gb-app .gb-slot-shot img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; }
.gb-app .gb-slot-shot b { font-size: 1.6rem; color: var(--ok-muted); }
.gb-app .gb-slot-text { display: flex; flex-direction: column; gap: 1px; padding: 0 2px; }
.gb-app .gb-slot-text strong { font-size: 0.86rem; }
.gb-app .gb-slot-text span { font-size: 0.72rem; color: var(--ok-muted); }
@container gbwin (min-width: 700px) {
    .gb-app .gb-sheet { align-items: center; padding: 24px; }
    .gb-app .gb-sheet .xa-sheet-card { max-width: 480px; border-radius: 26px; border-bottom: 1px solid var(--ok-line); padding-bottom: 20px; }
    .gb-app .gb-grab { display: none; }
    .gb-app .ok-column { max-width: 1100px; }
}
@media (hover: hover) and (pointer: fine) {
    .gb-app :is(.gb-game, .gb-hb, .gb-own, .gb-slot:not(:disabled)):hover { border-color: var(--ok-line-strong); background: color-mix(in srgb, var(--on-surface) 4%, var(--ok-card)); }
    .gb-play :is(.gb-top-btn, .gb-pill):hover { background: rgba(255, 255, 255, 0.16); }
}
html.kbd-nav .gb-app :is(.gb-game, .gb-hb, .gb-own, .gb-slot):focus-visible { outline: 2px solid var(--hue); outline-offset: 2px; }

/* ---------- Player ---------- */
.gb-play {
    --gb-ink: #eef3e6;
    --gb-shell: #16181d;
    --pad-alpha: 1;
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    background: radial-gradient(130% 80% at 50% 0%, #20242b 0%, #0c0e12 70%);
    color: var(--gb-ink);
    overflow: hidden;
    font-family: var(--font-main);
    user-select: none;
    -webkit-user-select: none;
}
.gb-play.gb-portal { position: fixed; z-index: 10000; }
.gb-play.is-away { visibility: hidden; }
.gb-app.gb-under > .ok-body { visibility: hidden; }

.gb-play .gb-top { display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top, 0px)); flex-shrink: 0; }
.gb-play .gb-top-btn { width: 40px; height: 40px; border-color: transparent; background: rgba(255, 255, 255, 0.08); color: var(--gb-ink); }
.gb-play .gb-top-btn svg { stroke: currentColor; }
.gb-play .gb-top-text { display: flex; flex-direction: column; flex: 1; min-width: 0; padding: 0 4px; }
.gb-play .gb-top-text strong { font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-play .gb-status { font-style: normal; font-size: 0.74rem; color: rgba(238, 243, 230, 0.6); font-variant-numeric: tabular-nums; }

.gb-play .gb-stage { position: relative; flex: 1 1 auto; min-height: 150px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gb-play .gb-screen {
    position: relative;
    width: 160px;
    height: 144px;
    transform: scale(var(--s, 2));
    border-radius: 2px;
    box-shadow: 0 0 0 calc(4px / var(--s, 2)) #0a0b0d, 0 0 0 calc(7px / var(--s, 2)) rgba(255, 255, 255, 0.06);
    background: #000000;
}
.gb-play .gb-screen canvas { display: block; width: 160px; height: 144px; image-rendering: pixelated; image-rendering: crisp-edges; }
.gb-play.gb-smooth .gb-screen canvas { image-rendering: auto; }
.gb-play .gb-lcd { position: absolute; inset: 0; display: none; pointer-events: none; background-image: linear-gradient(rgba(0, 0, 0, 0.22) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, 0.22) 1px, transparent 1px); background-size: 1px 1px; opacity: 0.55; }
.gb-play.gb-lcd-on .gb-lcd { display: block; }
.gb-play.is-rewinding .gb-screen { filter: saturate(0.4) brightness(0.9); }

.gb-play .gb-overlay, .gb-play .gb-paused { position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; font-size: 0.86rem; color: rgba(238, 243, 230, 0.8); }
.gb-play .gb-overlay { background: #0c0e12; }
.gb-play .gb-overlay strong { font-size: 1.05rem; color: var(--gb-ink); }
.gb-play .gb-err { display: inline-flex; align-items: center; justify-content: center; width: 60px; height: 60px; border-radius: 20px; background: #b91c1c; }
.gb-play .gb-err svg { stroke: #ffffff; }
.gb-play .gb-paused { background: rgba(0, 0, 0, 0.5); }
.gb-play .gb-paused[hidden], .gb-play .gb-hint[hidden], .gb-play .gb-ffbadge[hidden] { display: none; }
.gb-play .gb-paused-btn { display: inline-flex; align-items: center; justify-content: center; width: 70px; height: 70px; border: none; border-radius: 50%; background: #ffffff; color: #111111; cursor: pointer; }
.gb-play .gb-paused-btn svg { margin-left: 4px; }
.gb-play .gb-hint { position: absolute; top: 10px; left: 50%; translate: -50% 0; z-index: 3; max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 999px; background: rgba(20, 22, 28, 0.9); font-size: 0.8rem; font-weight: 600; text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.2s ease; }
.gb-play .gb-hint.is-on { opacity: 1; }
.gb-play .gb-ffbadge { position: absolute; top: 10px; right: 12px; z-index: 3; display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 999px; background: #f59e0b; color: #1a1205; font-size: 0.74rem; }
.gb-play .gb-flash { position: absolute; inset: 0; z-index: 4; background: #ffffff; opacity: 0; pointer-events: none; }

/* Buttons */
.gb-play { --u: 1; }
.gb-play[data-size="s"] { --u: 0.82; }
.gb-play[data-size="l"] { --u: 1.18; }
.gb-play .gb-pad { position: relative; flex-shrink: 0; display: flex; flex-direction: column; gap: calc(14px * var(--u)); padding: 8px 18px max(18px, env(safe-area-inset-bottom, 0px)); opacity: var(--pad-alpha); touch-action: none; }
.gb-play.pad-hidden .gb-pad { display: none; }
.gb-play .gb-pad-row { display: flex; justify-content: center; gap: 10px; }
.gb-play .gb-pad-top { justify-content: space-between; }
.gb-play .gb-pill { display: inline-flex; align-items: center; justify-content: center; width: calc(52px * var(--u)); height: calc(34px * var(--u)); border: none; border-radius: 999px; background: rgba(255, 255, 255, 0.08); color: var(--gb-ink); cursor: pointer; touch-action: none; }
.gb-play .gb-pill.is-on { background: #f59e0b; color: #1a1205; }
.gb-play [data-k="rewind"].is-on { background: #8b5cf6; color: #ffffff; }
.gb-play .gb-pad-main { display: flex; align-items: center; justify-content: space-between; }
.gb-play .gb-dpad { position: relative; width: calc(146px * var(--u)); height: calc(146px * var(--u)); flex-shrink: 0; touch-action: none; }
.gb-play .gb-dpad i { position: absolute; background: #2a2e36; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35); }
.gb-play .gb-d-up, .gb-play .gb-d-down { left: 33%; width: 34%; height: 36%; }
.gb-play .gb-d-up { top: 0; border-radius: 10px 10px 0 0; }
.gb-play .gb-d-down { bottom: 0; border-radius: 0 0 10px 10px; }
.gb-play .gb-d-left, .gb-play .gb-d-right { top: 33%; height: 34%; width: 36%; }
.gb-play .gb-d-left { left: 0; border-radius: 10px 0 0 10px; }
.gb-play .gb-d-right { right: 0; border-radius: 0 10px 10px 0; }
.gb-play .gb-d-mid { left: 32%; top: 32%; width: 36%; height: 36%; border-radius: 0; box-shadow: none; }
.gb-play .gb-dpad i.is-down { background: #3b4250; box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.4); }
.gb-play .gb-ab { display: flex; align-items: flex-end; gap: calc(16px * var(--u)); transform: rotate(-22deg); padding-right: 4px; }
.gb-play .gb-btn { width: calc(70px * var(--u)); height: calc(70px * var(--u)); border: none; border-radius: 50%; background: #b0234f; color: rgba(255, 255, 255, 0.85); font: 800 calc(1.05rem * var(--u)) var(--font-main); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.35); cursor: pointer; touch-action: none; }
.gb-play .gb-a { margin-bottom: calc(26px * var(--u)); }
.gb-play.ab-swapped .gb-ab { flex-direction: row-reverse; }
.gb-play.ab-swapped .gb-a { margin-bottom: 0; }
.gb-play.ab-swapped .gb-b { margin-bottom: calc(26px * var(--u)); }
.gb-play .gb-btn.is-down { background: #8e1a3f; box-shadow: inset 0 3px 0 rgba(0, 0, 0, 0.35); }
.gb-play .gb-pad-sys { gap: calc(26px * var(--u)); }
.gb-play .gb-sys { height: calc(28px * var(--u)); padding: 0 calc(16px * var(--u)); border: none; border-radius: 999px; background: #2a2e36; color: rgba(238, 243, 230, 0.7); font: 800 calc(0.66rem * var(--u)) var(--font-main); letter-spacing: 0.1em; transform: rotate(-22deg); cursor: pointer; touch-action: none; }
.gb-play .gb-sys.is-down { background: #3b4250; color: #ffffff; }

/* Landscape: d-pad left, screen in the middle, A/B right */
@media (orientation: landscape) and (max-height: 600px) {
    .gb-play { display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: auto 1fr; }
    .gb-play .gb-top { grid-column: 1 / -1; padding-top: max(4px, env(safe-area-inset-top, 0px)); padding-bottom: 0; }
    .gb-play .gb-stage { grid-column: 1 / -1; grid-row: 2; min-height: 0; }
    .gb-play .gb-pad { position: absolute; inset: 52px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); padding: 0; z-index: 3; pointer-events: none; display: block; }
    .gb-play .gb-pad > * { pointer-events: auto; }
    .gb-play .gb-pad-main { position: absolute; left: 0; right: 0; bottom: 30px; }
    .gb-play .gb-pad-top { position: absolute; left: 0; right: 0; top: 0; }
    .gb-play .gb-pad-sys { position: absolute; left: 0; right: 0; bottom: 0; justify-content: space-between; padding: 0 calc(30px * var(--u)); pointer-events: none; }
    .gb-play .gb-pad-sys > * { pointer-events: auto; }
    .gb-play .gb-pad-top [data-g] { display: none; }
    .gb-play .gb-pad-main { bottom: calc(44px * var(--u)); }
}

/* Light themes: the player stays a dark handheld. */
html.theme-solar-flare .gb-play, html.theme-arctic .gb-play, html.theme-paper .gb-play, html.theme-blossom .gb-play, html.theme-sage .gb-play { color: var(--gb-ink); }
.gb-play .gb-spin { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); border-top-color: #ffffff; }
