/**
 * style.css - 小妖怪的画笔 主样式表
 * 目标设备: 华为M6平板 (2560x1600, 16:10, 横屏)
 * 设计理念: Mobile First, Touch First, Fun First
 */

/* ========== CSS 变量 ========== */
:root {
    /* 主题色 */
    --color-primary: #4CAF50;
    --color-primary-dark: #388E3C;
    --color-secondary: #FF9800;
    --color-danger: #F44336;
    --color-info: #2196F3;

    /* 背景色 */
    --bg-splash: #1A1A2E;
    --bg-game: #F5F5DC;
    --bg-toolbar: #8B7355;
    --bg-overlay: rgba(0, 0, 0, 0.7);

    /* 文字色 */
    --text-primary: #333333;
    --text-light: #FFFFFF;
    --text-muted: #999999;

    /* 尺寸 */
    --toolbar-height: 120px;
    --header-height: 60px;
    --btn-min-size: 48px;
    --btn-large-size: 64px;
    --border-radius: 12px;
    --border-radius-lg: 24px;

    /* 动画 */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;

    /* 安全区域 */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========== 全局重置 ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background-color: var(--bg-splash);
    color: var(--text-primary);
}

img {
    max-width: 100%;
    height: auto;
    pointer-events: none;
    -webkit-user-drag: none;
}

button {
    font-family: inherit;
    font-size: inherit;
    border: none;
    background: none;
    cursor: pointer;
    touch-action: manipulation;
}

/* ========== 屏幕容器 ========== */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

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

.overlay-screen {
    background-color: var(--bg-overlay);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
}

/* ========== 启动页 (Splash Screen) ========== */
#splash-screen {
    position: relative;
    justify-content: center;
    align-items: center;
    /* 背景图 - 如果存在则显示，否则回退到渐变色 */
    background:
        url('../assets/images/splash/splash_bg.png') center/cover no-repeat,
        linear-gradient(135deg, #1A1A2E 0%, #16213E 50%, #0F3460 100%);
    background-color: #1A1A2E;
}

/* 启动页虚化遮罩层 */
#splash-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 0;
}

/* 确保内容在遮罩层之上 */
#splash-screen .splash-content {
    position: relative;
    z-index: 1;
}

.splash-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 20px;
}

.splash-logo {
    width: min(300px, 40vw);
    height: auto;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

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

.splash-title {
    font-size: clamp(32px, 6vw, 64px);
    font-weight: bold;
    color: #FFD93D;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

.splash-subtitle {
    font-size: clamp(16px, 3vw, 24px);
    color: var(--text-light);
    opacity: 0.8;
    margin-bottom: 40px;
}

/* 胶囊按钮 */
.btn-capsule {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 200px;
    min-height: 60px;
    padding: 16px 48px;
    font-size: clamp(18px, 3vw, 24px);
    font-weight: bold;
    color: var(--text-light);
    border-radius: 40px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-capsule:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 40px;
    box-shadow: 0 0 20px var(--color-primary);
    opacity: 0.5;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.02); }
}

/* ========== 关卡选择页 ========== */
#level-select-screen {
    background: linear-gradient(180deg, #E8DCC8 0%, #D4C4A8 100%);
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    padding-top: var(--safe-area-top);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-title {
    font-size: 24px;
    font-weight: bold;
    color: var(--text-primary);
}

.header-spacer {
    width: var(--btn-min-size);
}

.level-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.level-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition-fast);
}

.level-card:active {
    transform: scale(0.95);
}

.level-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.level-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: var(--text-light);
}

.level-card-number {
    font-size: 14px;
    opacity: 0.8;
}

.level-card-title {
    font-size: 16px;
    font-weight: bold;
}

.level-card.locked {
    filter: grayscale(80%);
    opacity: 0.6;
}

.level-card.locked::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 48px;
}

/* ========== 游戏主界面 ========== */
#game-screen {
    background-color: var(--bg-game);
}

/* 游戏顶部栏 */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 16px;
    padding-top: var(--safe-area-top);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.speaker-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #FFD93D;
    border: 3px solid var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
    transition: background-color var(--transition-fast), transform var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* 说话时的脉冲动画 */
.speaker-avatar.speaking {
    animation: speakerPulse 0.8s ease-in-out infinite;
    border-color: var(--color-primary);
    box-shadow: 0 0 12px var(--color-primary);
}

@keyframes speakerPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.btn-audio {
    animation: bounce 1s ease-in-out infinite;
}

.btn-audio.playing {
    animation: none;
    background: var(--color-primary);
    border-radius: 50%;
}

@keyframes bounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.level-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
}

/* 图标按钮 */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--btn-min-size);
    height: var(--btn-min-size);
    border-radius: 50%;
    transition: transform var(--transition-fast), background var(--transition-fast);
}

.btn-icon:active {
    transform: scale(0.9);
    background: rgba(0, 0, 0, 0.1);
}

.btn-icon img {
    width: 32px;
    height: 32px;
}

/* ========== 画布容器 (核心) ========== */
.canvas-container {
    position: relative;
    flex: 1;
    width: 100%;
    min-height: 0; /* 关键：允许 flex 子项收缩 */
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    background: #FAFAFA;
}

/* 所有画布层共用样式 */
.canvas-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* 底图层 */
.layer-base {
    z-index: 1;
    pointer-events: none !important;
}

/* 涂鸦层 - 关键：必须能接收事件 */
.layer-draw {
    z-index: 5;
    touch-action: none;
    pointer-events: auto !important;
    cursor: crosshair;
}

/* 线稿层 - 关键：必须穿透事件 */
.layer-line {
    z-index: 10;
    pointer-events: none !important;
}

/* 确保画布容器内的所有 img 元素都不拦截事件 */
.canvas-container img {
    pointer-events: none !important;
    user-select: none;
    -webkit-user-drag: none;
}

/* ========== 底部工具栏 ========== */
.game-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--toolbar-height);
    min-height: 120px; /* 严格最小高度，防止误触 */
    padding: 8px 16px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    /* 木纹质感渐变 */
    background:
        linear-gradient(90deg,
            rgba(139, 90, 43, 0.1) 0%,
            rgba(160, 120, 80, 0.2) 25%,
            rgba(139, 90, 43, 0.1) 50%,
            rgba(160, 120, 80, 0.2) 75%,
            rgba(139, 90, 43, 0.1) 100%),
        linear-gradient(180deg, #A08060 0%, var(--bg-toolbar) 50%, #6B5344 100%);
    box-shadow:
        0 -4px 20px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
    border-top: 2px solid #5D4037;
    z-index: 10;
}

.toolbar-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 调色盘 */
.palette-section {
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.color-palette {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    padding: 4px 0;
}

.color-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    border: 3px solid transparent;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.color-btn:active {
    transform: scale(0.9);
}

.color-btn.active {
    border-color: var(--text-light);
    transform: scale(1.1);
    box-shadow: 0 0 15px currentColor;
}

/* 工具按钮 */
.tools-section {
    gap: 12px;
}

.btn-tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius);
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-light);
    border: 2px solid transparent;
    transition: all var(--transition-fast);
}

.btn-tool:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 0.3);
}

.btn-tool.active {
    background: rgba(255, 255, 255, 0.4);
    border-color: var(--text-light);
    box-shadow:
        0 0 15px rgba(255, 255, 255, 0.4),
        inset 0 0 10px rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.btn-tool img {
    width: 40px;
    height: 40px;
    margin-bottom: 4px;
}

.btn-tool span {
    font-size: 12px;
    font-weight: bold;
}

/* 操作按钮 */
.action-section {
    gap: 12px;
}

.btn-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    border-radius: var(--border-radius);
    color: var(--text-light);
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: all var(--transition-fast);
}

.btn-action:active {
    transform: scale(0.92) translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.btn-action img {
    width: 36px;
    height: 36px;
    margin-bottom: 4px;
}

.btn-action span {
    font-size: 12px;
}

.btn-undo {
    background: var(--color-secondary);
}

.btn-done {
    background: var(--color-primary);
    width: 100px;
}

/* ========== 结算页 ========== */
#complete-screen {
    justify-content: center;
    align-items: center;
}

.complete-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    max-width: 90%;
}

.complete-title {
    font-size: clamp(24px, 4vw, 36px);
    color: #FFD93D;
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.artwork-frame {
    position: relative;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transform: rotate(-2deg);
    margin-bottom: 40px;
}

.artwork-frame::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 20px;
    background: #DDD;
    border-radius: 4px;
}

.artwork-preview {
    max-width: 400px;
    max-height: 300px;
    border-radius: 4px;
}

.complete-actions {
    display: flex;
    gap: 20px;
}

.btn-action-large {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100px;
    height: 100px;
    border-radius: var(--border-radius-lg);
    color: var(--text-light);
    font-weight: bold;
    transition: transform var(--transition-fast);
}

.btn-action-large:active {
    transform: scale(0.95);
}

.btn-action-large img {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
}

.btn-action-large span {
    font-size: 14px;
}

.btn-retry {
    background: var(--color-danger);
}

.btn-save {
    background: var(--color-info);
}

.btn-next {
    background: var(--color-primary);
    width: 140px;
}

/* ========== 响应式适配 ========== */

/* 竖屏模式 (不推荐) */
@media (orientation: portrait) {
    .splash-logo {
        width: min(250px, 60vw);
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .game-toolbar {
        flex-wrap: wrap;
        height: auto;
        min-height: var(--toolbar-height);
    }

    .palette-section {
        order: 1;
        flex-basis: 100%;
        justify-content: center;
        margin-bottom: 8px;
    }

    .tools-section {
        order: 2;
    }

    .action-section {
        order: 3;
    }
}

/* 小屏幕 */
@media (max-width: 600px) {
    :root {
        --btn-min-size: 44px;
        --btn-large-size: 56px;
        --toolbar-height: 100px;
    }

    .level-title {
        font-size: 14px;
    }

    .btn-tool, .btn-action {
        width: 60px;
        height: 60px;
    }

    .btn-tool img, .btn-action img {
        width: 28px;
        height: 28px;
    }

    .btn-tool span, .btn-action span {
        font-size: 10px;
    }
}

/* 华为 M6 优化 (2560x1600) */
@media (min-width: 2000px) {
    :root {
        --btn-min-size: 64px;
        --btn-large-size: 80px;
        --toolbar-height: 150px;
        --header-height: 80px;
    }

    .splash-title {
        font-size: 72px;
    }

    .level-title {
        font-size: 24px;
    }

    .color-btn {
        width: 80px;
        height: 80px;
    }
}

/* ========== 动画 ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes firework {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

.animate-fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.animate-slide-up {
    animation: slideUp 0.4s ease forwards;
}

/* ========== 横屏引导遮罩 ========== */
.orientation-lock {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1A1A2E 0%, #0F3460 100%);
    z-index: 99999;
    justify-content: center;
    align-items: center;
}

.orientation-content {
    text-align: center;
    color: var(--text-light);
}

.rotate-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotateHint 2s ease-in-out infinite;
}

@keyframes rotateHint {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-30deg);
    }
    75% {
        transform: rotate(90deg);
    }
}

.orientation-content p {
    font-size: 24px;
    margin: 10px 0;
}

.orientation-content .rotate-hint {
    font-size: 16px;
    opacity: 0.7;
}

/* 竖屏时显示引导遮罩 */
@media (orientation: portrait) {
    .orientation-lock {
        display: flex;
    }
}
