/* ============================================
   XPuzzle Game - 游戏风格 UI
   ============================================ */

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

/* ---------- 动画 ---------- */
@keyframes bgShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

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

@keyframes titleGlow {
    0%, 100% { text-shadow: 0 0 10px rgba(255,255,255,.4), 0 0 20px rgba(120,180,255,.5); }
    50%      { text-shadow: 0 0 20px rgba(255,255,255,.8), 0 0 40px rgba(120,180,255,.9); }
}

@keyframes pulseBadge {
    0%, 100% { transform: scale(1);    opacity: 1;  }
    50%      { transform: scale(1.08); opacity: .85; }
}

@keyframes shine {
    0%   { transform: translateX(-120%) skewX(-20deg); }
    100% { transform: translateX(220%)  skewX(-20deg); }
}

@keyframes ringPulse {
    0%   { box-shadow: 0 0 0 0 rgba(255, 212, 122, .55); }
    100% { box-shadow: 0 0 0 14px rgba(255, 212, 122, 0); }
}

/* ---------- 页面背景 ---------- */
body {
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
    color: #e8ecff;
    line-height: 1.6;
    min-height: 100vh;
    background: linear-gradient(-45deg, #0f0c29, #302b63, #24243e, #1a1a2e);
    background-size: 400% 400%;
    animation: bgShift 18s ease infinite;
    overflow-x: hidden;
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,.7), transparent),
        radial-gradient(1px 1px at 60% 70%, rgba(255,255,255,.6), transparent),
        radial-gradient(1.5px 1.5px at 80% 20%, rgba(255,255,255,.5), transparent),
        radial-gradient(1px 1px at 35% 85%, rgba(255,255,255,.5), transparent),
        radial-gradient(1.5px 1.5px at 90% 60%, rgba(255,255,255,.4), transparent);
    background-size: 800px 800px;
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* ---------- 顶部标题 ---------- */
header {
    text-align: center;
    margin-bottom: 30px;
    padding: 24px 0;
    background: linear-gradient(135deg, rgba(102,126,234,.85) 0%, rgba(118,75,162,.85) 100%);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 16px;
    box-shadow:
        0 8px 30px rgba(0, 0, 0, .35),
        inset 0 1px 0 rgba(255,255,255,.2);
    position: relative;
    overflow: hidden;
}

header::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 40%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255,255,255,.25), transparent);
    animation: shine 5s ease-in-out infinite;
}

h1 {
    font-size: 2.8em;
    letter-spacing: 3px;
    font-weight: 900;
    color: #fff;
    animation: titleGlow 3s ease-in-out infinite;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------- 面板 ---------- */
.screen {
    width: 100%;
    max-width: 820px;
    background: linear-gradient(160deg, rgba(30, 33, 68, .85) 0%, rgba(20, 22, 45, .9) 100%);
    border: 1px solid rgba(120, 140, 255, .25);
    border-radius: 18px;
    padding: 32px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, .5),
        inset 0 1px 0 rgba(255,255,255,.08);
    margin-bottom: 30px;
    text-align: center;
    backdrop-filter: blur(6px);
    animation: floatUp .4s ease-out;
}

.hidden { display: none !important; }

.section-title {
    font-size: 1.5em;
    font-weight: 800;
    color: #ffd47a;
    letter-spacing: 4px;
    margin: 10px 0 22px;
    text-shadow: 0 0 12px rgba(255,180,80,.4);
}

.section-title::before,
.section-title::after {
    content: "";
    display: inline-block;
    width: 40px;
    height: 2px;
    vertical-align: middle;
    margin: 0 14px;
    background: linear-gradient(90deg, transparent, #ffd47a, transparent);
}

/* ---------- 难度按钮 ---------- */
.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 20px 0 34px;
}

.difficulty-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 16px 22px;
    font-size: 1.15em;
    color: #fff;
    background: linear-gradient(135deg, #2a3a70 0%, #3d2c6b 100%);
    border: 2px solid rgba(150, 170, 255, .3);
    border-radius: 14px;
    cursor: pointer;
    font-weight: bold;
    text-align: left;
    letter-spacing: 1px;
    transition: transform .2s, box-shadow .25s, border-color .25s, background .25s;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08);
}

.difficulty-btn::before {
    content: "";
    position: absolute;
    top: 0;
    left: -60%;
    width: 40%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255,255,255,.25), transparent);
    transform: skewX(-20deg);
    transition: left .6s ease;
    pointer-events: none;
}

.difficulty-btn:hover {
    transform: translateY(-3px) scale(1.01);
    border-color: rgba(180, 200, 255, .8);
    box-shadow: 0 8px 25px rgba(80, 130, 255, .45), inset 0 1px 0 rgba(255,255,255,.15);
}

.difficulty-btn:hover::before { left: 120%; }
.difficulty-btn:active         { transform: translateY(-1px) scale(.99); }

.diff-icon {
    font-size: 2em;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,.5));
    flex-shrink: 0;
}

.diff-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
}

.diff-name {
    font-size: 1.35em;
    font-weight: 900;
    letter-spacing: 3px;
}

.diff-desc {
    font-size: .78em;
    font-weight: normal;
    color: rgba(255,255,255,.65);
    letter-spacing: 1px;
    margin-top: 2px;
}

.diff-badge {
    font-size: .75em;
    font-family: 'Consolas', 'Courier New', monospace;
    padding: 5px 12px;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 20px;
    letter-spacing: 2px;
    flex-shrink: 0;
}

/* 三个难度不同色系 */
.difficulty-btn[data-difficulty="easy"] {
    background: linear-gradient(135deg, #1e6f5c 0%, #2a9d8f 100%);
    border-color: rgba(120, 240, 200, .35);
}
.difficulty-btn[data-difficulty="easy"]:hover {
    box-shadow: 0 8px 25px rgba(46, 200, 150, .5), inset 0 1px 0 rgba(255,255,255,.15);
}

.difficulty-btn[data-difficulty="medium"] {
    background: linear-gradient(135deg, #c56b1a 0%, #e76f2c 100%);
    border-color: rgba(255, 200, 130, .4);
}
.difficulty-btn[data-difficulty="medium"]:hover {
    box-shadow: 0 8px 25px rgba(255, 140, 40, .5), inset 0 1px 0 rgba(255,255,255,.15);
}

.difficulty-btn[data-difficulty="hard"] {
    background: linear-gradient(135deg, #8b1a2b 0%, #c9184a 100%);
    border-color: rgba(255, 130, 160, .4);
}
.difficulty-btn[data-difficulty="hard"]:hover {
    box-shadow: 0 8px 25px rgba(230, 40, 90, .55), inset 0 1px 0 rgba(255,255,255,.15);
}

/* 选中态 - 强烈视觉反馈 */
.difficulty-btn.selected {
    transform: translateY(-2px) scale(1.02);
    border-color: #ffd47a;
    box-shadow:
        0 0 0 3px rgba(255, 212, 122, .35),
        0 10px 30px rgba(255, 180, 80, .45),
        inset 0 1px 0 rgba(255,255,255,.2);
}

.difficulty-btn.selected::after {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 12px;
    width: 26px;
    height: 26px;
    line-height: 24px;
    text-align: center;
    background: #ffd47a;
    color: #1a1a2e;
    border-radius: 50%;
    font-weight: 900;
    font-size: .9em;
    box-shadow: 0 2px 8px rgba(255, 200, 100, .6);
    animation: ringPulse 1.6s ease-out infinite;
}

.difficulty-btn.selected .diff-badge {
    background: rgba(255, 212, 122, .25);
    border-color: #ffd47a;
    color: #ffd47a;
    animation: pulseBadge 1.4s ease-in-out infinite;
}

.difficulty-btn.selected .diff-icon {
    transform: scale(1.15);
    transition: transform .3s ease;
}

/* ---------- 图片选择 ---------- */
.image-selector { margin: 20px 0 0; }

.image-options {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 22px;
}

.image-btn {
    padding: 10px 24px;
    background: linear-gradient(135deg, #3b5998 0%, #4a6cb3 100%);
    color: #fff;
    border: 2px solid rgba(255,255,255,.15);
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 1px;
    transition: transform .2s, box-shadow .25s, border-color .25s, background .25s;
}

.image-btn:hover {
    transform: translateY(-2px);
    border-color: rgba(180, 200, 255, .7);
    box-shadow: 0 6px 18px rgba(80, 130, 255, .4);
}

.image-btn.selected {
    background: linear-gradient(135deg, #d97706 0%, #f59e0b 100%);
    border-color: #ffd47a;
    box-shadow: 0 0 0 3px rgba(255, 212, 122, .3), 0 6px 18px rgba(255,180,80,.45);
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.image-item {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 10px;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,.12);
    transition: transform .2s, border-color .25s, box-shadow .25s;
    background: #222;
}

.image-item:hover {
    transform: translateY(-3px) scale(1.03);
    border-color: #7dd3fc;
    box-shadow: 0 8px 22px rgba(80, 180, 255, .45);
}

.image-item.selected {
    border-color: #ffd47a;
    box-shadow: 0 0 0 3px rgba(255, 212, 122, .35), 0 8px 22px rgba(255,180,80,.5);
    transform: translateY(-2px) scale(1.04);
}

.custom-image-container { margin-top: 18px; }

#image-upload { display: none; }

.upload-label {
    display: inline-block;
    padding: 12px 28px;
    background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 1px;
    border: 2px solid rgba(255,255,255,.15);
    transition: transform .2s, box-shadow .25s;
}

.upload-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(80, 130, 255, .5);
}

/* ---------- 游戏界面 ---------- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 14px 20px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 12px;
}

.game-info {
    font-size: 1.05em;
    font-weight: bold;
    color: #ffd47a;
    display: flex;
    gap: 22px;
}

.game-info span span {
    color: #fff;
    font-family: 'Consolas', 'Courier New', monospace;
    margin-left: 4px;
}

#restart-btn {
    padding: 10px 22px;
    background: linear-gradient(135deg, #c9184a 0%, #ff4d6d 100%);
    color: #fff;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 1px;
    transition: transform .2s, box-shadow .25s;
}

#restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(230, 40, 90, .5);
}

.back-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #4b5563 0%, #6b7280 100%);
    color: #fff;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    letter-spacing: 1px;
    transition: transform .2s, box-shadow .25s, background .25s;
}

.back-btn:hover {
    transform: translateY(-2px) translateX(-2px);
    background: linear-gradient(135deg, #6b7280 0%, #9ca3af 100%);
    box-shadow: 0 6px 18px rgba(0,0,0,.5);
}

#puzzle-canvas {
    border: 2px solid rgba(255,255,255,.15);
    border-radius: 12px;
    max-width: 100%;
    margin: 0 auto;
    background: #0f1225;
    box-shadow: 0 8px 30px rgba(0,0,0,.5);
    display: block;
}

.game-status {
    margin-top: 20px;
    padding: 14px;
    border-radius: 10px;
    font-weight: bold;
}

.game-status.win {
    background: rgba(46, 200, 150, .18);
    color: #a7f3d0;
    border: 1px solid rgba(46, 200, 150, .5);
}

/* ---------- 完成界面 ---------- */
#complete-screen h2 {
    font-size: 2em;
    color: #ffd47a;
    text-shadow: 0 0 20px rgba(255,180,80,.5);
    margin-bottom: 20px;
    letter-spacing: 4px;
    animation: titleGlow 2.5s ease-in-out infinite;
}

.complete-image-wrap {
    display: flex;
    justify-content: center;
    margin: 10px auto 22px;
    padding: 12px;
    background: linear-gradient(135deg, rgba(255,212,122,.15), rgba(255,180,80,.05));
    border: 2px solid rgba(255,212,122,.5);
    border-radius: 14px;
    box-shadow:
        0 0 30px rgba(255,180,80,.35),
        inset 0 0 20px rgba(255,212,122,.15);
    max-width: 480px;
    animation: floatUp .6s ease-out;
}

.complete-image {
    display: block;
    max-width: 100%;
    max-height: 570px;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.5);
    background: #0f1225;
}

.complete-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 18px 0 6px;
    flex-wrap: wrap;
}

.stat-card {
    min-width: 130px;
    padding: 14px 22px;
    background: rgba(255,255,255,.06);
    border: 1px solid rgba(255,212,122,.35);
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}

.stat-label {
    font-size: .85em;
    color: rgba(255,255,255,.7);
    letter-spacing: 3px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: 900;
    color: #ffd47a;
    font-family: 'Consolas', 'Courier New', monospace;
    text-shadow: 0 0 12px rgba(255,180,80,.5);
}

.stat-unit {
    font-size: .55em;
    margin-left: 4px;
    color: rgba(255,212,122,.75);
    letter-spacing: 1px;
}

.complete-buttons {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.complete-buttons button {
    padding: 12px 28px;
    border: 2px solid rgba(255,255,255,.15);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.05em;
    font-weight: bold;
    letter-spacing: 1px;
    color: #fff;
    transition: transform .2s, box-shadow .25s;
}

#play-again-btn {
    background: linear-gradient(135deg, #2a9d8f 0%, #34d399 100%);
}

#play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(46, 200, 150, .5);
}

#menu-btn {
    background: linear-gradient(135deg, #4b5563 0%, #6b7280 100%);
}

#menu-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,.5);
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .container { padding: 10px; }
    h1 { font-size: 2em; letter-spacing: 2px; }
    .screen { padding: 22px 16px; }
    .difficulty-buttons { gap: 12px; }
    .difficulty-btn {
        padding: 12px 14px;
        gap: 12px;
        font-size: 1em;
    }
    .diff-icon { font-size: 1.6em; }
    .diff-name { font-size: 1.15em; letter-spacing: 2px; }
    .diff-desc { font-size: .72em; }
    .diff-badge { padding: 4px 8px; font-size: .7em; }
    .game-header {
        flex-direction: column;
        gap: 12px;
    }
    .complete-buttons {
        flex-direction: column;
        align-items: center;
    }
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 10px;
    }
    .image-item { height: 90px; }
}
