* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-tertiary: #1a1a2e;
    --board-color: #dcb35c;
    --board-dark: #c9a24d;
    --line-color: #2a2318;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    --accent-gold: #ffd700;
    --accent-purple: #a855f7;
    --accent-glow: rgba(255, 215, 0, 0.4);
    --win-color: #22c55e;
    --win-glow: rgba(34, 197, 94, 0.5);
    --black-stone: #1a1a1a;
    --black-stone-highlight: #3a3a3a;
    --white-stone: #f5f5f0;
    --white-stone-shadow: #c0c0b8;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    overflow-x: hidden;
    position: relative;
}

/* Background Effects */
.bg-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s ease-in-out infinite;
}

.bg-orb:nth-child(1) {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #a855f7, #6366f1);
    top: -100px;
    left: -100px;
    animation-delay: 0s;
}

.bg-orb:nth-child(2) {
    width: 300px;
    height: 300px;
    background: linear-gradient(135deg, #ffd700, #ff8c00);
    bottom: -50px;
    right: -50px;
    animation-delay: -7s;
}

.bg-orb:nth-child(3) {
    width: 250px;
    height: 250px;
    background: linear-gradient(135deg, #22c55e, #06b6d4);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(20px, 10px) scale(1.02); }
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 500px;
    width: 100%;
    position: relative;
    z-index: 1;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 4px;
}

.title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.6rem;
    font-weight: 400;
    background: linear-gradient(135deg, #fff 0%, var(--accent-gold) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.home-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.home-link:hover {
    color: var(--accent-gold);
    background: var(--bg-tertiary);
}

.controls {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Jua', sans-serif;
    color: white;
    background: var(--bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn:hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
}

/* Board Size Selector */
.board-size-selector {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 10px;
}

.size-btn {
    padding: 6px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Jua', sans-serif;
    color: var(--text-secondary);
    background: rgba(255, 215, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.size-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent-gold);
}

.size-btn.active {
    color: var(--bg-primary);
    background: var(--accent-gold);
    border-color: var(--accent-gold);
}

/* Player Info */
.player-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.player {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-stone {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.player-stone.black {
    background: radial-gradient(ellipse at 30% 30%, var(--black-stone-highlight), var(--black-stone));
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.player-stone.white {
    background: radial-gradient(ellipse at 30% 30%, var(--white-stone), var(--white-stone-shadow));
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.player.active .player-stone {
    border-color: var(--accent-gold);
    box-shadow: 0 0 15px var(--accent-glow);
}

.player.winner .player-stone {
    border-color: var(--win-color);
    box-shadow: 0 0 20px var(--win-glow);
}

.player-details {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-primary);
}

.player-status {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.player.active .player-status {
    color: var(--accent-gold);
}

.player.winner .player-status {
    color: var(--win-color);
}

.score-box {
    text-align: center;
}

.score-value {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--accent-gold);
}

.score-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Board */
.board-wrapper {
    position: relative;
    padding: 12px;
    background: var(--board-color);
    border-radius: 8px;
    box-shadow:
        0 0 0 4px var(--board-dark),
        0 20px 50px rgba(0, 0, 0, 0.5),
        inset 0 0 30px rgba(0, 0, 0, 0.1);
}

.board {
    display: grid;
    position: relative;
    background: var(--board-color);
}

.intersection {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.intersection::before {
    content: '';
    position: absolute;
    background: var(--line-color);
    width: 100%;
    height: 1px;
    top: 50%;
    transform: translateY(-50%);
}

.intersection::after {
    content: '';
    position: absolute;
    width: 1px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--line-color);
}

/* Edge adjustments */
.intersection.top::after { top: 50%; height: 50%; }
.intersection.bottom::after { bottom: 50%; height: 50%; }
.intersection.left::before { left: 50%; width: 50%; }
.intersection.right::before { right: 50%; width: 50%; }

/* Star points */
.star-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--line-color);
    border-radius: 50%;
    z-index: 1;
}

/* Stones */
.stone {
    width: 90%;
    height: 90%;
    border-radius: 50%;
    position: relative;
    z-index: 2;
    transition: transform 0.15s ease;
}

.stone.black {
    background: radial-gradient(ellipse at 30% 30%, var(--black-stone-highlight), var(--black-stone));
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.stone.white {
    background: radial-gradient(ellipse at 30% 30%, var(--white-stone), var(--white-stone-shadow));
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.stone.last-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: var(--accent-gold);
}

.stone.winning {
    animation: winPulse 0.6s ease-in-out infinite alternate;
}

.stone.winning::after {
    background: var(--win-color);
}

@keyframes winPulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Preview stone */
.intersection:hover .preview-stone {
    opacity: 0.5;
}

.preview-stone {
    width: 90%;
    height: 90%;
    border-radius: 50%;
    position: absolute;
    opacity: 0;
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.15s ease;
}

.preview-stone.black {
    background: radial-gradient(ellipse at 30% 30%, var(--black-stone-highlight), var(--black-stone));
}

.preview-stone.white {
    background: radial-gradient(ellipse at 30% 30%, var(--white-stone), var(--white-stone-shadow));
}

/* Move number on stone */
.move-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.6rem;
    font-weight: 700;
    z-index: 3;
    pointer-events: none;
}

.stone.black .move-number { color: var(--white-stone); }
.stone.white .move-number { color: var(--black-stone); }

/* Status Bar */
.status-bar {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-text {
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-primary);
}

.status-text.win {
    color: var(--win-color);
}

/* Place Button */
.place-btn {
    padding: 8px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: 'Jua', sans-serif;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    cursor: not-allowed;
    transition: all 0.2s ease;
    min-height: 44px;
}

.place-btn:disabled {
    opacity: 0.5;
}

.place-btn.active {
    color: var(--bg-primary);
    background: linear-gradient(135deg, var(--accent-gold), #ffaa00);
    border-color: var(--accent-gold);
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
    animation: place-btn-pulse 1s ease-in-out infinite;
}

.place-btn.active:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.5);
}

@keyframes place-btn-pulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4); }
    50% { box-shadow: 0 4px 25px rgba(255, 215, 0, 0.6); }
}

/* Options */
.options {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
}

.option-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.option-item input {
    accent-color: var(--accent-gold);
}

/* Game Over Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

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

.modal-content {
    text-align: center;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 24px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.1),
        0 30px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
    min-width: 280px;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.modal-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.8rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.modal-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.modal-moves {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.modal-btn {
    padding: 14px 40px;
    font-size: 1rem;
    font-weight: 400;
    font-family: 'Jua', sans-serif;
    color: var(--bg-primary);
    background: linear-gradient(135deg, var(--accent-gold), #ff8c00);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

/* Move counter */
.move-counter {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
}

/* Game Content */
.game-content {
    width: 100%;
    max-width: 500px;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 16px;
    margin-top: 16px;
}

.game-content h2 {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.3rem;
    color: var(--accent-gold);
    margin-bottom: 12px;
}

.game-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
}

.game-content ul {
    list-style: none;
    padding: 0;
}

.game-content li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 0;
    padding-left: 20px;
    position: relative;
}

.game-content li::before {
    content: '•';
    color: var(--accent-gold);
    position: absolute;
    left: 0;
}

/* Footer */
footer {
    width: 100%;
    max-width: 500px;
    text-align: center;
    padding: 20px;
    margin-top: 20px;
}

footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--accent-gold);
}

/* Tap-Confirm Selected State */
.intersection.selected {
    z-index: 10;
}

.intersection.selected::before,
.intersection.selected::after {
    background: var(--accent-gold);
}

.intersection.selected .preview-stone {
    opacity: 0.8 !important;
    animation: pulse-confirm 0.8s ease-in-out infinite;
}

@keyframes pulse-confirm {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* AI Thinking Indicator */
.ai-thinking {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px 48px;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    z-index: 200;
}

.ai-thinking.active {
    display: flex;
}

.ai-thinking-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.ai-thinking-text {
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
}

/* Start Overlay */
.start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 10, 26, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

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

.start-content {
    text-align: center;
    padding: 40px;
    max-width: 400px;
    width: 90%;
}

.start-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: float-icon 3s ease-in-out infinite;
}

@keyframes float-icon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.start-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.start-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.mode-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 24px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px 32px;
    background: var(--bg-secondary);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: var(--accent-gold);
    background: var(--bg-tertiary);
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.mode-icon {
    font-size: 2.5rem;
}

.mode-text {
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
}

.difficulty-section {
    margin-top: 24px;
}

.difficulty-section.hidden {
    display: none;
}

.difficulty-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.difficulty-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.difficulty-btn {
    padding: 12px 24px;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-btn:hover {
    border-color: var(--accent-gold);
    transform: translateY(-2px);
}

.difficulty-btn[data-difficulty="easy"]:hover {
    border-color: #22c55e;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}

.difficulty-btn[data-difficulty="normal"]:hover {
    border-color: var(--accent-gold);
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}

.difficulty-btn[data-difficulty="hard"]:hover {
    border-color: #ef4444;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

/* Responsive */
@media (max-width: 420px) {
    .board-wrapper {
        padding: 8px;
    }

    .player-info {
        padding: 10px 12px;
    }

    .header {
        flex-direction: column;
        gap: 10px;
    }

    .options {
        flex-wrap: wrap;
        justify-content: center;
    }

    .game-content {
        display: none;
    }

    .mode-buttons {
        flex-direction: column;
        gap: 12px;
    }

    .mode-btn {
        padding: 20px 24px;
    }

    .difficulty-buttons {
        flex-wrap: wrap;
    }
}

/* Continue Modal */
.continue-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

.continue-modal-content {
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    max-width: 320px;
    width: 90%;
}

.continue-modal-title {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 15px;
}

.continue-modal-score {
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    color: var(--accent-gold);
    margin-bottom: 25px;
}

.continue-modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.continue-btn {
    padding: 14px 30px;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), #9333ea);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.continue-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 5px 20px var(--accent-glow);
}

.newgame-btn {
    padding: 12px 25px;
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.newgame-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}
