:root {
    --primary-color: #4facfe;
    --secondary-color: #00f2fe;
    --accent-color: #ff9a9e;
    --bg-color: #f0f2f5;
    --text-color: #333;
    --board-spacing: 2px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.container {
    width: 100%;
    max-width: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

/* Header Layout */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    position: relative;
    padding: 10px 0;
}

/* Back Button */
.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: white;
    border-radius: 50%;
    color: #666;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    cursor: pointer;
    z-index: 2;
    /* Ensure clickable */
}

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

/* Center Title */
.title {
    font-size: 24px;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;

    /* Absolute centering technique */
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
}

/* Right Status Area */
.header-status {
    display: flex;
    gap: 15px;
    z-index: 2;
}

.status-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.status-group .label {
    font-size: 10px;
    color: #999;
    margin-bottom: 2px;
}

.status-group .value {
    font-size: 16px;
    font-weight: bold;
    color: var(--text-color);
    font-family: monospace;
    line-height: 1;
}

/* Game Area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    position: relative;
}

/* Puzzle Board */
.board {
    /* 核心: 使用 vmin 确保在横屏竖屏都适配 */
    width: min(90vw, 50vh);
    height: min(90vw, 50vh);
    background: #ddd;
    border: 5px solid #fff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    position: relative;
    /* CSS Grid 将由 JS 动态设置 */
    display: grid;
    gap: var(--board-spacing);
    transition: filter 0.3s;
}

/* 模糊效果 - 用于未开始时 */
.board.blur-effect {
    filter: blur(5px) grayscale(0.8);
}

.tile {
    background-image: url('./res/img/default.jpg');
    background-repeat: no-repeat;
    /* background-size 由 JS 计算并设置 */
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
    border-radius: 2px;
}

.tile:active {
    transform: scale(0.95);
    z-index: 10;
}

.tile.empty {
    background: transparent;
    cursor: default;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.05);
}

/* Preview */
.original-preview {
    text-align: center;
}

.original-preview p {
    font-size: 12px;
    color: #999;
    margin-bottom: 5px;
}

#preview-img {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* Difficulty Buttons (in Modal) */
.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.btn-diff {
    width: 100%;
    border: none;
    background: #fff;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 16px;
    color: #555;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-diff:active {
    transform: scale(0.98);
}

.btn-diff.active {
    background: var(--primary-color);
    color: white;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    width: 80%;
    max-width: 320px;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-content h2 {
    color: var(--text-color);
    margin-bottom: 20px;
}

.stats-result {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 25px;
}

.stats-result p {
    margin: 8px 0;
    color: #666;
    display: flex;
    justify-content: space-between;
}

.stats-result span {
    font-weight: bold;
    color: var(--primary-color);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.4);
    transition: transform 0.2s;
}

/* Preview Content */
.preview-content {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    max-width: 90vw !important;
    width: auto !important;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#big-preview-img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 3px solid white;
}

#preview-img {
    cursor: zoom-in;
    transition: transform 0.2s;
}

#preview-img:hover {
    transform: scale(1.05);
}

.modal-content.preview-content {
    background: transparent;
}