* {
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html,
body,
#arcade-shell {
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #07070b;
    color: #a0a0b0;
    font-family: 'Courier New', monospace;
    min-height: 100vh;
}

#arcade-shell {
    width: min(100%, 1180px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #0b0b10;
    border: 2px solid #232334;
    border-radius: 8px;
}

.control-header,
.tab-menu {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.control-header {
    border-bottom: 1px solid #232334;
    padding-bottom: 10px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.system-status {
    color: #29abe2;
    font-size: 15px;
    font-weight: bold;
}

.action-btn,
#fullscreen-btn {
    background: #151522;
    border: 1px solid #34344e;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font: bold 14px monospace;
    padding: 10px 16px;
    text-transform: uppercase;
}

.action-btn:hover,
#fullscreen-btn:hover {
    background: #23233a;
    border-color: #29abe2;
    color: #29abe2;
}

.viewport-matrix {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.screen-box,
.console-hud {
    width: 100%;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    min-height: 360px;
    aspect-ratio: 16 / 9;
    background: #000;
    border: 3px solid #1a1a26;
    border-radius: 4px;
    image-rendering: pixelated;
}

.canvas-frame {
    display: grid;
    place-items: center;
    width: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 16 / 9;
    overflow: hidden;
}

.console-hud {
    background: #06060a;
    border: 1px solid #1a1a26;
    border-radius: 4px;
}

.tab-menu {
    border-bottom: 1px solid #1a1a26;
    background: #11111a;
}

.tab-link {
    flex: 1;
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font: bold 14px monospace;
    padding: 12px;
}

.tab-link.active {
    background: #101018;
    color: #29abe2;
}

.tab-content {
    display: none;
    min-height: 86px;
    overflow-y: auto;
    padding: 14px;
    font-size: 14px;
}

.tab-content.active-content {
    display: block;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    line-height: 1.8;
}

.attribute-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 14px;
}

#attribute-radar {
    display: block;
    width: min(100%, 186px);
    height: auto;
    max-height: 140px;
    min-height: 0;
    margin: 0 auto 4px;
    aspect-ratio: 4 / 3;
    border: 0;
    image-rendering: pixelated;
}

.item-list {
    color: #fff;
    line-height: 1.8;
    margin: 0;
    padding-left: 20px;
}

.dashboard-hud {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.party-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    background: #11111a;
    border: 1px solid #1e1e2f;
    border-radius: 4px;
    padding: 10px;
    text-align: left;
    font: inherit;
}

.party-slot.selected,
.party-slot:focus-visible {
    border-color: #29abe2;
    outline: 2px solid #29abe2;
    outline-offset: 1px;
}

.party-portrait {
    width: 72px;
    height: 72px;
    flex: 0 0 auto;
    background: #000;
    image-rendering: pixelated;
    object-fit: cover;
}

.slot-info {
    flex: 1;
    min-width: 0;
}

.slot-name {
    overflow: hidden;
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hp-track {
    height: 8px;
    margin-top: 8px;
    background: #272733;
}

.hp-fill {
    height: 100%;
    background: #35e512;
}

#spell-effect {
    display: none;
}

.spell-sprite:not(#spell-effect) {
    display: none;
}

.mobile-pad-container {
    display: flex;
    justify-content: center;
    padding: 18px 0 8px;
}

.combat-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.combat-actions > strong,
.auto-toggle {
    grid-column: 1 / -1;
}

.auto-toggle {
    color: #d5d7e4;
    font-size: 14px;
}

.recruit-panel {
    display: grid;
    gap: 10px;
    background: #101018;
    border: 1px solid #2b2b41;
    border-radius: 5px;
    color: #fff;
    padding: 14px;
}

.recruit-panel[hidden] {
    display: none;
}

.recruit-panel > span {
    color: #a0a0b0;
    font-size: 13px;
}

.recruit-row {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr;
    gap: 8px;
    align-items: center;
}

.recruit-row select {
    min-height: 38px;
    background: #1c1c2a;
    border: 1px solid #34344e;
    border-radius: 3px;
    color: #fff;
    font: 14px monospace;
    padding: 6px;
}

.combat-actions[hidden] {
    display: none;
}

.interaction-actions[hidden] {
    display: none;
}

.combat-btn {
    min-height: 52px;
    background: #291b26;
    border: 2px solid #9d4052;
    border-radius: 5px;
    color: #fff;
    cursor: pointer;
    font: bold 15px monospace;
    padding: 10px;
}

.interaction-actions,
.event-log-panel {
    display: grid;
    gap: 10px;
    background: #101018;
    border: 1px solid #2b2b41;
    border-radius: 5px;
    color: #fff;
    padding: 14px;
}

.target-actions[hidden] {
    display: none;
}

.target-actions {
    display: grid;
    gap: 5px;
    background: #101018;
    border: 1px solid #2b2b41;
    border-radius: 5px;
    color: #fff;
    padding: 6px;
}

#target-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.target-btn {
    min-height: 28px;
    background: #1c1c2a;
    border: 1px solid #586174;
    border-radius: 2px;
    color: #fff;
    cursor: pointer;
    font: bold 10px monospace;
    image-rendering: pixelated;
    padding: 4px 6px;
}

.target-btn.selected {
    border-color: #f0c674;
    background: #453a24;
}

.event-log-panel {
    color: #d5d7e4;
    font-size: 13px;
}

.event-log-panel > div {
    max-height: 110px;
    overflow-y: scroll;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    scrollbar-gutter: stable;
}

.point-buy-panel {
    display: grid;
    gap: 5px;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #2b2b41;
    background: #101018;
    color: #d5d7e4;
    font-size: 11px;
}

.point-buy-panel[hidden] {
    display: none;
}

.point-buy-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: #f0c674;
}

.point-buy-rows {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
}

.point-buy-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 24px 20px 24px;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border: 1px solid #232334;
}

.point-buy-row > span {
    overflow: hidden;
    color: #a0a0b0;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.point-buy-row button {
    min-width: 24px;
    min-height: 24px;
    border: 1px solid #3d4f66;
    background: #08080d;
    color: #fff;
    cursor: pointer;
}

.point-buy-row button:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

.point-buy-row output {
    color: #3bec2d;
    text-align: center;
}

#point-buy-validation {
    margin: 0;
    color: #a0a0b0;
    font-size: 10px;
}

#point-buy-validation[data-valid="true"] {
    color: #3bec2d;
}

.inventory-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.inventory-use-btn {
    border: 1px solid #586174;
    background: #1c1c2a;
    color: #fff;
    cursor: pointer;
}

.interaction-actions span {
    display: block;
    color: #a0a0b0;
    font-size: 13px;
    margin-top: 4px;
}

.equipment-map .equipment-center {
    grid-column: 2;
    text-align: center;
}

.equipment-map .equipment-left {
    grid-column: 1;
    text-align: right;
}

.equipment-map .equipment-right {
    grid-column: 3;
}

.detail-chip {
    background: #1c1c2a;
    border: 1px solid #34344e;
    border-radius: 3px;
    padding: 6px 8px;
}

.inventory-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.inventory-item button {
    background: #263b48;
    border: 1px solid #29abe2;
    border-radius: 3px;
    color: #fff;
    cursor: pointer;
    padding: 5px 8px;
}

.interaction-actions > div {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.interaction-actions .combat-btn {
    min-height: 40px;
    padding: 8px 12px;
}

.combat-btn:hover,
.combat-btn:focus-visible {
    background: #9d4052;
    outline: 2px solid #f0c674;
    outline-offset: 2px;
}

.combat-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

#reset-btn {
    border-color: #586174;
    background: #18202b;
}

.d-pad {
    position: relative;
    width: 210px;
    height: 190px;
}

.pad-btn {
    position: absolute;
    width: 62px;
    height: 62px;
    background: #151522;
    border: 2px solid #34344e;
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 25px;
    touch-action: none;
}

.pad-btn:active {
    background: #29abe2;
    border-color: #fff;
    color: #000;
}

#touch-w { top: 0; left: 74px; }
#touch-a { top: 64px; left: 10px; }
#touch-d { top: 64px; right: 10px; }
#touch-s { bottom: 0; left: 74px; }
#touch-turn-left { top: 64px; left: -64px; }
#touch-turn-right { top: 64px; right: -64px; }

@media (max-width: 760px) {
    canvas { min-height: 0; }
    .dashboard-hud { grid-template-columns: repeat(2, 1fr); }
    .party-portrait { width: 56px; height: 56px; }
    .point-buy-rows { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 440px) {
    .dashboard-hud { grid-template-columns: 1fr; }
    .system-status { font-size: 12px; }
    .action-btn, #fullscreen-btn { font-size: 11px; padding: 8px 10px; }
    .combat-actions { grid-template-columns: repeat(2, 1fr); }
    .recruit-row { grid-template-columns: 1fr; }
}

@media (min-width: 761px) {
    #arcade-shell {
        gap: clamp(4px, 0.8vh, 10px);
        padding: clamp(4px, 0.8vw, 12px);
        height: 100vh;
        max-height: 100vh;
        overflow: hidden;
    }

    .viewport-matrix {
        display: grid;
        flex: 1 1 0;
        grid-template-columns: minmax(0, 1fr) minmax(180px, 22%);
        grid-template-rows: minmax(0, 1fr) auto auto;
        gap: clamp(3px, 0.5vw, 7px);
        min-height: 0;
        max-height: 100%;
        overflow: hidden;
    }

    .screen-box {
        display: grid;
        grid-column: 1;
        grid-row: 1;
        grid-template-rows: minmax(0, 1fr) auto;
        min-width: 0;
        min-height: 0;
        place-items: center;
    }

    .canvas-frame {
        grid-row: 1;
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
        container-type: size;
    }

    .screen-box canvas {
        width: min(100cqw, calc(100cqh * 16 / 9));
        height: min(100cqh, calc(100cqw * 9 / 16));
        max-width: 100%;
        max-height: 100%;
        min-height: 0;
        aspect-ratio: 16 / 9;
    }

    #fighter-posture-slice-tray {
        grid-column: 1;
        grid-row: 3;
        align-self: end;
        margin: 0;
        flex-shrink: 0;
    }

    .class-carousel {
        grid-column: 1;
        grid-row: 2;
    }

    .point-buy-panel {
        grid-column: 1;
        grid-row: 3;
    }

    .recruit-actions {
        grid-column: 1;
        grid-row: 4;
    }

    .console-hud {
        grid-column: 2;
        grid-row: 1 / span 3;
        min-width: 0;
        min-height: 0;
        overflow-y: auto;
    }

    .mobile-pad-container {
        display: none;
    }

    .event-log-panel {
        flex: 0 0 auto;
        max-height: 20vh;
        min-height: 0;
        gap: 4px;
        padding: 6px 10px;
        overflow: hidden;
    }

    .event-log-panel > div {
        max-height: 20vh;
        overflow-y: scroll;
    }

    .combat-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 5px;
    }

    .combat-actions .combat-btn,
    .interaction-actions .combat-btn {
        min-height: 30px;
        padding: 4px;
        font-size: 10px;
        border-width: 1px;
        border-radius: 2px;
        image-rendering: pixelated;
    }

    .target-btn {
        min-height: 24px;
        padding: 3px 5px;
        font-size: 9px;
        border-width: 1px;
        border-radius: 2px;
        image-rendering: pixelated;
    }

    .tab-content {
        min-height: 0;
        max-height: 28vh;
        padding: 6px;
        font-size: 11px;
    }

    #attribute-radar {
        width: min(100%, 160px);
        max-height: 120px;
    }

    .recruit-panel {
        gap: 5px;
        padding: 8px;
        font-size: 11px;
    }

    .recruit-row {
        grid-template-columns: 1fr 1.2fr 0.8fr;
        gap: 4px;
    }

    .recruit-row select {
        min-height: 30px;
        font-size: 11px;
    }

    .dashboard-hud {
        flex: 0 0 auto;
        gap: 6px;
    }
}
