/* CSS 變數定義六種主題 */
:root {
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --board-bg: #ffffff;
    --board-border: #d1d5db;
    --line-color: #9ca3af;
    --x-color: #ef4444;
    --o-color: #3b82f6;
    --primary-btn: #4f46e5;
    --primary-btn-hover: #4338ca;
    --shop-bg: #e5e7eb;
    --accent: #f59e0b;
}
[data-theme="dark"] {
    --bg-color: #111827; --text-color: #f9fafb; --board-bg: #1f2937;
    --board-border: #374151; --line-color: #4b5563; --x-color: #f87171;
    --o-color: #60a5fa; --primary-btn: #6366f1; --primary-btn-hover: #4f46e5;
    --shop-bg: #374151; --accent: #fbbf24;
}
[data-theme="neon"] {
    --bg-color: #000000; --text-color: #ffffff; --board-bg: #0a0a0a;
    --board-border: #ff00ff; --line-color: #00ffff; --x-color: #ff00ff;
    --o-color: #00ffff; --primary-btn: #ff00ff; --primary-btn-hover: #cc00cc;
    --shop-bg: #1a1a1a; --accent: #00ff00; text-shadow: 0 0 5px var(--line-color);
}
[data-theme="retro"] {
    --bg-color: #2d3748; --text-color: #48bb78; --board-bg: #1a202c;
    --board-border: #48bb78; --line-color: #48bb78; --x-color: #48bb78;
    --o-color: #48bb78; --primary-btn: #38a169; --primary-btn-hover: #2f855a;
    --shop-bg: #2d3748; --accent: #ecc94b; font-family: 'Courier New', Courier, monospace;
}
[data-theme="ocean"] {
    --bg-color: #e0f2fe; --text-color: #0369a1; --board-bg: #bae6fd;
    --board-border: #7dd3fc; --line-color: #38bdf8; --x-color: #0284c7;
    --o-color: #0ea5e9; --primary-btn: #0284c7; --primary-btn-hover: #0369a1;
    --shop-bg: #7dd3fc; --accent: #fcd34d;
}
[data-theme="desert"] {
    --bg-color: #fef3c7; --text-color: #92400e; --board-bg: #fde68a;
    --board-border: #fcd34d; --line-color: #fbbf24; --x-color: #b45309;
    --o-color: #d97706; --primary-btn: #d97706; --primary-btn-hover: #b45309;
    --shop-bg: #fcd34d; --accent: #ef4444;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

nav { z-index: 50; backdrop-filter: blur(8px); }

.btn-primary { background-color: var(--primary-btn); color: white; transition: background-color 0.2s, transform 0.1s; }
.btn-primary:hover { background-color: var(--primary-btn-hover); }
.btn-primary:active { transform: scale(0.95); }

.player-icon {
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: grayscale(100%); opacity: 0.3; transform: scale(0.8);
}
.player-icon.active { filter: grayscale(0%); opacity: 1; transform: scale(1); }
.player-icon.active.my-turn { transform: scale(1.3); }

.pop-in { animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
@keyframes popIn { 0% { opacity: 0; transform: scale(0.3); } 100% { opacity: 1; transform: scale(1); } }

.board-dynamic {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    background-color: var(--line-color);
    width: 100%; max-width: min(100%, 400px, 55vh);
    margin: 0 auto; aspect-ratio: 1; position: relative; /* 必須為 relative 以繪製勝利線 */
}
.cell {
    background-color: var(--bg-color); display: flex; justify-content: center; align-items: center;
    font-size: 4rem; font-weight: bold; cursor: pointer; transition: background-color 0.2s, opacity 0.3s;
    user-select: none; aspect-ratio: 1; overflow: hidden; line-height: 1;
}
.cell:hover { filter: brightness(0.95); }
.cell.x { color: var(--x-color); }
.cell.o { color: var(--o-color); }

.fading { opacity: 0.3; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

.board-ultimate {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    background-color: var(--line-color); border: 6px solid var(--line-color); border-radius: 8px;
    width: 100%; max-width: min(100%, 500px, 60vh);
    margin: 0 auto; aspect-ratio: 1; position: relative; /* 必須為 relative 以繪製勝利線 */
}

.sub-board {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
    background-color: var(--board-border); position: relative; aspect-ratio: 1;
}
.sub-board.active-board { box-shadow: 0 0 15px var(--accent) inset; background-color: var(--accent); }
.sub-board .cell { font-size: 1.5rem; }

.winner-overlay {
    position: absolute; inset: 0; display: flex; justify-content: center; align-items: center;
    font-size: 5rem; font-weight: bold; background-color: var(--board-bg); opacity: 0.9; z-index: 10;
}

/* 勝利劃線動畫設定 */
.strike-line {
    position: absolute;
    z-index: 20;
    border-radius: 999px;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    animation: drawLine 0.4s ease-out forwards;
}
.strike-row-1 { top: calc(16.66% - 6px); left: 2%; width: 96%; height: 12px; }
.strike-row-2 { top: calc(50% - 6px); left: 2%; width: 96%; height: 12px; }
.strike-row-3 { top: calc(83.33% - 6px); left: 2%; width: 96%; height: 12px; }
.strike-col-1 { left: calc(16.66% - 6px); top: 2%; height: 96%; width: 12px; animation-name: drawLineVert; }
.strike-col-2 { left: calc(50% - 6px); top: 2%; height: 96%; width: 12px; animation-name: drawLineVert; }
.strike-col-3 { left: calc(83.33% - 6px); top: 2%; height: 96%; width: 12px; animation-name: drawLineVert; }
.strike-diag-1 { top: calc(50% - 6px); left: -10%; width: 120%; height: 12px; transform: rotate(45deg); }
.strike-diag-2 { top: calc(50% - 6px); left: -10%; width: 120%; height: 12px; transform: rotate(-45deg); }

@keyframes drawLine { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes drawLineVert { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }

.shop-card {
    background-color: var(--shop-bg); border: 2px solid var(--board-border);
    border-radius: 8px; padding: 1.5rem; text-align: center; transition: transform 0.2s;
}
.shop-card:hover { transform: translateY(-5px); }
.tab-btn {
    padding: 0.5rem 0.5rem; font-weight: bold; font-size: 1.1rem; color: var(--line-color);
    background-color: transparent; border-bottom: 2px solid transparent; transition: all 0.2s;
    margin-bottom: -1px; cursor: pointer;
}
.tab-btn.active { color: var(--primary-btn); border-bottom: 2px solid var(--primary-btn); }
.timer-container { width: 100%; background-color: var(--board-border); height: 6px; border-radius: 4px; overflow: hidden; margin-top: 15px; }
.timer-bar { height: 100%; background-color: var(--accent); transition: width 1s linear; }
.timer-bar.warning { background-color: #ef4444; }
.hidden { display: none !important; }