/* ============================================
   记忆序列 — Memory Sequence Game
   ============================================ */

/* ---- CSS Variables ---- */
:root {
    --bg: #08080f;
    --bg-card: #12121d;
    --text: #e8e8f0;
    --text-dim: #7a7a95;
    --text-muted: #4a4a60;

    --pad-red: #ff5e5e;
    --pad-red-glow: rgba(255, 94, 94, 0.55);
    --pad-red-active: #ff8080;
    --pad-blue: #4dc9f6;
    --pad-blue-glow: rgba(77, 201, 246, 0.55);
    --pad-blue-active: #70d4f8;
    --pad-green: #5ef78c;
    --pad-green-glow: rgba(94, 247, 140, 0.55);
    --pad-green-active: #80f9a3;
    --pad-yellow: #ffcc4d;
    --pad-yellow-glow: rgba(255, 204, 77, 0.55);
    --pad-yellow-active: #ffd670;

    --accent: #a78bfa;
    --success: #4ade80;
    --danger: #f87171;

    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 28px;

    --font-mono: "SF Mono", "Cascadia Code", "Fira Code", monospace;
}

/* ---- Reset ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
}

/* ---- Subtle ambient background ---- */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 60% at 50% 10%, rgba(120, 100, 220, 0.07), transparent),
        radial-gradient(ellipse 60% 50% at 20% 90%, rgba(77, 201, 246, 0.04), transparent),
        radial-gradient(ellipse 60% 50% at 80% 90%, rgba(94, 247, 140, 0.04), transparent);
    pointer-events: none;
    z-index: 0;
}

/* ---- Particle Canvas ---- */
#particles-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

/* ---- App Container ---- */
#app {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 520px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---- Screens ---- */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    animation: screenIn 0.35s ease-out;
}

.screen.active {
    display: flex;
}

.screen-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

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

/* ---- Sound Toggle ---- */
.sound-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.sound-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
}

.hidden {
    display: none !important;
}

/* =============================================
   Start Screen
   ============================================= */
.logo-wrapper {
    margin-bottom: 12px;
}

.logo {
    font-size: 64px;
    display: block;
    animation: logoFloat 3s ease-in-out infinite;
}

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

.title {
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #c4b5fd 0%, #f0abfc 50%, #67e8f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}

.subtitle {
    font-size: 15px;
    color: var(--text-dim);
    margin-bottom: 32px;
}

.stats-preview {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 18px 36px;
    margin-bottom: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 0 20px;
}

.stat-number {
    font-size: 28px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text);
}

.stat-label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
}

.stat-divider {
    width: 1px;
    height: 36px;
    background: rgba(255, 255, 255, 0.08);
}

/* ---- Buttons ---- */
.btn-primary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 48px;
    font-size: 17px;
    font-weight: 700;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, #7c3aed 0%, #a78bfa 100%);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 24px rgba(124, 58, 237, 0.35);
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 32px rgba(124, 58, 237, 0.45);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-shortcut {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.15);
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.btn-outline {
    padding: 12px 40px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    color: var(--text);
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.25);
}

.btn-outline:active {
    transform: scale(0.97);
}

.btn-ghost {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-dim);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-ghost:hover {
    color: var(--text);
}

.hint {
    margin-top: 14px;
    font-size: 13px;
    color: var(--text-muted);
}

.hint kbd {
    display: inline-block;
    padding: 1px 7px;
    font-size: 11px;
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: var(--text-dim);
}

/* =============================================
   Game Screen
   ============================================= */
#game-screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 480px;
    padding: 0 8px;
}

.hud-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-right: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hud-value {
    font-size: 26px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.hud-level .hud-value {
    color: #c4b5fd;
}

.hud-best .hud-value {
    color: var(--text-dim);
}

/* ---- Game Board ---- */
.game-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: clamp(8px, 2vw, 16px);
    width: min(85vw, 85vh, 420px);
    height: min(85vw, 85vh, 420px);
    position: relative;
}

/* ---- Pads ---- */
.pad {
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    position: relative;
    transition: transform 0.1s ease-out, filter 0.15s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.pad:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 3px;
}

/* Pad default colors */
.pad-0 { background: var(--pad-red);   box-shadow: 0 0 30px var(--pad-red-glow); }
.pad-1 { background: var(--pad-blue);  box-shadow: 0 0 30px var(--pad-blue-glow); }
.pad-2 { background: var(--pad-green); box-shadow: 0 0 30px var(--pad-green-glow); }
.pad-3 { background: var(--pad-yellow); box-shadow: 0 0 30px var(--pad-yellow-glow); }

/* Pad active (lit up during sequence display) */
.pad.lit {
    transform: scale(1.05);
    filter: brightness(1.4) saturate(1.2);
}

.pad-0.lit { box-shadow: 0 0 60px var(--pad-red-glow), 0 0 120px var(--pad-red-glow); }
.pad-1.lit { box-shadow: 0 0 60px var(--pad-blue-glow), 0 0 120px var(--pad-blue-glow); }
.pad-2.lit { box-shadow: 0 0 60px var(--pad-green-glow), 0 0 120px var(--pad-green-glow); }
.pad-3.lit { box-shadow: 0 0 60px var(--pad-yellow-glow), 0 0 120px var(--pad-yellow-glow); }

/* Pad pressed by player */
.pad.pressed {
    transform: scale(0.93);
    filter: brightness(1.3);
    transition: transform 0.08s ease-out;
}

/* Pad disabled (during sequence display) */
.game-board.disabled .pad {
    cursor: default;
    pointer-events: none;
}

.game-board.disabled .pad:focus-visible {
    outline: none;
}

/* Keyboard key hint on pads */
.pad-key {
    position: absolute;
    bottom: 8px;
    right: 10px;
    font-size: 12px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

/* ---- Game Status ---- */
.game-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
    min-height: 28px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.status-dot.watch {
    background: var(--pad-yellow);
    animation: dotPulse 0.6s ease-in-out infinite;
}

.status-dot.play {
    background: var(--success);
}

.status-dot.wrong {
    background: var(--danger);
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

.keyboard-guide {
    font-size: 12px;
    color: var(--text-muted);
}

.keyboard-guide kbd {
    display: inline-block;
    padding: 2px 7px;
    font-size: 11px;
    font-family: var(--font-mono);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin: 0 2px;
}

/* Keyboard guide hidden on touch devices */
@media (hover: none) and (pointer: coarse) {
    .keyboard-guide {
        display: none;
    }
    .pad-key {
        display: none;
    }
    .btn-shortcut {
        display: none;
    }
    .hint {
        display: none;
    }
}

/* =============================================
   Result Screen
   ============================================= */
#result-screen .screen-content {
    gap: 6px;
}

.result-badge {
    font-size: 56px;
    margin-bottom: 8px;
    animation: badgePop 0.5s ease-out;
}

@keyframes badgePop {
    0% { transform: scale(0); }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.result-rank {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.result-score {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 8px 0 4px;
}

.score-num {
    font-size: 72px;
    font-weight: 800;
    font-family: var(--font-mono);
    background: linear-gradient(180deg, #fff 0%, #c4b5fd 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1;
}

.score-text {
    font-size: 20px;
    color: var(--text-dim);
    font-weight: 600;
}

.result-msg {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 18px;
    text-align: center;
    max-width: 280px;
    line-height: 1.5;
}

.result-metrics {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 14px 28px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 0 16px;
}

.metric-value {
    font-size: 22px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text);
}

.metric-label {
    font-size: 11px;
    color: var(--text-dim);
}

.result-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.result-actions .btn-primary,
.result-actions .btn-outline {
    width: 100%;
    text-align: center;
    justify-content: center;
}

/* ---- Screen shake on error ---- */
.shake {
    animation: shake 0.4s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-8px); }
    30% { transform: translateX(8px); }
    45% { transform: translateX(-6px); }
    60% { transform: translateX(6px); }
    75% { transform: translateX(-3px); }
    90% { transform: translateX(3px); }
}

/* ---- Responsive ---- */
@media (min-width: 768px) {
    .title {
        font-size: 42px;
    }

    .game-board {
        width: min(480px, 70vh);
        height: min(480px, 70vh);
    }

    .pad:hover {
        filter: brightness(1.1);
        transform: scale(1.02);
    }

    .game-board.disabled .pad:hover {
        filter: none;
        transform: none;
    }

    .score-num {
        font-size: 80px;
    }
}

@media (min-width: 1024px) {
    .game-board {
        width: min(480px, 75vh);
        height: min(480px, 75vh);
    }

    .pad {
        border-radius: 24px;
    }
}

/* Short screens (landscape mobile) */
@media (max-height: 500px) {
    #game-screen.active {
        gap: 8px;
    }

    .game-board {
        width: min(60vh, 400px);
        height: min(60vh, 400px);
    }

    .game-hud {
        padding: 0 4px;
    }

    .hud-value {
        font-size: 20px;
    }

    .game-status {
        font-size: 13px;
    }
}

/* Very small screens */
@media (max-width: 340px) {
    .title {
        font-size: 28px;
    }

    .game-board {
        width: 92vw;
        height: 92vw;
    }

    .stats-preview,
    .result-metrics {
        padding: 12px 16px;
    }

    .stat-item,
    .metric {
        padding: 0 10px;
    }

    .stat-number {
        font-size: 22px;
    }
}
