:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f3f4f6;
    --board-bg: #e5e7eb;
    --tile-bg: #ffffff;
    --tile-color: #1f2937;
    --text-color: #111827;
    --border-radius: 8px;
    --transition-speed: 0.2s;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px; /* 减小移动端 padding */
    margin: 0;
}

.container {
    background: white;
    padding: 1.5rem; /* 减小内边距 */
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 1rem;
}

h1 {
    font-size: 1.8rem; /* 稍微调小标题 */
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem; /* 调小字体 */
}

select, button {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: var(--border-radius);
    font-size: 14px;
    outline: none;
    /* 增加触摸目标大小 */
    min-height: 40px; 
}

select {
    background-color: white;
    cursor: pointer;
    /* 移除默认样式，在移动端更好看 */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 24px;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23111827%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 8px top 50%;
    background-size: 10px auto;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background-color var(--transition-speed);
    /* 防止移动端双击缩放 */
    touch-action: manipulation;
}

button:hover {
    background-color: var(--primary-hover);
}

.secondary-btn {
    background-color: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.secondary-btn:hover {
    background-color: #e5e7eb;
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stats {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1.5rem;
    background-color: var(--bg-color);
    padding: 10px;
    border-radius: var(--border-radius);
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}

.board {
    background-color: var(--board-bg);
    border-radius: var(--border-radius);
    padding: 10px;
    display: grid;
    gap: 5px;
    margin: 0 auto;
    width: 100%;
    /* 限制最大宽度，防止在 iPad 上过大 */
    max-width: 450px;
    aspect-ratio: 1 / 1;
    position: relative;
    /* 防止移动端滑动时触发页面滚动 */
    touch-action: none;
}

.tile {
    background-color: var(--tile-bg);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 使用相对单位，自适应屏幕 */
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: bold;
    color: var(--tile-color);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none; /* Safari */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform var(--transition-speed) ease-in-out;
    background-size: cover;
    background-position: center;
    /* 防止移动端长按弹出菜单 */
    -webkit-touch-callout: none;
}

.tile.empty {
    background: transparent;
    box-shadow: none;
    cursor: default;
}

.image-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 1.5rem;
}

.hidden {
    display: none !important;
}

/* 弹窗样式 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-width: 90%;
    width: 350px;
    position: relative;
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.modal-content p {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.modal-content button {
    margin-top: 1.5rem;
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
}

.preview-content {
    width: auto;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
}

.preview-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
    margin-top: 1rem;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
}

/* 媒体查询：针对小屏幕手机 */
@media (max-width: 400px) {
    .container {
        padding: 1rem;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .controls {
        gap: 5px;
    }
    
    select, button {
        padding: 6px 10px;
        font-size: 13px;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
}