/* ==========================================================================
   数字迷宫 (Number Maze) - 样式表
   专门针对 10 岁小学生打造的高颜值、现代双色主题与沉浸式卡片视觉设计
   ========================================================================== */

:root {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #311042 100%);
    --panel-bg: rgba(255, 255, 255, 0.12);
    --panel-border: rgba(255, 255, 255, 0.22);
    --panel-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);

    --primary-color: #f59e0b;
    --primary-hover: #d97706;
    --accent-color: #06b6d4;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f97316;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dark: #1e293b;

    /* 格子颜色系统 */
    --cell-bg: rgba(255, 255, 255, 0.15);
    --cell-border: rgba(255, 255, 255, 0.25);
    --cell-pos-bg: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    --cell-neg-bg: linear-gradient(135deg, #ea580c 0%, #c2410c 100%);
    --cell-blank-bg: rgba(255, 255, 255, 0.08);
    --cell-obstacle-bg: #0f172a;
    --cell-start-bg: linear-gradient(135deg, #059669 0%, #047857 100%);
    --cell-end-bg: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);

    --path-glow: #facc15;
    --font-main: 'Fredoka', 'Noto Sans SC', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    padding: 12px;
}

.app-container {
    width: 100%;
    max-width: 900px;
    height: 94vh;
    max-height: 860px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* 通用玻璃拟态面板 */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    box-shadow: var(--panel-shadow);
}

/* 音效控制按钮 */
.audio-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.audio-btn:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.3);
}

/* 屏幕显示/隐藏切换 */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.screen.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* ==========================================================================
   1. 主菜单界面 (Main Menu)
   ========================================================================== */
.menu-card {
    width: 90%;
    max-width: 440px;
    padding: 40px 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 28px;
    animation: floatIn 0.6s ease-out;
}

.game-logo .logo-badge {
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    color: #0f172a;
    font-weight: 700;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.game-logo .logo-title {
    font-size: 42px;
    font-weight: 900;
    margin-top: 10px;
    background: linear-gradient(180deg, #ffffff 0%, #fef08a 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    letter-spacing: 2px;
}

.logo-stars {
    font-size: 18px;
    margin-top: 4px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 通用按钮系统 */
.btn {
    border: none;
    outline: none;
    padding: 14px 28px;
    font-size: 18px;
    font-weight: 700;
    font-family: var(--font-main);
    border-radius: 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.btn-icon {
    font-size: 22px;
}

.btn-primary {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: #ffffff;
}

.btn-secondary {
    background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
    color: #ffffff;
}

.btn-info {
    background: linear-gradient(135deg, #0d9488 0%, #0f766e 100%);
    color: #ffffff;
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #ffffff;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #ffffff;
}

.btn-warning {
    background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
    color: #ffffff;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 12px;
}

.btn-lg {
    padding: 16px 36px;
    font-size: 22px;
    border-radius: 20px;
}

.btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(1px) scale(0.98);
}

.pulse-glow {
    animation: pulseGlow 2s infinite;
}

@keyframes pulseGlow {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.6); }
    70% { box-shadow: 0 0 0 16px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

.menu-footer {
    color: var(--text-muted);
    font-size: 14px;
}

.menu-footer strong {
    color: var(--primary-color);
}

/* ==========================================================================
   2. 关卡选择界面 (Level Selection)
   ========================================================================== */
.modal-card {
    width: 90%;
    max-width: 520px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-size: 24px;
    color: #ffffff;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #ffffff;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-height: 380px;
    overflow-y: auto;
    padding-right: 4px;
}

.level-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 14px 16px;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    transition: all 0.2s ease;
}

.level-btn .lvl-num {
    font-size: 18px;
    font-weight: 700;
}

.level-btn .lvl-grid-size {
    font-size: 13px;
    color: var(--text-muted);
}

.level-btn:hover:not(.locked) {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.level-btn.active-level {
    border-color: var(--primary-color);
    background: rgba(245, 158, 11, 0.2);
}

.level-btn.locked {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==========================================================================
   3. 游戏规则弹窗 (Game Rules Modal)
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* 遵循照片要求：规则界面为白色界面，深色文字 */
.rules-card {
    background: #ffffff;
    color: var(--text-dark);
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    border-radius: 24px;
    padding: 28px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
}

.rules-card .modal-header h2 {
    color: var(--text-dark);
}

.rules-card .close-btn {
    color: #64748b;
}

.rules-content ol {
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 15px;
    line-height: 1.6;
}

.rules-content ul {
    margin-top: 6px;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #ffffff;
}

.badge.pos { background: #0284c7; }
.badge.neg { background: #ea580c; }
.badge.obstacle { background: #0f172a; }
.badge.start { background: #059669; }
.badge.end { background: #7c3aed; }

/* ==========================================================================
   4. 游戏主界面 (Gameplay Screen)
   ========================================================================== */
#screen-gameplay {
    justify-content: space-between;
    padding: 10px 0;
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.level-info-badge {
    background: rgba(255, 255, 255, 0.15);
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

/* 照片手稿中的长方形数值卡片 (3x3方格上面的一行长方形) */
.sum-tracker-card {
    background: #ffffff;
    color: var(--text-dark);
    padding: 8px 24px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    border: 3px solid #f59e0b;
}

.tracker-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tracker-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 700;
}

.tracker-value {
    font-size: 26px;
    font-weight: 900;
    line-height: 1.1;
}

.tracker-value.limit-tag {
    color: #2563eb;
}

.tracker-value.sum-tag {
    color: #d97706;
}

.tracker-divider {
    font-size: 24px;
    font-weight: 300;
    color: #cbd5e1;
}

/* 迷宫网格区域 */
.game-board-container {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.maze-grid {
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 580px;
    max-height: 580px;
    aspect-ratio: 1 / 1;
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* 格子样式 */
.cell {
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    font-weight: 800;
    font-size: calc(22px - (var(--grid-cols, 3) * 1.2px));
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border: 2px solid transparent;
}

.cell-val {
    z-index: 2;
}

.cell-tag {
    font-size: calc(11px - (var(--grid-cols, 3) * 0.4px));
    font-weight: 700;
    margin-top: 2px;
    opacity: 0.9;
    z-index: 2;
}

/* 各种格子类型的着色 */
.cell.cell-start {
    background: var(--cell-start-bg);
    border-color: #34d399;
    color: #ffffff;
}

.cell.cell-end {
    background: var(--cell-end-bg);
    border-color: #a78bfa;
    color: #ffffff;
}

.cell.cell-pos {
    background: var(--cell-pos-bg);
    color: #ffffff;
}

.cell.cell-neg {
    background: var(--cell-neg-bg);
    color: #ffffff;
}

.cell.cell-blank {
    background: var(--cell-blank-bg);
    color: rgba(255, 255, 255, 0.5);
    border-color: rgba(255, 255, 255, 0.1);
}

.cell.cell-obstacle {
    background: var(--cell-obstacle-bg);
    color: #475569;
    cursor: not-allowed;
    border-color: #1e293b;
    background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0, rgba(255,255,255,0.03) 10px, transparent 0, transparent 20px);
}

/* 可触达/邻近可点击的格子高亮 */
.cell.cell-reachable {
    border-color: #facc15;
    animation: reachablePulse 1.5s infinite alternate;
}

.cell.cell-reachable:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 16px rgba(250, 204, 21, 0.4);
}

@keyframes reachablePulse {
    0% { border-color: rgba(250, 204, 21, 0.4); }
    100% { border-color: rgba(250, 204, 21, 1); }
}

/* 处于当前移动路线上的格子 */
.cell.cell-visited {
    box-shadow: inset 0 0 0 3px #facc15, 0 0 16px rgba(250, 204, 21, 0.5);
}

.cell.cell-current-player {
    transform: scale(1.05);
    z-index: 10;
}

/* 玩家头像角标 */
.cell-avatar {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: calc(20px - (var(--grid-cols, 3) * 0.8px));
    z-index: 20;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* 照片要求：步数超过上限时，格子闪烁变红 1 秒 */
.cell.cell-error-flash {
    background: #dc2626 !important;
    border-color: #f87171 !important;
    color: #ffffff !important;
    animation: errorShake 0.4s ease-in-out infinite alternate;
    box-shadow: 0 0 25px #ef4444 !important;
    z-index: 30;
}

@keyframes errorShake {
    0% { transform: translate(-3px, -3px) scale(1.08); }
    100% { transform: translate(3px, 3px) scale(1.08); }
}

/* 底部功能栏 */
.game-footer {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.game-footer .btn {
    padding: 10px 20px;
    font-size: 15px;
}

.keyboard-tips {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* ==========================================================================
   5. 单关通关与全通关界面 (Victory & All Cleared)
   ========================================================================== */
.victory-card {
    text-align: center;
    gap: 16px;
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.victory-icon {
    font-size: 56px;
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 10px 0;
}

.stat-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-box span {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-box strong {
    font-size: 22px;
    color: var(--primary-color);
}

/* 写真一 bottom 的全通关界面 */
.all-cleared-card {
    width: 90%;
    max-width: 500px;
    padding: 50px 30px;
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: zoomIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 写真一 bottom 画的号角装饰图标 */
.horn-decor {
    position: absolute;
    bottom: 30px;
    font-size: 42px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

.horn-left {
    left: 20px;
    transform: rotate(-25deg);
}

.horn-right {
    right: 20px;
    transform: rotate(25deg) scaleX(-1);
}

.trophy-badge {
    font-size: 64px;
    animation: bounce 2s infinite;
}

.congrats-title {
    font-size: 48px;
    font-weight: 900;
    color: #fef08a;
    text-shadow: 0 4px 16px rgba(250, 204, 21, 0.5);
    letter-spacing: 4px;
}

.all-cleared-subtitle {
    font-size: 38px;
    font-weight: 900;
    color: #ffffff;
    letter-spacing: 3px;
}

.game-name-tag {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-color);
    background: rgba(245, 158, 11, 0.15);
    padding: 4px 20px;
    border-radius: 20px;
    border: 1px solid rgba(245, 158, 11, 0.4);
}

.completion-banner {
    background: rgba(255, 255, 255, 0.1);
    padding: 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
    color: #e2e8f0;
}

/* 彩花 Canvas */
#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 300;
}

/* Keyframes */
@keyframes floatIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.6); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

/* 响应式微调 */
@media (max-width: 600px) {
    .menu-card { padding: 30px 20px; }
    .game-logo .logo-title { font-size: 34px; }
    .congrats-title { font-size: 36px; }
    .all-cleared-subtitle { font-size: 28px; }
    .sum-tracker-card { padding: 6px 16px; }
    .tracker-value { font-size: 20px; }
    .horn-decor { font-size: 32px; bottom: 15px; }
}
