#game-menu-root {
    position: absolute;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#game-menu-root.open {
    pointer-events: auto;
}

[data-menu-backdrop] {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0.78) 100%);
    backdrop-filter: blur(3px);
}

.game-menu-panel {
    position: relative;
    z-index: 1;
    /* ไม่เกินความกว้างจอเกมแนวตั้ง (~320px) */
    width: min(92vw, 320px);
    max-width: 100%;
    max-height: min(90vh, 640px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 10px 8px;
    box-sizing: border-box;
    background: linear-gradient(168deg, #3d3026 0%, #1e1814 48%, #120e0c 100%);
    border: 2px solid #6b5344;
    box-shadow:
        0 0 28px rgba(0, 0, 0, 0.55),
        0 0 20px var(--px-glow-gold),
        inset 0 1px 0 rgba(255, 220, 160, 0.12);
}

.game-menu-header {
    text-align: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(212, 175, 55, 0.22);
}

.game-menu-title {
    margin: 0;
    font-size: var(--text-lg);
    color: var(--px-gold);
    letter-spacing: 0.04em;
}

.game-menu-subtitle {
    margin: 4px 0 0;
    font-size: var(--text-xs);
    color: rgba(255, 235, 200, 0.55);
}

.game-menu-section {
    margin-bottom: 8px;
}

.game-menu-section--system {
    margin-bottom: 6px;
}

.game-menu-section-label {
    margin: 0 0 4px;
    padding-left: 2px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(212, 175, 55, 0.75);
}

.game-menu-grid {
    display: grid;
    gap: 5px;
}

.game-menu-grid--play,
.game-menu-grid--system {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.game-menu-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.game-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--touch-min);
    padding: 6px 10px;
    border: 2px solid #4a3a2e;
    border-radius: 0;
    background: linear-gradient(180deg, #4a3d32 0%, #2a221c 100%);
    color: #f5e6c8;
    font-family: inherit;
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    box-shadow:
        0 2px 0 #1a1410,
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transition: filter 0.12s ease, transform 0.08s ease;
}

.game-menu-item:hover,
.game-menu-item:focus-visible {
    filter: brightness(1.12);
    outline: none;
}

.game-menu-item:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 #1a1410;
}

.game-menu-item:disabled,
.game-menu-item.is-disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
    filter: none;
}

.game-menu-item.is-active {
    border-color: rgba(212, 175, 55, 0.7);
    box-shadow:
        0 2px 0 #1a1410,
        inset 0 0 0 1px rgba(212, 175, 55, 0.28),
        0 0 14px rgba(212, 175, 55, 0.2);
}

.game-menu-item--wide {
    width: 100%;
}

a.game-menu-item--link {
    text-decoration: none;
    box-sizing: border-box;
}

.game-menu-item-icon {
    flex-shrink: 0;
    width: 1.4em;
    font-size: 1.1em;
    line-height: 1;
    text-align: center;
}

.game-menu-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.game-menu-item-label {
    flex: 1;
    min-width: 0;
    font-weight: bold;
    line-height: 1.25;
}

.game-menu-item-hint {
    font-size: 10px;
    color: rgba(255, 235, 200, 0.5);
    line-height: 1.2;
}

.game-menu-kbd {
    flex-shrink: 0;
    min-width: 1.6em;
    padding: 3px 6px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    border-radius: 2px;
    background: linear-gradient(180deg, #2a2420 0%, #1a1614 100%);
    color: rgba(255, 235, 200, 0.85);
    font-family: inherit;
    font-size: 11px;
    font-weight: bold;
    line-height: 1;
    text-align: center;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.game-menu-kbd--accent {
    border-color: rgba(212, 175, 55, 0.55);
    color: var(--px-gold);
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.25);
}

.game-menu-kbd--sm {
    min-width: auto;
    padding: 2px 5px;
    font-size: 10px;
}

.game-menu-settings-panel {
    padding: 10px;
    border: 1px solid rgba(212, 175, 55, 0.35);
    background: linear-gradient(180deg, rgba(38, 30, 24, 0.92) 0%, rgba(24, 19, 16, 0.96) 100%);
}

.game-menu-settings-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.game-menu-settings-tab {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 36px;
    padding: 6px 8px;
    font-size: var(--text-xs);
    color: rgba(255, 235, 200, 0.75);
    background: rgba(20, 16, 12, 0.65);
    border: 1px solid rgba(212, 175, 55, 0.22);
    border-radius: 6px;
    cursor: pointer;
}

.game-menu-settings-tab.is-active {
    color: var(--px-gold);
    border-color: rgba(212, 175, 55, 0.65);
    background: linear-gradient(180deg, rgba(56, 44, 28, 0.95) 0%, rgba(32, 24, 16, 0.95) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 220, 140, 0.12);
}

.game-menu-settings-pane[hidden] {
    display: none !important;
}

.game-menu-setting-hint {
    margin: 0 0 10px;
    font-size: 11px;
    line-height: 1.4;
    color: rgba(210, 190, 160, 0.65);
}

.game-menu-settings-view {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.game-menu-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.game-menu-setting-row--toggle {
    margin-top: 8px;
    margin-bottom: 0;
    padding-top: 8px;
    border-top: 1px solid rgba(212, 175, 55, 0.14);
}

.game-menu-settings-pane > .game-menu-setting-row--toggle:first-of-type {
    margin-top: 4px;
}

.game-menu-setting-section-label {
    margin: 0 0 8px;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--px-gold);
}

.game-menu-setting-label {
    font-size: var(--text-xs);
    color: rgba(255, 235, 200, 0.88);
    line-height: 1.35;
}

.game-menu-setting-value {
    min-width: 3.2em;
    text-align: right;
    font-size: var(--text-xs);
    color: var(--px-gold);
}

.game-menu-toggle-btn {
    min-width: 4.2em;
    min-height: 36px;
    padding: 6px 12px;
    font-size: var(--text-xs);
    flex-shrink: 0;
}

.game-menu-toggle-btn.is-on {
    border-color: rgba(212, 175, 55, 0.65);
    color: var(--px-gold);
}

.game-menu-mute-btn {
    min-width: 32px;
    min-height: 28px;
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
    margin-left: 4px;
    cursor: pointer;
}
.game-menu-mute-btn.is-muted {
    opacity: 0.5;
}

.game-menu-volume-slider {
    width: 100%;
    accent-color: #d4af37;
    margin-bottom: 4px;
}

.game-menu-settings-back {
    width: 100%;
}

.game-menu-panel.is-settings-view .game-menu-header,
.game-menu-panel.is-settings-view .game-menu-footer {
    display: none;
}

.game-menu-panel.is-settings-view {
    max-height: min(90vh, 680px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.game-menu-settings-view .inv-header-row {
    margin-bottom: 0;
}

.game-menu-setting-section-label {
    margin: 0 0 6px;
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: rgba(212, 175, 55, 0.75);
}

.game-menu-account-block {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(212, 175, 55, 0.22);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-menu-account-hint {
    margin: 0;
    font-size: 11px;
    color: rgba(255, 235, 200, 0.55);
    line-height: 1.4;
}

.game-menu-account-open {
    width: 100%;
    min-height: var(--touch-min);
}

.game-menu-footer {
    margin-top: 2px;
    padding-top: 8px;
    border-top: 1px solid rgba(212, 175, 55, 0.15);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
}

.game-menu-close {
    width: 100%;
    min-height: var(--touch-min);
}

.game-menu-footer-hint {
    margin: 0;
    text-align: center;
    font-size: 10px;
    color: rgba(255, 235, 200, 0.45);
}

/* ช่องกริด 3 คอลัมน์ — ไอคอน + ป้ายกลาง บีบให้พอดีแผง 320px */
.game-menu-grid--play .game-menu-item,
.game-menu-grid--system .game-menu-item {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 56px;
    padding: 6px 4px 5px;
    text-align: center;
}

.game-menu-grid--play .game-menu-item-icon,
.game-menu-grid--system .game-menu-item-icon {
    width: auto;
    font-size: 1.15em;
}

.game-menu-grid--play .game-menu-item-label,
.game-menu-grid--system .game-menu-item-label {
    flex: none;
    width: 100%;
    font-size: 10px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-menu-grid--play .game-menu-kbd,
.game-menu-grid--system .game-menu-kbd {
    margin-top: 0;
    min-width: 1.35em;
    padding: 2px 4px;
    font-size: 10px;
}

/* ฉากเปิด intro_road — ESC เหลือแค่หมวด「ระบบ」 */
html.ui-intro-road .game-menu-section:not(.game-menu-section--system) {
    display: none;
}

html.ui-intro-road .game-menu-subtitle {
    display: none;
}

