/* ============================================================
   Pocket GBA — home, game screen, pad, editor, settings.
   Layout follows the GBA Player design spec.
   ============================================================ */

/* ----------------------------- app shell ----------------------------- */

.screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.screen.on {
    display: flex;
}

/* ----------------------------- home ----------------------------- */

#screen-home {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

.home {
    padding: calc(48px + var(--safe-top)) 20px calc(28px + var(--safe-bottom));
    max-width: 620px;
    margin: 0 auto;
    width: 100%;
}

.home-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.home-head .grow {
    flex: 1;
}

.home .sub {
    margin: 2px 0 0;
}

/* drop zone */
.dz {
    border: 2px dashed #4a4478;
    border-radius: var(--r-l);
    padding: 28px 16px;
    text-align: center;
    margin: 22px 0 8px;
    background: var(--s1);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dz.over {
    border-color: var(--ac);
    background: var(--s2);
}

.dz .ic {
    color: var(--ac);
    display: flex;
    justify-content: center;
}

.dz b {
    display: block;
    margin: 6px 0 12px;
    font-size: 14px;
}

.note {
    margin: 0;
}

.section-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-head h2 {
    margin: 22px 0 10px;
    flex: 1;
}

.section-head .count {
    color: var(--mu);
    font-size: 12px;
    margin: 22px 0 10px;
}

.search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--r-s);
    background: var(--s1);
    border: 1px solid var(--line);
    color: var(--mu);
    margin-bottom: 12px;
}

.search input {
    flex: 1;
    min-width: 0;
    border: none;
    background: none;
    outline: none;
    color: var(--tx);
    font-size: 14px;
    user-select: text;
    -webkit-user-select: text;
}

.search input::placeholder {
    color: var(--mu);
}

/* game cards */
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (min-width: 720px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.card {
    background: var(--s1);
    border: 0;
    border-radius: var(--r-m);
    overflow: hidden;
    text-align: left;
    padding: 0;
    position: relative;
    transition: transform 0.12s ease;
}

.card:active {
    transform: scale(0.97);
}

.card .cover {
    display: block;
    aspect-ratio: 3 / 2;
    position: relative;
}

.card .cover .mono {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    font-weight: 850;
    color: rgba(255, 255, 255, 0.92);
    text-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.card .cover .badge {
    position: absolute;
    right: 8px;
    top: 8px;
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 99px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.card p {
    margin: 8px 10px 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card small {
    display: block;
    margin: 2px 10px 10px;
    color: var(--mu);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card .more {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.empty {
    border: 1.5px dashed #4a4478;
    border-radius: var(--r-l);
    padding: 34px 18px;
    text-align: center;
    color: var(--mu);
    background: var(--s1);
}

.empty .h2 {
    color: var(--tx);
    margin-bottom: 6px;
}

/* ----------------------------- game screen ----------------------------- */

#screen-game {
    background: var(--bg-deep);
}

.game-stage {
    position: absolute;
    overflow: hidden;
    background: #000;
}

/* portrait: game sits at the top (3:2) */
@media (orientation: portrait) {
    .game-stage {
        left: 0;
        right: 0;
        top: var(--safe-top);
        aspect-ratio: 3 / 2;
    }
}

/* landscape: full height, centered (3:2) */
@media (orientation: landscape) {
    .game-stage {
        top: 0;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        height: 100%;
        aspect-ratio: 3 / 2;
        max-width: 100%;
    }
}

.ejs-host,
#ejs-player-mount {
    width: 100%;
    height: 100%;
}

/* aspect modes (applied on top of the engine's canvas) */
.game-stage.stretch .ejs_canvas {
    width: 100% !important;
    height: 100% !important;
}

.game-stage.pix .ejs_canvas {
    image-rendering: pixelated;
}

.game-stage .ejs_canvas {
    image-rendering: auto;
}

/* LCD grid overlay */
.lcd-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.13) 0 1px, transparent 1px 3px),
        repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.1) 0 1px, transparent 1px 3px);
    mix-blend-mode: multiply;
}

.lcd-overlay::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(185, 215, 155, 0.1);
}

/* hide any residual engine chrome */
.game-stage .ejs_menu_bar,
.game-stage .ejs_bottom_bar,
.game-stage .ejs_virtualGamepad_parent {
    display: none !important;
}

.start-hint {
    position: absolute;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    width: max-content;
    max-width: 86%;
    text-align: center;
    color: var(--mu);
    font-size: 12px;
    background: rgba(17, 15, 31, 0.75);
    padding: 8px 16px;
    border-radius: 99px;
    border: 1px solid var(--line);
    pointer-events: none;
    z-index: 6;
}

/* ----------------------------- floating gamepad ----------------------------- */

.pad {
    position: absolute;
    inset: 0;
    z-index: 4;
    touch-action: none;
    transition: opacity 0.4s ease;
}

.pad.dimmed {
    opacity: 0.15;
}

.pad[hidden] {
    display: none !important;
}

.cb {
    position: absolute;
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, 0.16);
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: #fff;
    font-weight: 700;
    touch-action: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: background 0.06s ease, transform 0.06s ease;
}

.cb.c {
    border-radius: 50%;
}

.cb.r {
    border-radius: 14px;
}

.cb.dn {
    background: rgba(139, 124, 255, 0.8);
    border-color: #fff;
}

.cb b {
    position: absolute;
    font-size: 16px;
    transform: translate(-50%, -50%);
    font-weight: 700;
    pointer-events: none;
}

/* editor affordances */
.pad.editing {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 20px 20px;
}

.pad.editing .cb {
    outline: 1px dashed rgba(255, 255, 255, 0.6);
    outline-offset: 3px;
    cursor: grab;
}

.pad.editing .cb.sel {
    outline: 2px solid var(--hi);
}

.pad.editing .cb.ov {
    outline: 2px solid var(--er);
}

/* ----------------------------- editor sheet ----------------------------- */

#editor-sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--s1);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: 8px 16px calc(16px + var(--safe-bottom));
    z-index: 10;
    transition: transform 0.25s ease;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.6);
    touch-action: pan-y;
    max-height: 58%;
    overflow-y: auto;
}

#editor-sheet.min {
    transform: translateY(calc(100% - 66px));
}

@media (orientation: landscape) and (max-height: 560px) {
    #editor-sheet {
        left: auto;
        top: 0;
        width: 290px;
        border-radius: var(--r-xl) 0 0 var(--r-xl);
        padding-bottom: 12px;
        max-height: 100%;
    }
    #editor-sheet.min {
        transform: translateX(calc(100% - 28px));
    }
    #editor-sheet .gr {
        position: absolute;
        left: 10px;
        top: 50%;
        width: 5px;
        height: 44px;
        margin: 0;
    }
    #editor-sheet .rw label {
        flex-basis: 84px;
    }
}

.gr {
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: #4a4478;
    margin: 0 auto 8px;
    cursor: pointer;
}

.rw {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.rw label {
    flex: 0 0 92px;
    color: var(--mu);
    font-size: 12px;
}

.rw output {
    width: 40px;
    text-align: right;
    font-size: 12px;
    color: var(--mu);
}

.rw b {
    font-size: 14px;
}

/* ----------------------------- settings screen ----------------------------- */

#screen-settings {
    background: var(--bg);
}

.set-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(12px + var(--safe-top)) 16px 0;
}

.set-head h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.4px;
    flex: 1;
}

.set-lang {
    display: flex;
    gap: 4px;
    background: var(--s1);
    border-radius: 99px;
    padding: 3px;
}

.set-lang .chip {
    min-height: 28px;
    padding: 4px 10px;
}

.tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    margin: 14px 16px 4px;
    padding-bottom: 6px;
    touch-action: pan-x;
    flex: none;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.set-body {
    overflow-y: auto;
    flex: 1;
    padding: 4px 16px calc(24px + var(--safe-bottom));
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    max-width: 620px;
    margin: 0 auto;
    width: 100%;
}

.set-body .row.v > .name {
    font-size: 14px;
    font-weight: 600;
}

.keymap {
    margin: 8px 0;
    border-top: 1px solid var(--line);
}

.keymap .row {
    gap: 10px;
}

.key-cap {
    min-width: 86px;
    height: 34px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--s2);
    border: 1px solid var(--line-strong);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--mu);
}

.key-cap.listening {
    border-color: var(--hi);
    color: var(--hi);
    animation: keypulse 1s ease infinite;
}

@keyframes keypulse {
    50% {
        background: var(--s3);
    }
}

.storage-note {
    margin-top: 10px;
}

/* game detail bits inside sheets */
.meta-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 2px 0 6px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    font-size: 13px;
}

.meta-row .k {
    color: var(--mu);
}

.state-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.state-row:last-child {
    border-bottom: none;
}

.state-thumb {
    width: 72px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--s2);
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--mu);
}

.state-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.state-main {
    flex: 1;
    min-width: 0;
}

.state-name {
    font-weight: 700;
    font-size: 13px;
}

.state-sub {
    color: var(--mu);
    font-size: 11.5px;
}

.state-actions {
    display: flex;
    gap: 6px;
}

/* review list (backup import) */
.review-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.review-row .grow {
    flex: 1;
    min-width: 0;
}

.review-row .name {
    font-size: 13.5px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.review-row .sub {
    color: var(--mu);
    font-size: 11.5px;
}

.chip.small {
    min-height: 26px;
    padding: 3px 10px;
    font-size: 11px;
}
