*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #060b19;
    color: #f8fafc;
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

.is-hidden {
    display: none !important;
}

.studio-app {
    position: relative;
    width: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: radial-gradient(circle at 20% 0%, #172554 0%, #090e1f 65%);
}

/* 顶部紧凑功能栏 (50px，适配 iPad 窄分屏) */
.studio-topbar {
    flex: 0 0 50px;
    height: 50px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: rgba(15, 23, 42, 0.92);
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 30;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}

.studio-logo {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #22c55e, #0ea5e9);
    font-size: 19px;
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.35);
}

.studio-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 9px;
    display: block;
}

.shelf-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
    height: 34px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(74, 222, 128, 0.4);
    background: rgba(30, 41, 59, 0.9);
    color: #f8fafc;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease;
}

.shelf-btn:active {
    transform: scale(0.96);
}

.shelf-btn-icon {
    flex: 0 0 auto;
    font-size: 16px;
}

.shelf-btn-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shelf-btn-caret {
    flex: 0 0 auto;
    font-size: 12px;
    color: #94a3b8;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.version-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 10px;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(15, 23, 42, 0.9);
    color: #bae6fd;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.version-pill:active {
    transform: scale(0.95);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px #4ade80;
    animation: pulseLive 1.8s ease-in-out infinite;
}

@keyframes pulseLive {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.8); }
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(30, 41, 59, 0.85);
    color: #f8fafc;
    font-size: 16px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.icon-btn.is-muted {
    border-color: rgba(248, 113, 113, 0.5);
    color: #fca5a5;
}

.icon-btn:active {
    transform: scale(0.93);
}

/* 回退试玩横幅 */
.rollback-banner {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 7px 12px;
    background: linear-gradient(90deg, #92400e, #b45309);
    color: #fef3c7;
    font-size: 13px;
    font-weight: 700;
    z-index: 28;
}

.rollback-exit-btn {
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    padding: 5px 12px;
    background: #fef08a;
    color: #78350f;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

/* 右侧主游戏画布 */
.stage-container {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #020617;
}

.game-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #020617;
    transition: opacity 0.22s ease;
}

/* 魔法更新浮窗 Toast */
.update-toast {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: min(92%, 440px);
    padding: 12px 14px;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.94);
    border: 1.5px solid rgba(74, 222, 128, 0.65);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 24px rgba(34, 197, 94, 0.22);
    z-index: 26;
    animation: toastSlideIn 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translate(-50%, -14px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.toast-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.toast-badge {
    font-size: 13px;
    font-weight: 800;
    color: #86efac;
}

.toast-close {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: rgba(148, 163, 184, 0.2);
    color: #e2e8f0;
    font-size: 13px;
    cursor: pointer;
}

.toast-msg {
    margin: 6px 0 10px;
    font-size: 14px;
    line-height: 1.45;
    color: #f1f5f9;
}

.toast-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.toast-voice-btn {
    border: none;
    border-radius: 999px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.toast-tap-hint {
    font-size: 12px;
    color: #fde047;
    font-weight: 700;
}

/* 抽屉弹窗与遮罩 */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.68);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 40;
}

.studio-drawer {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    width: min(94vw, 540px);
    max-height: calc(100dvh - 72px);
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    background: #0f172a;
    border: 1.5px solid rgba(148, 163, 184, 0.3);
    box-shadow: 0 22px 50px rgba(0, 0, 0, 0.65);
    z-index: 50;
    overflow: hidden;
}

.drawer-header {
    flex: 0 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(30, 41, 59, 0.65);
}

.drawer-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.drawer-title h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
    color: #f8fafc;
}

.drawer-close-btn {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.8);
    color: #cbd5e1;
    font-size: 15px;
    cursor: pointer;
}

.drawer-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 16px 18px;
    -webkit-overflow-scrolling: touch;
}

/* 多游戏卡带架 */
.cartridge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.cartridge-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    border-radius: 16px;
    border: 2px solid rgba(148, 163, 184, 0.25);
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
    color: #f8fafc;
    text-align: left;
    cursor: pointer;
    transition: transform 0.14s ease, border-color 0.15s ease;
}

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

.cartridge-card.is-active {
    border-color: #4ade80;
    box-shadow: 0 0 22px rgba(34, 197, 94, 0.22);
}

.cartridge-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cartridge-icon {
    font-size: 32px;
    line-height: 1;
}

.cartridge-badge {
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    background: rgba(74, 222, 128, 0.2);
    color: #86efac;
}

.cartridge-title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
}

.cartridge-sub {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
    color: #94a3b8;
}

.cartridge-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px dashed rgba(148, 163, 184, 0.2);
    font-size: 12px;
    color: #fde047;
    font-weight: 700;
}

.cartridge-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.cartridge-tag {
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(51, 65, 85, 0.85);
    color: #cbd5e1;
    font-size: 11px;
}

.new-game-tip {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1.5px dashed rgba(56, 189, 248, 0.5);
    background: rgba(14, 165, 233, 0.08);
    color: #bae6fd;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

/* 时光机与语音设置 */
.drawer-section + .drawer-section {
    margin-top: 18px;
}

.section-label {
    margin: 0 0 10px;
    font-size: 13px;
    font-weight: 800;
    color: #94a3b8;
}

.role-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.role-chip {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1.5px solid rgba(148, 163, 184, 0.28);
    background: rgba(30, 41, 59, 0.85);
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.role-chip.is-selected {
    border-color: #38bdf8;
    background: rgba(14, 165, 233, 0.22);
    color: #e0f2fe;
}

.snapshot-list, .history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.snapshot-item, .history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(30, 41, 59, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.16);
}

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

.item-title {
    font-size: 13px;
    font-weight: 800;
    color: #f8fafc;
}

.item-note {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.4;
    color: #94a3b8;
}

.item-action-btn {
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    padding: 6px 12px;
    background: rgba(56, 189, 248, 0.22);
    color: #7dd3fc;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.item-action-btn.is-current {
    background: rgba(74, 222, 128, 0.22);
    color: #86efac;
}

@media (max-width: 580px) {
    .studio-topbar {
        padding: 0 8px;
        gap: 6px;
    }
    .shelf-btn {
        padding: 0 8px;
        font-size: 13px;
    }
    .cartridge-grid {
        grid-template-columns: 1fr;
    }
}
