/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    min-height: 100vh;
    font-family: 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
    color: #fff;
    user-select: none;
    overflow-x: hidden;
}

a { color: #48dbfb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Top Navigation ===== */
.top-nav {
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
    padding: 10px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-nav .logo {
    font-size: 1.3rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.top-nav .nav-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.top-nav .nav-btn {
    padding: 7px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
    color: #fff;
    background: rgba(255,255,255,0.08);
}

.top-nav .nav-btn:hover {
    background: rgba(255,255,255,0.15);
    transform: translateY(-1px);
}

.top-nav .nav-btn.primary {
    background: linear-gradient(135deg, #00b894, #00cec9);
}

.top-nav .nav-btn.danger {
    background: rgba(255,107,107,0.2);
    color: #ff6b6b;
}

.top-nav .lang-btn {
    background: rgba(255, 215, 0, 0.15);
    color: #ffd700;
    font-weight: 600;
    border: 1px solid rgba(255, 215, 0, 0.3);
    margin-left: 4px;
}

.top-nav .lang-btn:hover {
    background: rgba(255, 215, 0, 0.3);
}

.top-nav .user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #aabbcc;
    font-size: 0.9rem;
}

.top-nav .user-info .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
    color: #fff;
}

/* ===== Main Layout ===== */
.main-container {
    max-width: 1150px;
    margin: 0 auto;
    padding: 10px 20px 30px;
}

/* ===== Pages (show/hide) ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== Auth Page ===== */
.auth-container {
    max-width: 420px;
    margin: 40px auto;
}

.auth-card {
    background: rgba(255,255,255,0.05);
    border-radius: 20px;
    padding: 40px;
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
}

.auth-card h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 8px;
    color: #48dbfb;
}

.auth-card .auth-subtitle {
    text-align: center;
    color: #667788;
    margin-bottom: 25px;
    font-size: 0.9rem;
}

.auth-tabs {
    display: flex;
    margin-bottom: 25px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    overflow: hidden;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: #667788;
    border: none;
    background: none;
    font-family: inherit;
    transition: all 0.3s;
}

.auth-tab.active {
    background: rgba(72, 219, 251, 0.15);
    color: #48dbfb;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: #8899aa;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    background: rgba(0,0,0,0.3);
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s;
    outline: none;
}

.form-group input:focus {
    border-color: #48dbfb;
}

.form-group input::placeholder {
    color: rgba(255,255,255,0.2);
}

.auth-submit {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: bold;
    cursor: pointer;
    font-family: inherit;
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: #fff;
    transition: all 0.2s;
    margin-top: 5px;
}

.auth-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0,184,148,0.3);
}

.auth-error {
    background: rgba(255,107,107,0.15);
    color: #ff6b6b;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 15px;
    display: none;
    text-align: center;
}

.auth-error.show { display: block; }

/* ===== Game Page ===== */
.game-header {
    text-align: center;
    margin-bottom: 5px;
}

.game-header h1 {
    font-size: 2rem;
    text-shadow: 0 0 20px rgba(100, 200, 255, 0.5);
    letter-spacing: 4px;
}

.game-header .subtitle {
    font-size: 0.85rem;
    color: #667788;
    margin-top: 2px;
}

/* Info bar */
.info-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
    margin: 8px 0;
    flex-wrap: wrap;
}

.info-item {
    background: rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 5px 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 100px;
    justify-content: center;
}

.info-item .label {
    color: #667788;
    font-size: 0.75rem;
}

.info-item .value {
    font-weight: bold;
    font-size: 1.1rem;
    color: #fff;
}

.info-item .value.time-warning {
    color: #ff6b6b;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 1; }
    to { opacity: 0.5; }
}

/* Timer bar */
.timer-bar-container {
    width: 100%;
    max-width: 530px;
    height: 5px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    margin: 0 auto 10px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    background: linear-gradient(90deg, #00b894, #55efc4);
    border-radius: 3px;
    transition: width 0.3s linear;
}

.timer-bar.low {
    background: linear-gradient(90deg, #e17055, #ff6b6b);
}

/* Grid */
.grid-wrapper {
    display: flex;
    justify-content: center;
}

.grid-container {
    background-color: #e4e4e4;
    background-image:
        linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
        linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
        linear-gradient(-45deg, transparent 75%, #d8d8d8 75%);
    /* background-size = 2 × (cell 26px + gap 3px) = 58px */
    background-size: 58px 58px;
    /* offset by container padding (7px) so squares align with cells */
    background-position: 7px 7px, 7px 36px, 36px -22px, -22px 7px;
    border-radius: 16px;
    padding: 7px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    border: 1px solid rgba(200,210,220,0.15);
    display: inline-block;
    position: relative;
}

/* Game Start Overlay */
.game-start-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(6px);
}

.game-start-overlay.hidden {
    display: none;
}

.start-content {
    text-align: center;
    animation: startPulse 2s ease-in-out infinite;
}

.start-title {
    font-size: 3rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.6), 0 0 60px rgba(255, 215, 0, 0.3);
    margin-bottom: 12px;
    letter-spacing: 4px;
}

.start-subtitle {
    color: rgba(255,255,255,0.6);
    font-size: 0.95rem;
    margin-bottom: 25px;
}

.btn-game-start {
    font-size: 1.3rem;
    padding: 14px 50px;
    background: linear-gradient(135deg, #ffd700, #ff8c00);
    color: #000;
    font-weight: 800;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-game-start:hover {
    transform: scale(1.08);
    box-shadow: 0 0 35px rgba(255, 215, 0, 0.7);
}

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

.grid {
    display: grid;
    gap: 3px;
}

.cell {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s, opacity 0.3s;
    position: relative;
}

.cell.empty {
    background: rgba(220,220,220,0.15);
    border: 1px solid rgba(200,200,200,0.2);
}

.cell.empty:hover {
    background: rgba(220,220,220,0.32);
    border-color: rgba(220,220,220,0.5);
    transform: scale(1.06);
}

.cell.tile {
    cursor: default;
}

.cell.tile:hover {
    transform: scale(1.06);
}

/* Tile colors — 10 colors */
.cell.color-0 { background: linear-gradient(135deg, #ff7675, #d63031); }  /* 紅 */
.cell.color-1 { background: linear-gradient(135deg, #81ecec, #00cec9); }  /* 水藍 */
.cell.color-2 { background: linear-gradient(135deg, #ffeaa7, #fdcb6e); }  /* 黃 */
.cell.color-3 { background: linear-gradient(135deg, #55efc4, #00b894); }  /* 綠 */
.cell.color-4 { background: linear-gradient(135deg, #d8a5f5, #a855f7); }  /* 紫 */
.cell.color-5 { background: linear-gradient(135deg, #ff9ff3, #e84393); }  /* 粉紅 */
.cell.color-6 { background: linear-gradient(135deg, #ffa94d, #e8590c); }  /* 橘 */
.cell.color-7 { background: linear-gradient(135deg, #74b9ff, #0984e3); }  /* 藍 */
.cell.color-8 { background: linear-gradient(135deg, #b2bec3, #636e72); }  /* 灰 */
.cell.color-9 { background: linear-gradient(135deg, #d4a574, #8b5e3c); }  /* 棕 */

/* Shape mode */
.shape-mode .cell.tile::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 17px;
    font-weight: bold;
}
.shape-mode .cell.color-0::after { content: '●'; color: #fff8f8; text-shadow: 0 0 5px rgba(255,80,80,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 紅亮 */
.shape-mode .cell.color-1::after { content: 'I';  color: #f0ffff; text-shadow: 0 0 5px rgba(0,230,230,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 水藍亮 */
.shape-mode .cell.color-2::after { content: '▲'; color: #fffff0; text-shadow: 0 0 5px rgba(255,220,0,0.9),   0 1px 2px rgba(0,0,0,0.4); }  /* 黃亮 */
.shape-mode .cell.color-3::after { content: '◆'; color: #f0fff8; text-shadow: 0 0 5px rgba(0,220,150,0.9),   0 1px 2px rgba(0,0,0,0.4); }  /* 綠亮 */
.shape-mode .cell.color-4::after { content: '▼'; color: #fdf0ff; text-shadow: 0 0 5px rgba(180,80,255,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 紫亮 */
.shape-mode .cell.color-5::after { content: '－'; color: #fff0fd; text-shadow: 0 0 5px rgba(255,80,220,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 粉紅亮 */
.shape-mode .cell.color-6::after { content: '★'; color: #fff8f0; text-shadow: 0 0 5px rgba(255,140,0,0.9),   0 1px 2px rgba(0,0,0,0.4); }  /* 橘亮 */
.shape-mode .cell.color-7::after { content: '⬟'; color: #f0f8ff; text-shadow: 0 0 5px rgba(50,150,255,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 藍亮 */
.shape-mode .cell.color-8::after { content: '＝'; color: #f8fafb; text-shadow: 0 0 5px rgba(160,180,190,0.9), 0 1px 2px rgba(0,0,0,0.4); }  /* 灰亮 */
.shape-mode .cell.color-9::after { content: '✦'; color: #fff5ec; text-shadow: 0 0 5px rgba(200,130,60,0.9),  0 1px 2px rgba(0,0,0,0.4); }  /* 棕亮 */

/* Animations */
/* Game Buttons */
.btn-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 12px;
    flex-wrap: wrap;
}

.btn {
    padding: 9px 22px;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    font-family: inherit;
    color: #fff;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.btn-start { background: linear-gradient(135deg, #00b894, #00cec9); }
.btn-shape { background: linear-gradient(135deg, #6c5ce7, #a29bfe); }
.btn-shape.active { background: linear-gradient(135deg, #fdcb6e, #e17055); }
.btn-leaderboard { background: linear-gradient(135deg, #fd79a8, #e84393); }
.btn-history { background: linear-gradient(135deg, #0984e3, #74b9ff); }

/* ===== How to Play ===== */
.how-to-play {
    max-width: 640px;
    margin: 14px auto 4px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 14px 20px;
}
.how-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #a29bfe;
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.how-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.how-list li {
    font-size: 0.82rem;
    color: rgba(255,255,255,0.65);
    line-height: 1.5;
}
.how-list li b {
    color: rgba(255,255,255,0.9);
    font-weight: 600;
}

/* ===== Volume Control ===== */
.volume-control {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 20px;
    padding: 0 12px 0 8px;
    height: 38px;
}
.volume-icon {
    font-size: 18px;
    cursor: pointer;
    user-select: none;
    line-height: 1;
}
.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.3);
    outline: none;
    cursor: pointer;
}
.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #a29bfe;
    cursor: pointer;
    transition: background 0.2s;
}
.volume-slider::-webkit-slider-thumb:hover {
    background: #fdcb6e;
}
.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #a29bfe;
    border: none;
    cursor: pointer;
}

/* ===== Overlay / Modal ===== */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    backdrop-filter: blur(5px);
}

.overlay.hidden { display: none; }

.modal {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border-radius: 20px;
    padding: 35px 45px;
    text-align: center;
    box-shadow: 0 15px 50px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.08);
    max-width: 440px;
    width: 90%;
}

.modal h2 {
    font-size: 1.6rem;
    margin-bottom: 8px;
    color: #feca57;
}

.modal .final-score {
    font-size: 3rem;
    font-weight: bold;
    color: #55efc4;
    margin: 12px 0;
}

.modal .detail {
    color: #667788;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.modal .btn { margin-top: 18px; }

.modal .rank-badge {
    display: inline-block;
    padding: 4px 16px;
    border-radius: 20px;
    background: linear-gradient(135deg, #fdcb6e, #e17055);
    font-size: 0.85rem;
    font-weight: bold;
    margin-top: 8px;
}

/* ===== Leaderboard Page ===== */
.leaderboard-container {
    max-width: 700px;
    margin: 20px auto;
}

.leaderboard-container h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 5px;
    color: #feca57;
}

.leaderboard-subtitle {
    text-align: center;
    color: #667788;
    margin-bottom: 20px;
    font-size: 0.85rem;
}

.lb-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    overflow: hidden;
    max-width: 450px;
    margin-left: auto;
    margin-right: auto;
}

.lb-tab {
    flex: 1;
    padding: 10px 14px;
    text-align: center;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #667788;
    border: none;
    background: none;
    font-family: inherit;
    transition: all 0.3s;
}

.lb-tab.active {
    background: rgba(254, 202, 87, 0.15);
    color: #feca57;
}

.lb-table-wrap {
    background: rgba(255,255,255,0.03);
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.06);
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 490px; /* ~10 rows; scrollbar appears if >10 */
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(162,155,254,0.5) rgba(255,255,255,0.04);
}
.lb-table-wrap::-webkit-scrollbar {
    width: 6px;
}
.lb-table-wrap::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.03);
    border-radius: 3px;
}
.lb-table-wrap::-webkit-scrollbar-thumb {
    background: rgba(162,155,254,0.5);
    border-radius: 3px;
}
.lb-table-wrap::-webkit-scrollbar-thumb:hover {
    background: rgba(162,155,254,0.8);
}

.lb-table {
    width: 100%;
    border-collapse: collapse;
}

.lb-table th {
    background: #1a1a2e;
    padding: 12px 16px;
    font-size: 0.8rem;
    color: #667788;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 1;
}

.lb-table td {
    padding: 12px 16px;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    background: #12122a;
}

.lb-table tr:last-child td {
    border-bottom: none;
}

.lb-table tr:hover td {
    background: #1a1a38;
}

.lb-rank {
    font-weight: bold;
    font-size: 1.1rem;
    width: 50px;
    text-align: center;
}

.lb-rank.gold { color: #feca57; }
.lb-rank.silver { color: #b2bec3; }
.lb-rank.bronze { color: #e17055; }

.lb-name {
    font-weight: 600;
}

.lb-score {
    color: #55efc4;
    font-weight: bold;
    font-size: 1.05rem;
}

.lb-time { color: #48dbfb; }

.lb-cleared {
    color: #feca57;
    font-size: 0.8rem;
}

.lb-empty {
    text-align: center;
    padding: 40px;
    color: #556677;
}

/* ===== History Page ===== */
.history-container {
    max-width: 700px;
    margin: 20px auto;
}

.history-container h2 {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 5px;
    color: #48dbfb;
}

.history-subtitle {
    text-align: center;
    color: #667788;
    margin-bottom: 20px;
    font-size: 0.85rem;
}

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 25px;
}

.stat-card {
    background: rgba(255,255,255,0.05);
    border-radius: 14px;
    padding: 18px 12px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.05);
}

.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: bold;
    color: #55efc4;
}

.stat-card .stat-label {
    font-size: 0.75rem;
    color: #667788;
    margin-top: 4px;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    .cell { width: 10px; height: 10px; border-radius: 2px; }
    .grid { gap: 1px; }
    .grid-container { padding: 5px; }
    .game-header h1 { font-size: 1.4rem; }
    .info-bar { gap: 8px; }
    .info-item { padding: 6px 12px; min-width: 90px; }
    .auth-card { padding: 25px; }
    .modal { padding: 25px 20px; }
    .top-nav { padding: 8px 15px; }
    .top-nav .logo { font-size: 1.1rem; }
    .lb-table th, .lb-table td { padding: 8px 10px; font-size: 0.8rem; }
    .start-title { font-size: 1.6rem; }
    .start-subtitle { font-size: 0.75rem; }
    .btn-game-start { font-size: 1rem; padding: 10px 35px; }
}
