/* controls.css — Sharp MZ-800 WebAssembly Player Styling */
:root {
    --bg-color: #121316;
    --panel-bg: #1c1e24;
    --panel-border: #2d313b;
    --accent-red: #d03400;
    --accent-blue: #24ccff;
    --accent-green: #54ff54;
    --text-primary: #e6e8ee;
    --text-muted: #8a8f9d;
    --btn-bg: #272a33;
    --btn-hover: #333845;
    --btn-active: #d03400;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, monospace;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-height: 100%;
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}


/* Toolbar Header */
#toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    z-index: 30;
    gap: 8px;
    box-sizing: border-box;
    width: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.brand .logo-badge {
    background: linear-gradient(135deg, #c02000, #ff5020);
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 800;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.btn-text-full {
    display: inline;
}

.btn {
    background-color: var(--btn-bg);
    color: var(--text-primary);
    border: 1px solid var(--panel-border);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.15s, border-color 0.15s, transform 0.05s;
}

.btn:hover {
    background-color: var(--btn-hover);
    border-color: #4a5163;
}

.btn:active {
    background-color: var(--btn-active);
    transform: scale(0.97);
}

.btn.active {
    background-color: #d03400;
    border-color: #ff5020;
    color: #fff;
}

select.btn-select {
    background-color: var(--btn-bg);
    color: var(--text-primary);
    border: 1px solid var(--panel-border);
    padding: 5px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

select.btn-select:hover {
    background-color: var(--btn-hover);
}

/* Screen Area */
#screen-viewport {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #000;
    overflow: hidden;
    padding: 6px;
}

.crt-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(0, 0, 0, 0.7);
    border-radius: 6px;
    overflow: hidden;
    background-color: #000;
    max-width: 100%;
    max-height: 100%;
    transition: width 0.15s ease, height 0.15s ease;
}

#mz-canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background-color: #000;
}

/* CRT Scanline Overlay */
.crt-scanlines::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.3) 50%);
    background-size: 100% 4px;
    z-index: 2;
    pointer-events: none;
    opacity: 0.6;
}

/* Status Overlay */
#status-overlay {
    position: absolute;
    top: 10px;
    left: 12px;
    background: rgba(18, 19, 22, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.72rem;
    font-family: monospace;
    display: flex;
    gap: 10px;
    z-index: 5;
    pointer-events: none;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #555;
}

.status-dot.active {
    background-color: var(--accent-green);
    box-shadow: 0 0 6px var(--accent-green);
}

/* Virtual Game Controller Overlay */
#touch-controller {
    position: relative;
    width: 100%;
    flex-shrink: 0;
    height: auto;
    min-height: calc(150px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to bottom, #181a20, #101115);
    border-top: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px max(14px, calc(8px + env(safe-area-inset-bottom, 0px))) 20px;
    touch-action: none;
    user-select: none;
    z-index: 8;
    box-sizing: border-box;
}


/* Left: D-Pad Container */
.dpad-container {
    position: relative;
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.dpad-btn {
    position: absolute;
    z-index: 2;
    background: #2b2e38;
    border: 2px solid #3c4150;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    cursor: pointer;
    color: #a8b0c2;
    font-size: 1.2rem;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 3px 6px rgba(0,0,0,0.4);
    transition: background 0.05s, transform 0.05s;
}

.dpad-btn:active, .dpad-btn.pressed {
    background: #d03400;
    color: #fff;
    border-color: #ff5020;
    transform: scale(0.94);
}

.dpad-up {
    top: 0;
    left: 48px;
    width: 44px;
    height: 48px;
    border-radius: 8px 8px 2px 2px;
}

.dpad-down {
    bottom: 0;
    left: 48px;
    width: 44px;
    height: 48px;
    border-radius: 2px 2px 8px 8px;
}

.dpad-left {
    top: 48px;
    left: 0;
    width: 48px;
    height: 44px;
    border-radius: 8px 2px 2px 8px;
}

.dpad-right {
    top: 48px;
    right: 0;
    width: 48px;
    height: 44px;
    border-radius: 2px 8px 8px 2px;
}

.dpad-center {
    position: absolute;
    z-index: 1;
    top: 48px;
    left: 48px;
    width: 44px;
    height: 44px;
    background: #23262f;
    border: 1px solid #343946;
    border-radius: 4px;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad-center::after {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #1c1e24;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
}

/* Center: Auxiliary / System Keys (BREAK, CR/ENTER, SPACE) */
.center-keys {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: center;
    min-width: 95px;
    max-width: 125px;
    flex-shrink: 0;
    margin: 0 4px;
}

.sys-btn {
    background: #272a33;
    color: #9da4b4;
    border: 1px solid #3c4150;
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    touch-action: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    width: 100%;
    text-align: center;
}

.sys-btn:active, .sys-btn.pressed {
    background: #474c5d;
    color: #fff;
    border-color: #8a94ac;
    transform: scale(0.95);
}

.sys-btn-wide {
    width: 100%;
    min-width: 95px;
    text-align: center;
    border-radius: 8px;
    padding: 8px 14px;
}

/* BREAK: Isolated at top of center column, far from D-pad and Action buttons */
.danger-btn {
    background: rgba(168, 28, 28, 0.3);
    color: #ff9999;
    border: 1px solid rgba(255, 60, 60, 0.45);
    border-radius: 12px;
    padding: 3px 12px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    cursor: pointer;
    touch-action: none;
    opacity: 0.8;
    transition: background 0.1s, opacity 0.1s, transform 0.05s;
}

.danger-btn:active, .danger-btn.pressed {
    background: #c02020;
    border-color: #ff4444;
    color: #fff;
    opacity: 1;
    transform: scale(0.94);
}

/* Right: Action Buttons (A, B) */
.action-buttons-container {
    position: relative;
    width: 140px;
    height: 140px;
}

.act-btn {
    position: absolute;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2f3440, #22252e);
    border: 2px solid #434a5c;
    color: #e6e8ee;
    font-size: 1.1rem;
    font-weight: 800;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    touch-action: none;
    cursor: pointer;
    box-shadow: inset 0 2px 0 rgba(255,255,255,0.15), 0 4px 8px rgba(0,0,0,0.5);
    transition: background 0.05s, transform 0.05s;
}

.act-btn span.label {
    font-size: 0.55rem;
    font-weight: 600;
    color: #8c93a4;
    text-transform: uppercase;
}

.act-btn:active, .act-btn.pressed {
    background: linear-gradient(135deg, #d03400, #f05420);
    border-color: #ff7040;
    color: #fff;
    transform: scale(0.92);
}

.act-btn:active span.label, .act-btn.pressed span.label {
    color: #ffd0c0;
}

/* Button Positions */
.act-btn-a {
    bottom: 8px;
    right: 8px;
}

.act-btn-b {
    top: 8px;
    right: 56px;
}

/* "More" toolbar toggle — hidden on wide screens where everything fits inline */
.toolbar-more-btn {
    display: none;
}

/* Mobile & Fullscreen Adjustments */
@media (max-width: 600px) {
    #touch-controller {
        height: auto;
        min-height: calc(134px + env(safe-area-inset-bottom, 0px));
        padding-top: 6px;
        padding-bottom: max(14px, calc(6px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(12px, calc(6px + env(safe-area-inset-left, 0px)));
        padding-right: max(12px, calc(6px + env(safe-area-inset-right, 0px)));
    }

    .dpad-container {
        width: 120px;
        height: 120px;
    }
    .dpad-up, .dpad-down {
        left: 40px;
        width: 40px;
        height: 40px;
    }
    .dpad-left, .dpad-right {
        top: 40px;
        width: 40px;
        height: 40px;
    }
    .dpad-center {
        top: 40px;
        left: 40px;
        width: 40px;
        height: 40px;
    }
    .action-buttons-container {
        width: 120px;
        height: 120px;
    }
    .act-btn {
        width: 48px;
        height: 48px;
    }
    .act-btn-b {
        right: 48px;
    }
    .center-keys {
        min-width: 85px;
        max-width: 105px;
        gap: 6px;
    }
    .sys-btn-wide {
        min-width: 85px;
        padding: 7px 10px;
        font-size: 0.7rem;
    }
    .sys-btn {
        padding: 5px 8px;
        font-size: 0.68rem;
    }
    .danger-btn {
        padding: 3px 10px;
        font-size: 0.62rem;
    }
}

/* Very narrow phones (<= 380px width) */
@media (max-width: 380px) {
    #touch-controller {
        height: auto;
        min-height: calc(122px + env(safe-area-inset-bottom, 0px));
        padding-top: 4px;
        padding-bottom: max(12px, calc(4px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(8px, calc(4px + env(safe-area-inset-left, 0px)));
        padding-right: max(8px, calc(4px + env(safe-area-inset-right, 0px)));
    }
    .dpad-container {
        width: 110px;
        height: 110px;
    }
    .dpad-up, .dpad-down {
        left: 36px;
        width: 38px;
        height: 38px;
    }
    .dpad-left, .dpad-right {
        top: 36px;
        width: 38px;
        height: 38px;
    }
    .dpad-center {
        top: 36px;
        left: 36px;
        width: 38px;
        height: 38px;
    }
    .action-buttons-container {
        width: 110px;
        height: 110px;
    }
    .act-btn {
        width: 44px;
        height: 44px;
    }
    .act-btn-b {
        right: 44px;
    }
    .center-keys {
        min-width: 76px;
        max-width: 88px;
        gap: 5px;
    }
    .sys-btn-wide {
        min-width: 76px;
        padding: 5px 6px;
        font-size: 0.65rem;
    }
    .sys-btn {
        padding: 4px 6px;
        font-size: 0.62rem;
    }
    .danger-btn {
        padding: 2px 8px;
        font-size: 0.6rem;
    }
}

/* Landscape phones: the controller bar competes with a very short viewport */
@media (max-height: 500px) {
    #touch-controller {
        height: auto;
        min-height: calc(108px + env(safe-area-inset-bottom, 0px));
        padding-top: 4px;
        padding-bottom: max(8px, calc(4px + env(safe-area-inset-bottom, 0px)));
        padding-left: max(18px, calc(8px + env(safe-area-inset-left, 0px)));
        padding-right: max(18px, calc(8px + env(safe-area-inset-right, 0px)));
    }

    .danger-btn {
        padding: 2px 8px;
        font-size: 0.58rem;
    }
    .dpad-container {
        width: 100px;
        height: 100px;
    }
    .dpad-up, .dpad-down {
        left: 32px;
        width: 36px;
        height: 32px;
    }
    .dpad-left, .dpad-right {
        top: 32px;
        width: 32px;
        height: 36px;
    }
    .dpad-center {
        top: 32px;
        left: 32px;
        width: 36px;
        height: 36px;
    }
    .action-buttons-container {
        width: 100px;
        height: 100px;
    }
    .act-btn {
        width: 42px;
        height: 42px;
    }
    .act-btn-b {
        right: 42px;
    }
    .center-keys {
        gap: 4px;
        min-width: 80px;
        max-width: 100px;
    }
    .sys-btn-wide {
        padding: 4px 8px;
        font-size: 0.65rem;
        min-width: 80px;
    }
    .sys-btn {
        padding: 3px 6px;
        font-size: 0.62rem;
    }
}

/* Compact toolbar on mobile/tablets: collapse secondary actions behind ⚙️ */
@media (max-width: 768px) {
    #toolbar {
        padding: 4px 6px;
        gap: 4px;
        position: relative;
        flex-wrap: nowrap;
        overflow: visible;
    }
    .brand {
        flex-shrink: 0;
    }
    .brand .logo-svg {
        height: 18px;
        max-width: 60px;
    }
    #toolbar .btn {
        padding: 4px 6px;
        font-size: 0.74rem;
        gap: 2px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .toolbar-group {
        gap: 4px;
        flex-wrap: nowrap;
    }
    .toolbar-primary {
        flex-wrap: nowrap;
        flex-shrink: 1;
    }
    .toolbar-more-btn {
        display: inline-flex;
        flex-shrink: 0;
    }
    .toolbar-more-btn.active {
        background-color: #d03400;
        border-color: #ff5020;
        color: #fff;
    }
    .btn-text-full {
        display: none;
    }
    .toolbar-secondary {
        display: none;
        position: absolute;
        top: 100%;
        right: 4px;
        margin-top: 5px;
        flex-direction: column;
        align-items: stretch;
        background: #1c1f26;
        border: 1px solid var(--panel-border);
        border-radius: 8px;
        padding: 6px;
        gap: 5px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.85);
        z-index: 100;
        min-width: 180px;
    }
    .toolbar-secondary.open {
        display: flex !important;
    }
    .toolbar-secondary .btn {
        width: 100%;
        justify-content: flex-start;
        padding: 7px 10px;
        font-size: 0.78rem;
        box-sizing: border-box;
        border-radius: 4px;
        text-align: left;
    }
}

@media (max-width: 420px) {
    #toolbar {
        padding: 3px 4px;
        gap: 2px;
    }
    .brand .logo-svg {
        height: 16px;
        max-width: 50px;
    }
    #toolbar .btn {
        padding: 3px 5px;
        font-size: 0.71rem;
    }
    .toolbar-group {
        gap: 2px;
    }
}

/* Floating overlay mode when fullscreen or keyboard present */
body.hide-controls #touch-controller {
    display: none !important;
}

/* Debug & Error Modal */
.hidden,
.modal-overlay.hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    max-width: 650px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    font-size: 13.5px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--panel-border);
    background: #232730;
}

.modal-title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ff9944;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    line-height: 1.5;
}

.modal-log-box {
    background: #0d0e11;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11.5px;
    max-height: 160px;
    overflow-y: auto;
    color: #a0a6b5;
    white-space: pre-wrap;
    word-break: break-all;
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.modal-btn {
    padding: 8px 14px;
    border-radius: 4px;
    border: 1px solid var(--panel-border);
    background: var(--btn-bg);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.modal-btn:hover {
    background: var(--btn-hover);
}

.modal-btn-primary {
    background: var(--accent-red);
    border-color: #e04410;
    color: #fff;
    font-weight: 500;
}

.modal-btn-primary:hover {
    background: #e04410;
}

/* PWA Update Banner & Install Button */
.update-banner {
    width: 100%;
    background: linear-gradient(90deg, #1c202a 0%, #252b3a 100%);
    border-bottom: 2px solid var(--accent-red);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    padding: 6px 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    z-index: 50;
}

.update-banner.hidden {
    display: none !important;
}

.update-banner-content {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}

.update-banner-icon {
    font-size: 1rem;
    animation: pwa-pulse 1.5s infinite;
}

@keyframes pwa-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.update-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-update {
    background-color: var(--accent-red) !important;
    border-color: #ff4820 !important;
    color: #fff !important;
    font-weight: 700 !important;
    padding: 4px 10px !important;
    font-size: 0.78rem !important;
    cursor: pointer;
    touch-action: manipulation;
}

.btn-update:hover {
    background-color: #e03800 !important;
}

.btn-dismiss {
    background: transparent !important;
    border: none !important;
    color: var(--text-muted) !important;
    font-size: 1.1rem !important;
    padding: 2px 6px !important;
    cursor: pointer;
    touch-action: manipulation;
}

.btn-dismiss:hover {
    color: var(--text-primary) !important;
}

#btn-pwa-install {
    background: linear-gradient(135deg, #1f3b58, #184c78);
    border-color: #2b70a8;
    color: #64d2ff;
}

#btn-pwa-install:hover {
    background: linear-gradient(135deg, #25476a, #1d5b90);
}

/* ==========================================================================
   Sharp MZ-800 Virtual Keyboard Styling
   Authentic vintage Japanese microcomputer aesthetic with mobile ergonomics
   ========================================================================== */

#virtual-keyboard {
    position: relative;
    width: 100%;
    flex-shrink: 0;
    background: linear-gradient(to bottom, #1a1c22 0%, #111216 100%);
    border-top: 1px solid var(--panel-border);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    padding: 6px 10px max(10px, calc(6px + env(safe-area-inset-bottom, 0px))) 10px;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    z-index: 9;
    box-sizing: border-box;
}

#virtual-keyboard.hidden {
    display: none !important;
}

/* Header & Status Bar */
.vkbd-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px 4px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 4px;
}

.vkbd-status-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.vkbd-title {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.8px;
    color: #7b8292;
    text-transform: uppercase;
}

.vkbd-indicator {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    background: #23262f;
    color: #555b6a;
    border: 1px solid #303542;
    transition: all 0.15s ease;
}

.vkbd-indicator.active {
    background: #d03400;
    color: #fff;
    border-color: #ff5020;
    box-shadow: 0 0 6px rgba(208, 52, 0, 0.6);
}

.vkbd-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.vkbd-hdr-btn {
    background: #272a33;
    border: 1px solid #3c4150;
    color: #c4c9d6;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    touch-action: manipulation;
    transition: background 0.1s, border-color 0.1s;
}

.vkbd-hdr-btn:hover {
    background: #363b47;
    border-color: #4f576a;
}

.vkbd-close-btn {
    color: #ff7777;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 1px 7px;
}

.vkbd-close-btn:hover {
    background: #4a2424;
    color: #ffaaaa;
}

/* Key Matrix & Rows */
.vkbd-matrix {
    display: flex;
    flex-direction: column;
    gap: 3.5px;
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
}

.vk-row {
    display: flex;
    width: 100%;
    gap: 3.5px;
    justify-content: space-between;
}

.vk-spacer {
    flex: 0.8;
    min-width: 4px;
}

/* Keycaps: Authentic Sharp MZ-800 Styling */
.vk-key {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    height: 38px;
    border-radius: 4px;
    border: 1px solid #8e95a5;
    border-bottom: 2px solid #5a6070;
    background: linear-gradient(to bottom, #f3f5f8 0%, #d8dce4 100%);
    color: #17181d;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    touch-action: none;
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
    padding: 0 1px;
    transition: transform 0.04s, background 0.05s, border-color 0.05s;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    box-sizing: border-box;
}

.vk-key:active, .vk-key.pressed {
    transform: translateY(2px);
    border-bottom-width: 1px;
    background: #b2b8c6;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}

.vk-main {
    line-height: 1;
    pointer-events: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
    text-align: center;
}

.vk-sub {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.55rem;
    font-weight: 600;
    color: #636b7b;
    pointer-events: none;
    line-height: 1;
    transition: color 0.15s, transform 0.15s;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 85%;
}

.vk-lbl-short {
    display: none;
}
.vk-lbl-full {
    display: inline;
}

/* Special & Modifier Keys (Dark Gray) */
.vk-special {
    background: linear-gradient(to bottom, #393d4a 0%, #262933 100%);
    color: #e4e7ef;
    border-color: #4a5060;
    border-bottom-color: #1d2028;
}

.vk-special .vk-sub {
    color: #98a0b2;
}

.vk-special:active, .vk-special.pressed {
    background: #1c1e26;
    border-color: #2e3340;
}

/* Function Keys (F1-F5) with Sharp Blue label */
.vk-fn {
    background: linear-gradient(to bottom, #2d323f 0%, #1e222b 100%);
    color: #24ccff;
    border-color: #3b4252;
    border-bottom-color: #15181f;
    height: 27px;
    font-size: 0.72rem;
}

.vk-fn:active, .vk-fn.pressed {
    background: #171a22;
    color: #6ee7b7;
}

/* BREAK key with Red accent */
.vk-break {
    background: linear-gradient(to bottom, #4c2222 0%, #351717 100%);
    color: #ffa0a0;
    border-color: #6e3030;
    border-bottom-color: #250f0f;
    height: 27px;
    font-size: 0.68rem;
}

.vk-break:active, .vk-break.pressed {
    background: #c02020;
    color: #fff;
    border-color: #ff5050;
}

.vk-row-0 .vk-special {
    height: 27px;
    font-size: 0.68rem;
}

/* Specific key flex widths */
.vk-tab { flex: 1.35; }
.vk-cr { flex: 1.65; color: #24ccff; font-weight: 800; }
.vk-mod-graph { flex: 1.35; }
.vk-mod-ctrl { flex: 1.35; }
.vk-shift-l { flex: 1.45; }
.vk-mod-alpha { flex: 1.35; }
.vk-shift-r { flex: 1.7; }
.vk-space { flex: 6; height: 36px; }

/* Multi-character key label typography scaling */
.vk-mod-shift .vk-main,
.vk-mod-alpha .vk-main,
.vk-mod-graph .vk-main,
.vk-mod-ctrl .vk-main,
.vk-break .vk-main {
    font-size: 0.66rem;
    letter-spacing: -0.2px;
}

/* Cursor Navigation Cluster */
.vk-cursor-cluster {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 3;
    justify-content: flex-end;
}

.vk-cursor-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    height: 36px;
}

.vk-cursor-col .vk-cursor {
    height: 17px;
    font-size: 0.55rem;
}

.vk-cursor {
    flex: 1;
    height: 36px;
    background: linear-gradient(to bottom, #393d4a 0%, #262933 100%);
    color: #a8b0c2;
    border: 1px solid #4a5060;
    border-bottom: 2px solid #1d2028;
    font-size: 0.75rem;
}

/* Sticky / Latching Modifier Feedback */
.vk-key.latched {
    background: linear-gradient(to bottom, #f57c00 0%, #e65100 100%) !important;
    border-color: #ff9800 !important;
    color: #fff !important;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.7) !important;
}

.vk-key.locked {
    background: linear-gradient(to bottom, #e53935 0%, #b71c1c 100%) !important;
    border-color: #ff5252 !important;
    color: #fff !important;
    box-shadow: 0 0 12px rgba(244, 67, 54, 0.85) !important;
}

/* Shifted View dynamic highlights */
.vkbd-container.vkbd-shifted .vk-sub {
    color: #d03400;
    font-weight: 800;
    transform: scale(1.15);
}

/* Responsive adjustments for mobile screens */
@media (max-width: 600px) {
    .vk-lbl-short {
        display: inline !important;
    }
    .vk-lbl-full {
        display: none !important;
    }

    .vk-mod-shift .vk-main,
    .vk-mod-alpha .vk-main,
    .vk-mod-graph .vk-main,
    .vk-mod-ctrl .vk-main,
    .vk-break .vk-main {
        font-size: 0.54rem;
        letter-spacing: -0.3px;
    }

    #virtual-keyboard {
        padding: 4px 6px max(8px, calc(4px + env(safe-area-inset-bottom, 0px))) 6px;
    }
    .vkbd-matrix {
        gap: 2.5px;
    }
    .vk-row {
        gap: 2.5px;
    }
    .vk-key {
        height: 34px;
        font-size: 0.72rem;
        border-radius: 3px;
    }
    .vk-key .vk-sub {
        font-size: 0.48rem;
        top: 1.5px;
        left: 2px;
    }
    .vk-fn, .vk-row-0 .vk-special, .vk-break {
        height: 23px;
        font-size: 0.6rem;
    }
    .vk-space {
        height: 33px;
    }
    .vk-cursor-col {
        height: 33px;
    }
    .vk-cursor-col .vk-cursor {
        height: 15.5px;
        font-size: 0.5rem;
    }
    .vk-cursor {
        height: 33px;
        font-size: 0.68rem;
    }
}

@media (max-width: 380px) {
    .vk-mod-shift .vk-main,
    .vk-mod-alpha .vk-main,
    .vk-mod-graph .vk-main,
    .vk-mod-ctrl .vk-main,
    .vk-break .vk-main {
        font-size: 0.48rem;
        letter-spacing: -0.4px;
    }

    #virtual-keyboard {
        padding: 3px 4px max(6px, calc(3px + env(safe-area-inset-bottom, 0px))) 4px;
    }
    .vkbd-matrix {
        gap: 2px;
    }
    .vk-row {
        gap: 2px;
    }
    .vk-key {
        height: 30px;
        font-size: 0.65rem;
        border-radius: 2.5px;
    }
    .vk-key .vk-sub {
        font-size: 0.42rem;
        top: 1px;
        left: 1.5px;
    }
    .vk-fn, .vk-row-0 .vk-special, .vk-break {
        height: 21px;
        font-size: 0.55rem;
    }
    .vk-space {
        height: 29px;
    }
    .vk-cursor-col {
        height: 29px;
    }
    .vk-cursor-col .vk-cursor {
        height: 13.5px;
    }
    .vk-cursor {
        height: 29px;
    }
    .vkbd-title {
        display: none;
    }
}

/* Landscape mobile orientation: preserve maximal CRT screen height */
@media (max-height: 500px) {
    #virtual-keyboard {
        padding: 3px 8px max(6px, calc(3px + env(safe-area-inset-bottom, 0px))) 8px;
    }
    .vkbd-header {
        padding-bottom: 2px;
        margin-bottom: 2px;
    }
    .vkbd-matrix {
        gap: 2px;
    }
    .vk-row {
        gap: 2px;
    }
    .vk-key {
        height: 24px;
        font-size: 0.65rem;
        border-radius: 3px;
    }
    .vk-key .vk-sub {
        font-size: 0.45rem;
        top: 1px;
        left: 2px;
    }
    .vk-fn, .vk-row-0 .vk-special, .vk-break {
        height: 18px;
        font-size: 0.52rem;
    }
    .vk-space {
        height: 24px;
    }
    .vk-cursor-col {
        height: 24px;
    }
    .vk-cursor-col .vk-cursor {
        height: 11px;
        font-size: 0.45rem;
    }
    .vk-cursor {
        height: 24px;
        font-size: 0.62rem;
    }
}



