/* ==================== 设计变量 ==================== */
:root {
    --bg: #05090e;
    --panel: #0c1620;
    --panel-2: #101d29;
    --line: rgba(110, 231, 200, 0.14);
    --line-soft: rgba(255, 255, 255, 0.07);
    --text: #eef6fb;
    --muted: rgba(238, 246, 251, 0.6);
    --faint: rgba(238, 246, 251, 0.38);
    --teal: #6ee7c8;
    --teal-dim: rgba(110, 231, 200, 0.14);
    --gold: #f6cf72;
    --rose: #fb7185;
    --violet: #c4b5fd;
    --green: #67e8a5;
    --blue: #8ec5ff;
    --radius: 14px;
    --radius-sm: 9px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(900px 500px at 85% -10%, rgba(110, 231, 200, 0.07), transparent 60%),
        radial-gradient(700px 420px at -10% 110%, rgba(142, 197, 255, 0.06), transparent 60%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

button { font-family: inherit; }

/* ==================== 顶栏 ==================== */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--line-soft);
    background: rgba(5, 9, 14, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-right: auto;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 20px;
    color: #06251d;
    background: linear-gradient(135deg, #6ee7c8, #3fb8a5);
    box-shadow: 0 6px 18px rgba(110, 231, 200, 0.25);
}

.brand h1 { font-size: 19px; letter-spacing: 0.5px; }
.brand p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.mode-switch {
    display: flex;
    background: var(--panel-2);
    border: 1px solid var(--line-soft);
    border-radius: 999px;
    padding: 3px;
}

.mode-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 7px 18px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: var(--teal-dim);
    color: var(--teal);
    font-weight: 600;
}

.progress-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    font-size: 12px;
    color: var(--muted);
}

.progress-dots { display: flex; gap: 3px; }
.progress-dots i {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
}
.progress-dots i.done { background: var(--teal); }

/* ==================== 主布局 ==================== */
.layout {
    flex: 1;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr) 350px;
    gap: 14px;
    padding: 14px 18px 18px;
    max-width: 1700px;
    width: 100%;
    margin: 0 auto;
    min-height: 0;
}

.panel {
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    padding: 16px;
}

/* ==================== 课程导航 ==================== */
.course-nav {
    overflow-y: auto;
    max-height: calc(100vh - 110px);
}

.course-nav h2, .side h2 {
    font-size: 13px;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 12px;
}

.chapter { margin-bottom: 14px; }

.chapter-title {
    font-size: 12px;
    color: var(--muted);
    padding: 4px 6px;
    display: flex;
    justify-content: space-between;
}

.chapter-title .chapter-count { color: var(--faint); }

.level-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13.5px;
    transition: background 0.15s ease;
}

.level-item:hover:not(.locked) { background: rgba(255, 255, 255, 0.05); }

.level-item.current {
    background: var(--teal-dim);
    border-color: var(--line);
}

.level-item.locked {
    color: var(--faint);
    cursor: not-allowed;
}

.level-status {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 11px;
    flex-shrink: 0;
    border: 1px solid var(--line-soft);
    color: var(--faint);
}

.level-item.done .level-status {
    background: var(--teal);
    border-color: var(--teal);
    color: #06251d;
    font-weight: 700;
}

.level-item.current .level-status {
    border-color: var(--teal);
    color: var(--teal);
}

/* ==================== 画布区 ==================== */
.stage {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.canvas-wrap {
    position: relative;
    flex: 1;
    min-height: 480px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(110, 231, 200, 0.05), transparent 38%),
        #071017;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

#stage-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

#stage-canvas:focus-visible {
    outline: 3px solid rgba(110, 231, 200, 0.9);
    outline-offset: -3px;
}

.canvas-zoom {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(5, 12, 18, 0.78);
    border: 1px solid var(--line);
    backdrop-filter: blur(6px);
    z-index: 3;
}

.zoom-btn {
    width: 30px; height: 30px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: rgba(243, 247, 250, 0.85);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
}

.zoom-btn:hover { background: var(--teal-dim); color: var(--teal); }

.zoom-level {
    min-width: 46px;
    text-align: center;
    font-size: 12px;
    color: rgba(243, 247, 250, 0.72);
    cursor: pointer;
    border: none;
    background: transparent;
    padding: 4px 2px;
    border-radius: 8px;
}

.zoom-level:hover { color: var(--teal); }

.canvas-hint {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    max-width: calc(100% - 24px);
    padding: 5px 14px;
    border-radius: 999px;
    background: rgba(5, 12, 18, 0.72);
    border: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 3;
}

.tooltip {
    position: absolute;
    background: rgba(10, 22, 32, 0.95);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 4;
    white-space: nowrap;
    border: 1px solid var(--line-soft);
}

.tooltip.show { opacity: 1; }

/* 关卡完成横幅（非阻塞：只浮在画布底部，画布可继续交互） */
.celebrate {
    position: absolute;
    inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 18px;
    pointer-events: none;
    z-index: 10;
}

.celebrate.show { display: flex; }

.celebrate-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid var(--line);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    animation: slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
}

@keyframes slide-up {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.celebrate-card .celebrate-emoji { font-size: 26px; }
.celebrate-card h3 { font-size: 15px; margin: 0 0 2px; color: var(--teal); }
.celebrate-card p { color: var(--muted); font-size: 12px; margin: 0; }

/* ==================== 场景工具条 ==================== */
.scene-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* ==================== 按钮 ==================== */
.btn {
    padding: 8px 15px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--teal-dim);
    color: var(--teal);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s ease;
}

.btn:hover { background: rgba(110, 231, 200, 0.24); transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn.ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--line-soft);
}

.btn.ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }

.btn.gold {
    background: rgba(246, 207, 114, 0.14);
    border-color: rgba(246, 207, 114, 0.35);
    color: var(--gold);
}

.btn.primary {
    background: linear-gradient(135deg, #6ee7c8, #3fb8a5);
    color: #06251d;
    font-weight: 700;
    border: none;
}

.btn.toggle-on {
    background: var(--teal-dim);
    color: var(--teal);
    border-color: var(--line);
}

.btn.toggle-off {
    background: transparent;
    color: var(--faint);
    border-color: var(--line-soft);
}

/* ==================== 右侧栏 ==================== */
.side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    max-height: calc(100vh - 110px);
}

/* 任务卡 */
.task-card .level-kicker {
    font-size: 12px;
    color: var(--teal);
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.task-card h3 {
    font-size: 19px;
    margin-bottom: 10px;
    line-height: 1.35;
}

.task-card .brief {
    font-size: 13.5px;
    color: var(--muted);
    line-height: 1.75;
    margin-bottom: 14px;
}

.task-card .brief strong { color: var(--text); }
.task-card .brief em { color: var(--gold); font-style: normal; }

.task-list { list-style: none; margin-bottom: 12px; }

.task-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    color: var(--muted);
    border: 1px solid transparent;
    margin-bottom: 6px;
    background: rgba(255, 255, 255, 0.025);
    transition: all 0.25s ease;
}

.task-list li .tick {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 1.5px solid var(--faint);
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 11px;
    color: transparent;
    margin-top: 1px;
    transition: all 0.25s ease;
}

.task-list li.done {
    color: var(--text);
    border-color: var(--line);
    background: var(--teal-dim);
}

.task-list li.done .tick {
    background: var(--teal);
    border-color: var(--teal);
    color: #06251d;
}

/* 选择题选项 */
.task-list li.has-choice { flex-wrap: wrap; }

.choice-options {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
}

.choice-btn {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    text-align: left;
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--line-soft);
}

.choice-btn:hover { background: rgba(110, 231, 200, 0.12); }

.choice-btn.correct {
    background: var(--teal-dim);
    border-color: var(--teal);
    color: var(--teal);
}

.choice-btn.wrong {
    background: rgba(251, 113, 133, 0.12);
    border-color: rgba(251, 113, 133, 0.5);
    color: #fb7185;
}

.choice-explain {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.6;
    padding: 0 4px 4px;
}

.hint-box {
    border: 1px dashed rgba(246, 207, 114, 0.3);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.hint-box summary {
    cursor: pointer;
    padding: 9px 12px;
    font-size: 13px;
    color: var(--gold);
    list-style: none;
}

.hint-box summary::before { content: '💡 '; }

.hint-box .hint-body {
    padding: 0 12px 10px;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.7;
}

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

/* 矩阵面板 */
.matrix-grid {
    display: grid;
    gap: 6px;
    margin: 10px auto;
    max-width: 240px;
}

.matrix-cell {
    min-width: 0;
}

.matrix-cell input {
    width: 100%;
    padding: 10px 6px;
    text-align: center;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.045);
    color: var(--text);
    font-size: 15px;
    font-family: "SF Mono", Consolas, monospace;
    transition: border-color 0.15s ease, background 0.2s ease;
}

.matrix-cell input:focus {
    outline: none;
    border-color: var(--teal);
}

.matrix-cell input[readonly] {
    background: rgba(255, 255, 255, 0.02);
    color: var(--muted);
}

.matrix-cell.flash input {
    border-color: var(--gold);
    background: rgba(246, 207, 114, 0.14);
}

.matrix-frame {
    position: relative;
    padding: 6px 10px;
}

.matrix-frame::before, .matrix-frame::after {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    width: 10px;
    border: 2px solid var(--faint);
}

.matrix-frame::before { left: 0; border-right: none; border-radius: 6px 0 0 6px; }
.matrix-frame::after { right: 0; border-left: none; border-radius: 0 6px 6px 0; }

.diag-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 12px;
}

.diag-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.diag-item .diag-label { font-size: 11px; color: var(--faint); }
.diag-item .diag-value { font-size: 14.5px; color: var(--text); margin-top: 3px; font-family: "SF Mono", Consolas, monospace; }
.diag-item.accent .diag-value { color: var(--teal); }

.panel-note {
    font-size: 12.5px;
    color: var(--faint);
    line-height: 1.6;
    margin-top: 10px;
}

/* 沙盒面板 */
.sandbox-section { margin-bottom: 16px; }
.sandbox-section h4 {
    font-size: 12px;
    color: var(--faint);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

.op-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    font-family: "SF Mono", Consolas, monospace;
    font-size: 13px;
    color: var(--muted);
    padding: 10px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line-soft);
}

/* toast */
.toast {
    position: fixed;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(10, 22, 32, 0.96);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 10px 20px;
    border-radius: 999px;
    font-size: 13.5px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================== 响应式 ==================== */
@media (max-width: 1100px) {
    .layout { grid-template-columns: 1fr; }
    .course-nav {
        max-height: none;
        order: 2;
    }
    .stage { order: 1; }
    .side {
        order: 3;
        max-height: none;
    }
    .canvas-wrap { min-height: 60vw; }
    .canvas-hint { display: none; }
}

/* ==================== 移动端（≤900px）：单列 + 顶部章节横滑条 ==================== */
@media (max-width: 900px) {
    .topbar { padding: 10px 14px; gap: 10px; }
    .brand p { display: none; }

    .layout { padding: 10px 12px 14px; gap: 10px; }

    /* 右栏拆解为布局项，与画布自由排序：任务卡 → 画布 → 矩阵面板 → 沙盒面板 */
    .side { display: contents; }

    /* 章节导航：顶部水平滚动条 */
    .course-nav {
        order: 0;
        max-height: none;
        padding: 10px 12px;
    }
    .course-nav h2 { margin-bottom: 8px; }
    #chapter-list {
        display: flex;
        gap: 14px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .chapter { flex: 0 0 auto; margin-bottom: 0; min-width: 160px; }

    .task-card { order: 1; }
    .stage { order: 2; }
    #matrix-panel { order: 3; }
    #sandbox-panel { order: 4; }

    /* 画布保持正方形比例 */
    .canvas-wrap {
        flex: none;
        min-height: 0;
        aspect-ratio: 1 / 1;
    }

    /* 触控目标 ≥ 44px */
    .btn { min-height: 44px; padding: 10px 18px; }
    .mode-btn { min-height: 44px; padding: 10px 18px; }
    .zoom-btn { width: 44px; height: 44px; font-size: 18px; }
    .zoom-level { min-height: 44px; min-width: 52px; padding: 10px 6px; }
    .level-item { min-height: 44px; }
    .hint-box summary { min-height: 44px; padding: 12px; }
}

/* ==================== 解锁完整版弹窗 ==================== */
.level-item.locked.paywalled { cursor: pointer; }
.level-item.locked.paywalled:hover { background: rgba(246, 207, 114, 0.08); }

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(5, 9, 14, 0.66);
    backdrop-filter: blur(4px);
    z-index: 60;
}
.modal-overlay.show { display: flex; }

.modal-card {
    position: relative;
    width: min(380px, 100%);
    padding: 24px 22px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.modal-card h3 { font-size: 16px; margin-bottom: 8px; color: var(--gold); }
.modal-card p { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 16px; }

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 4px 10px;
}

.unlock-form { display: flex; gap: 8px; margin-bottom: 12px; }
.unlock-form input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.unlock-form input:focus { border-color: var(--teal); }

.unlock-buy-link {
    font-size: 13px;
    color: var(--teal);
    text-decoration: none;
}
.unlock-buy-link:hover { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
