:root {
    --bg-color: #f0f2f5;
    --primary-color: #007aff;
    --tile-bg: #ffffff;
    --tile-color: #333333;
    --record-color: #ff9500;
    --help-color: #34c759;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    touch-action: none; 
    justify-content: center; 
    padding-bottom: 8vh; 
    box-sizing: border-box; 
    overscroll-behavior: none; 
}

h1 { margin-top: 0; margin-bottom: 20px; color: #333; user-select: none; }

#menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 350px;
}

.menu-top-actions { display: flex; gap: 10px; margin-bottom: 5px; }

.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    user-select: none;
}

.btn.leaderboard-btn { background-color: var(--record-color); flex: 1; justify-content: center; }
.btn.help-btn { background-color: var(--help-color); flex: 1; justify-content: center; }
.btn .record-text { font-size: 12px; font-weight: normal; background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 10px; }
.btn:active { transform: scale(0.98); }

#game-container, #leaderboard-container { display: none; flex-direction: column; align-items: center; width: 100%; }

.header {
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 400px;
    margin: 10px 0;
    background: #fff;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    box-sizing: border-box;
    gap: 8px;
    user-select: none;
}

.header-top { display: flex; justify-content: space-between; align-items: center; }
.header-bottom { display: flex; justify-content: center; font-size: 13px; color: var(--record-color); font-weight: bold; }
.back-btn { background-color: #ff3b30; padding: 6px 12px; font-size: 14px; width: auto; }
.stats { display: flex; gap: 12px; font-size: 15px; font-weight: 600; }

#board {
    position: relative;
    background-color: #bbb;
    border-radius: 8px;
    width: 95vmin;
    max-width: 400px;
    height: 95vmin;
    max-height: 400px;
    overflow: hidden;
    border: 2px solid #999;
    touch-action: none; 
}

.tile-wrapper {
    position: absolute;
    transition: top 0.1s ease-in-out, left 0.1s ease-in-out;
    padding: 1px;
    box-sizing: border-box;
    z-index: 1;
}

.tile {
    width: 100%;
    height: 100%;
    background-color: var(--tile-bg);
    color: var(--tile-color);
    font-weight: bold;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    box-shadow: inset 0 0 1px rgba(0,0,0,0.1);
    -webkit-tap-highlight-color: transparent; 
}

/* 開發者模式高亮 */
.tile.dev-highlight { color: #ff3b30 !important; }

.lb-board { background: #fff; width: 90%; max-width: 400px; border-radius: 12px; padding: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); box-sizing: border-box; }
.lb-selector { width: 100%; padding: 10px; font-size: 16px; border-radius: 8px; margin-bottom: 15px; border: 1px solid #ccc; }
.lb-list { list-style: none; padding: 0; margin: 0; max-height: 400px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.lb-item { display: flex; justify-content: space-between; padding: 12px 5px; border-bottom: 1px solid #eee; font-size: 15px; }
.lb-rank { font-weight: bold; color: var(--primary-color); width: 35px; flex-shrink: 0; }
.lb-name { flex-grow: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 10px; }
.lb-score { font-weight: bold; color: #555; flex-shrink: 0; text-align: right; }

#instruction-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; justify-content: center; align-items: center; }
.modal-content { background: white; padding: 25px 20px; border-radius: 16px; width: 85%; max-width: 340px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.2); animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes popIn { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.modal-content h2 { margin-top: 0; font-size: 22px; color: #333; margin-bottom: 15px; }
.instruction-text { text-align: left; font-size: 15px; color: #444; line-height: 1.6; margin-bottom: 20px; background: #f9f9f9; padding: 15px; border-radius: 10px; }
.checkbox-label { display: flex; align-items: center; justify-content: center; margin-bottom: 20px; font-size: 15px; color: #666; cursor: pointer; }
.checkbox-label input { margin-right: 8px; transform: scale(1.2); }
.modal-content .btn { width: 100%; justify-content: center; font-size: 18px; }