/* ==========================================================================
   在线红白机（NES / FC）—— 页面样式
   复用 assets/game.css 的深色街机外壳（--gm-* 变量、.gm-topbar、.gm-foot），
   这里只管「电视 + 手柄 + 工具条」这部分。
   ========================================================================== */

.ns-wrap {
    max-width: 1360px;
    margin: 0 auto;
}

/* ===================== 电视机 ===================== */

.ns-tv {
    margin-top: 14px;
    padding: 16px;
    border-radius: 20px;
    background: linear-gradient(160deg, #1a2436 0%, #101724 58%, #0d1320 100%);
    border: 1px solid var(--gm-line);
    box-shadow:
        0 22px 60px rgba(0, 0, 0, .5),
        inset 0 1px 0 rgba(255, 255, 255, .05);
}

.ns-tv-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.ns-led {
    width: 9px; height: 9px;
    border-radius: 50%;
    background: #3d4a5f;
    box-shadow: none;
    flex: none;
    transition: background .2s, box-shadow .2s;
}
.ns-led.on {
    background: #38e07b;
    box-shadow: 0 0 10px rgba(56, 224, 123, .85);
}
.ns-led.err {
    background: #ff5d73;
    box-shadow: 0 0 10px rgba(255, 93, 115, .85);
}
.ns-tv-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--gm-text-2);
    letter-spacing: .3px;
}

/* 屏幕 */
.ns-screen-wrap {
    position: relative;
    width: 100%;
    margin: 0 auto;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 2px solid #0a0f18;
    box-shadow: inset 0 0 60px rgba(0, 0, 0, .9), 0 0 0 1px rgba(255, 255, 255, .04);
    /* 4:3 是电视机比例（NES 像素是 8:7 的）；.pixel 模式改成 256:240 方像素 */
    aspect-ratio: 4 / 3;
    max-height: calc(100vh - 250px);
}
.ns-screen-wrap.pixel { aspect-ratio: 256 / 240; }

.ns-screen {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #000;
    touch-action: none;
}
.ns-screen.smooth {
    image-rendering: auto;
    image-rendering: smooth;
}

/* 屏幕上的遮罩层 */
.ns-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 22px;
    text-align: center;
    background: rgba(6, 10, 18, .82);
    backdrop-filter: blur(2px);
    z-index: 3;
}
.ns-overlay .big { font-size: 40px; line-height: 1; }
.ns-overlay h3 { margin: 0; font-size: 17px; color: var(--gm-text); }
.ns-overlay p {
    margin: 0;
    font-size: 13px;
    line-height: 1.75;
    color: var(--gm-text-2);
    max-width: 46ch;
}
.ns-overlay code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12.5px;
    background: rgba(255, 255, 255, .08);
    border-radius: 5px;
    padding: 1px 6px;
    color: #ffd479;
}
.ns-spinner {
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, .16);
    border-top-color: var(--gm-accent);
    animation: ns-spin .75s linear infinite;
}
@keyframes ns-spin { to { transform: rotate(360deg); } }

/* 全屏：铺满整屏，让 canvas 自己 letterbox */
.ns-screen-wrap:fullscreen {
    max-height: none;
    width: 100vw;
    height: 100vh;
    aspect-ratio: auto;
    border-radius: 0;
    border: 0;
    box-shadow: none;
}
.ns-screen-wrap:fullscreen .ns-screen {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 暂停角标 */
.ns-paused-tag {
    position: absolute;
    left: 12px; top: 12px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    color: #08131f;
    background: var(--gm-gold);
    z-index: 2;
}

/* ===================== 工具条 ===================== */

.ns-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 13px;
}

.ns-tb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 38px;
    padding: 8px 15px;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--gm-text);
    background: rgba(255, 255, 255, .07);
    border: 1px solid var(--gm-line);
    border-radius: 999px;
    cursor: pointer;
    transition: background .16s, transform .16s, border-color .16s;
    white-space: nowrap;
}
.ns-tb:hover:not(:disabled) { background: rgba(255, 255, 255, .13); transform: translateY(-1px); }
.ns-tb:disabled { opacity: .45; cursor: not-allowed; }
.ns-tb.on {
    color: #08131f;
    background: linear-gradient(135deg, #57e39b, #34d399);
    border-color: transparent;
}
.ns-tb-main {
    color: #fff;
    background: linear-gradient(135deg, var(--gm-accent), var(--gm-accent-2));
    border-color: transparent;
    box-shadow: 0 8px 20px rgba(76, 141, 255, .34);
}
.ns-tb-main:hover:not(:disabled) { background: linear-gradient(135deg, #5f9bff, #8a6cff); }

.ns-spacer { flex: 1 1 auto; min-width: 0; }

/* 音量滑块 */
.ns-vol {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--gm-line);
    font-size: 12.5px;
    color: var(--gm-text-2);
    min-height: 38px;
}
.ns-vol input[type="range"] {
    width: 96px;
    accent-color: var(--gm-accent);
    cursor: pointer;
}

/* 状态小胶囊 */
.ns-chips {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 11px;
}
.ns-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--gm-text-2);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--gm-line);
    font-family: ui-monospace, Consolas, monospace;
}
.ns-chip b { color: var(--gm-text); font-weight: 800; }
.ns-chip.ok b { color: var(--gm-green); }
.ns-chip.warn { border-color: rgba(251, 191, 36, .5); }
.ns-chip.warn b { color: var(--gm-gold); }
.ns-chip.bad { border-color: rgba(255, 93, 115, .5); }
.ns-chip.bad b { color: var(--gm-red); }

/* ===================== 卡带告警 ===================== */

.ns-warn {
    margin-top: 13px;
    padding: 13px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 93, 115, .45);
    border-left-width: 5px;
    background: rgba(255, 93, 115, .1);
    font-size: 13px;
    line-height: 1.85;
    color: #ffc9d1;
}
.ns-warn b { color: #fff; }
.ns-warn code {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, .28);
    border-radius: 5px;
    padding: 1px 6px;
    color: #ffd479;
}

/* ===================== 虚拟手柄 ===================== */

.ns-pad {
    display: none;
    margin-top: 14px;
    padding: 14px;
    border-radius: 18px;
    background: linear-gradient(160deg, #18202f, #101724);
    border: 1px solid var(--gm-line);
    gap: 16px;
}
.ns-pad.show { display: flex; }
.ns-pad {
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

/* 十字键 */
.ns-dpad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
    gap: 5px;
    flex: none;
    touch-action: none;
}
.ns-dbtn, .ns-abtn {
    display: flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 800;
    color: var(--gm-text);
    background: linear-gradient(180deg, #2a3547, #1d2634);
    border: 1px solid #38465e;
    border-radius: 12px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    transition: transform .07s, background .07s;
    font-size: 15px;
}
.ns-dbtn.active, .ns-abtn.active {
    background: linear-gradient(180deg, #4c8dff, #3a6fd8);
    transform: scale(.94);
}
.ns-dbtn { font-size: 17px; }
.ns-dpad .u { grid-area: 1 / 2; }
.ns-dpad .l { grid-area: 2 / 1; }
.ns-dpad .c {
    grid-area: 2 / 2;
    background: #161d29;
    border-color: #1d2634;
    border-radius: 6px;
    pointer-events: none;
}
.ns-dpad .r { grid-area: 2 / 3; }
.ns-dpad .d { grid-area: 3 / 2; }

/* A/B 与 START/SELECT */
.ns-right {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.ns-ab {
    display: flex;
    align-items: center;
    gap: 12px;
}
.ns-abtn {
    width: 60px; height: 60px;
    border-radius: 50%;
    font-size: 16px;
}
.ns-abtn.b {
    background: linear-gradient(180deg, #ff7d8f, #e0455c);
    border-color: #ff9aa8;
    color: #fff;
}
.ns-abtn.a {
    background: linear-gradient(180deg, #ffd479, #f0a01e);
    border-color: #ffe1a1;
    color: #3a2400;
}
.ns-abtn.active { transform: scale(.92); filter: brightness(1.15); }
.ns-small {
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.ns-small button {
    min-width: 92px;
    padding: 9px 14px;
    font: inherit;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .5px;
    color: var(--gm-text);
    background: linear-gradient(180deg, #2a3547, #1d2634);
    border: 1px solid #38465e;
    border-radius: 999px;
    cursor: pointer;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.ns-small button.active { background: linear-gradient(180deg, #4c8dff, #3a6fd8); }

/* 手柄提示（1P/2P 键位） */
.ns-keys {
    margin-top: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
}
.ns-keycard {
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--gm-line);
    font-size: 12.5px;
    line-height: 2;
    color: var(--gm-text-2);
}
.ns-keycard h4 {
    margin: 0 0 6px;
    font-size: 12.5px;
    color: var(--gm-text);
    letter-spacing: .4px;
}
.ns-keycard kbd {
    display: inline-block;
    min-width: 22px;
    padding: 1px 7px;
    margin: 0 2px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 11.5px;
    color: var(--gm-text);
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .16);
    border-bottom-width: 2px;
    border-radius: 5px;
    text-align: center;
}

/* ===================== 卡带信息 ===================== */

.ns-info {
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .035);
    border: 1px solid var(--gm-line);
    font-size: 13px;
}
.ns-info > summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--gm-text);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ns-info > summary::-webkit-details-marker { display: none; }
.ns-info > summary::before { content: '▸'; color: var(--gm-text-2); transition: transform .18s; }
.ns-info[open] > summary::before { transform: rotate(90deg); }
.ns-info table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 12.5px;
}
.ns-info th, .ns-info td {
    text-align: left;
    padding: 7px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    vertical-align: top;
}
.ns-info th {
    width: 38%;
    color: var(--gm-text-2);
    font-weight: 600;
    white-space: nowrap;
}
.ns-info td {
    color: var(--gm-text);
    font-family: ui-monospace, Consolas, monospace;
    word-break: break-word;
}
.ns-info td.bad { color: var(--gm-red); font-weight: 700; }
.ns-info td.ok { color: var(--gm-green); font-weight: 700; }
.ns-info .note {
    margin-top: 10px;
    font-size: 12.5px;
    line-height: 1.85;
    color: var(--gm-text-2);
}

/* ===================== 窄屏 ===================== */

@media (max-width: 900px) {
    .ns-tv { padding: 11px; border-radius: 16px; }
    .ns-screen-wrap { max-height: none; }
    .ns-toolbar { gap: 7px; }
    .ns-tb { padding: 8px 12px; font-size: 12.5px; min-height: 40px; }
    .ns-vol { padding: 6px 12px; }
    .ns-vol input[type="range"] { width: 78px; }
    .ns-dpad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); }
    .ns-abtn { width: 54px; height: 54px; }
    .ns-pad { gap: 10px; padding: 12px; }
    .ns-right { gap: 12px; }
}

@media (max-width: 560px) {
    .ns-toolbar .ns-hides { display: none; }
    .ns-tv-title { font-size: 12.5px; }
    .ns-dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
    .ns-abtn { width: 50px; height: 50px; font-size: 14px; }
    .ns-pad { justify-content: space-between; }
    .ns-info th { width: 42%; }
}

/* 横屏手机：把手柄压扁，别把屏幕顶出视野 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
    .ns-screen-wrap { max-height: 62vh; }
    .ns-pad { padding: 9px; }
    .ns-dpad { grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(3, 38px); }
}

@media (prefers-reduced-motion: reduce) {
    .ns-tb, .ns-dbtn, .ns-abtn, .ns-spinner { transition: none !important; animation: none !important; }
}
