/* ============================================
   The2nd Games - 메인 허브 스타일
   테마: 아케이드 라운지 (네온 + 다크)
   ============================================ */

:root {
    /* 기본 */
    --bg-dark: #0a0e27;
    --bg-medium: #1a1f3a;
    --text-primary: #ffffff;
    --text-secondary: #b8b8b8;

    /* 네온 액센트 */
    --neon-cyan: #00ffff;
    --neon-pink: #ff006e;
    --neon-purple: #8338ec;

    /* 게임별 색상 */
    --game1-color: #ff6b35;
    --game2-color: #00d9ff;
    --game3-color: #ffd700;
    --game4-color: #c58b4a;
    --game5-color: #111111;
    --game6-color: #ffbd5a;
    --othello-hub-disc-scale: 1.01;
    --app-height: 100dvh;
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
    --hub-controller-height: clamp(92px, 15dvh, 116px);
    --hub-core-base-width: 352px;
    --hub-core-base-height: 300px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html {
    height: 100%;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    overscroll-behavior: none;
    background-color: var(--bg-dark);
}

body {
    height: 100%;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    margin: 0;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
    font-family: 'Jua', 'Inter', sans-serif;
    background: linear-gradient(180deg,
            var(--bg-dark) 0%,
            var(--bg-medium) 50%,
            var(--bg-dark) 100%);
    color: var(--text-primary);
}

/* ============================================
   메인 컨테이너
   ============================================ */
.hub-container {
    width: 100%;
    height: 100%;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    display: block;
    position: relative;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) var(--app-safe-bottom) env(safe-area-inset-left);
    overflow: hidden;
    overscroll-behavior: none;
}

/* ============================================
   플레이어 섹션
   ============================================ */
.player-section {
    position: absolute;
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    height: var(--hub-controller-height);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25;
}

.player2-section {
    top: env(safe-area-inset-top, 0px);
    transform: rotate(180deg);
}

.player1-section {
    bottom: var(--app-safe-bottom);
}

.hub-container.p2-ai-opponent .player2-section .player-emoji,
.hub-container.p2-ai-opponent .player2-section .player-name,
.hub-container.p2-ai-opponent .player2-section .player-stats {
    transform: rotate(180deg);
}

.player-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 10px 15px;
    max-width: 300px;
    width: 100%;
}

.player-emoji {
    font-size: 2.5rem;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
}

.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.player-name {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.player-stats {
    font-family: 'Jua', sans-serif;
    font-size: 0.95rem;
    color: var(--neon-cyan);
}

.settings-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

/* ============================================
   게임 허브 (중앙)
   ============================================ */
.game-hub {
    position: absolute;
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    top: calc(var(--hub-controller-height) + env(safe-area-inset-top, 0px));
    bottom: calc(var(--hub-controller-height) + var(--app-safe-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 15px;
    overflow: hidden;
    overscroll-behavior: none;
    min-height: 0;
    z-index: 10;
}

.hub-core {
    --hub-core-scale: 1;
    --hub-core-bottom-reserve: 0px;
    width: var(--hub-core-base-width);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    transform: scale(var(--hub-core-scale));
    transform-origin: top center;
    will-change: transform;
    margin: clamp(10px, 1.8vh, 18px) auto var(--hub-core-bottom-reserve);
    position: relative;
    z-index: 1;
}

.hub-title {
    position: absolute;
    top: var(--hub-title-top, clamp(2px, 1.2vh, 12px));
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 24px);
    text-align: center;
    pointer-events: none;
    z-index: 2;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: 0 0 24px rgba(0, 255, 255, 0.58);
    letter-spacing: 2px;
    line-height: 1;
    margin: 0;
    animation: hub-title-neon-breathe 2.4s ease-in-out infinite;
    will-change: text-shadow, opacity;
    isolation: isolate;
}

.hub-title::before,
.hub-title::after {
    content: attr(data-text);
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    z-index: 1;
    mix-blend-mode: screen;
}

.hub-title::before {
    color: #00d9ff;
    text-shadow:
        0 0 12px rgba(0, 217, 255, 0.62),
        0 0 20px rgba(0, 217, 255, 0.34);
    animation: hub-title-glitch-cyan 4.8s steps(1, end) infinite;
}

.hub-title::after {
    color: #ff6b35;
    text-shadow:
        0 0 12px rgba(255, 107, 53, 0.58),
        0 0 20px rgba(255, 107, 53, 0.32);
    animation: hub-title-glitch-orange 5.2s steps(1, end) infinite 0.2s;
}

@keyframes hub-title-neon-breathe {
    0%,
    100% {
        opacity: 0.92;
        text-shadow:
            0 0 12px rgba(0, 217, 255, 0.44),
            0 0 24px rgba(0, 217, 255, 0.28);
    }
    50% {
        opacity: 1;
        text-shadow:
            0 0 16px rgba(0, 217, 255, 0.68),
            0 0 32px rgba(0, 217, 255, 0.4);
    }
}

@keyframes hub-title-glitch-cyan {
    0%,
    67%,
    100% {
        opacity: 0;
        transform: translate(0, 0);
    }
    68% {
        opacity: 0.55;
        transform: translate(-2px, -1px);
    }
    69% {
        opacity: 0.68;
        transform: translate(2px, 0);
    }
    70% {
        opacity: 0.46;
        transform: translate(-2px, 1px);
    }
    71% {
        opacity: 0;
        transform: translate(0, 0);
    }
    83% {
        opacity: 0.38;
        transform: translate(2px, -1px);
    }
    84% {
        opacity: 0.5;
        transform: translate(-2px, 1px);
    }
    85% {
        opacity: 0;
        transform: translate(0, 0);
    }
}

@keyframes hub-title-glitch-orange {
    0%,
    71%,
    100% {
        opacity: 0;
        transform: translate(0, 0);
    }
    72% {
        opacity: 0.52;
        transform: translate(2px, 0);
    }
    73% {
        opacity: 0.66;
        transform: translate(-2px, 1px);
    }
    74% {
        opacity: 0.45;
        transform: translate(2px, -1px);
    }
    75% {
        opacity: 0;
        transform: translate(0, 0);
    }
    88% {
        opacity: 0.34;
        transform: translate(-2px, 0);
    }
    89% {
        opacity: 0.48;
        transform: translate(2px, 1px);
    }
    90% {
        opacity: 0;
        transform: translate(0, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .hub-title {
        animation: hub-title-neon-breathe 3.8s ease-in-out infinite;
    }
    .hub-title::before,
    .hub-title::after {
        opacity: 0;
    }
    .hub-title::before {
        animation-duration: 8.6s;
    }
    .hub-title::after {
        animation-duration: 9.2s;
    }
}

.hub-subtitle {
    font-family: 'Jua', sans-serif;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.resume-last-game-btn {
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(239, 213, 158, 0.58);
    background: rgba(37, 31, 18, 0.78);
    color: #f8e7bc;
    font-family: 'Jua', sans-serif;
    font-size: 0.9rem;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
    box-shadow: 0 0 14px rgba(247, 197, 107, 0.2);
}

.resume-last-game-btn:active {
    transform: scale(0.97);
}

.resume-last-game-btn:hover {
    background: rgba(51, 42, 22, 0.88);
    box-shadow: 0 0 18px rgba(250, 203, 118, 0.34);
}

.version-meta {
    position: absolute;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.version-tag {
    font-family: 'Space Grotesk', monospace;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.2);
}

.version-updated-at {
    font-family: 'Space Grotesk', monospace;
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.18);
    pointer-events: none;
}

/* ============================================
   게임 그리드
   ============================================ */
.game-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 0;
    max-width: none;
    width: 100%;
    margin-inline: auto;
}

.game-card {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--game1-color);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    transition: box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
    transform: translateZ(0);
    backface-visibility: hidden;
    will-change: box-shadow;
}

.game-card:active {
    transform: scale(0.95);
}

.game-card[data-game="the2nd"] {
    border-color: var(--game1-color);
    box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
}

.game-card[data-game="the2nd"]:hover,
.game-card[data-game="the2nd"]:active {
    box-shadow: 0 0 25px rgba(255, 107, 53, 0.6);
}

.game-card[data-game="yachtdice"] {
    border-color: var(--game2-color);
    box-shadow: 0 0 15px rgba(0, 217, 255, 0.3);
}

.game-card[data-game="yachtdice"]:hover,
.game-card[data-game="yachtdice"]:active {
    box-shadow: 0 0 25px rgba(0, 217, 255, 0.6);
}

.game-card[data-game="airhockey"] {
    border-color: var(--game3-color);
    box-shadow: 0 0 13px rgba(255, 215, 0, 0.24);
}

.game-card[data-game="airhockey"]:hover,
.game-card[data-game="airhockey"]:active {
    box-shadow: 0 0 22px rgba(255, 215, 0, 0.46);
}

.game-card[data-game="tankduel"] {
    border-color: var(--game4-color);
    box-shadow: 0 0 15px rgba(197, 139, 74, 0.42);
    gap: 3px;
}

.game-card[data-game="tankduel"]:hover,
.game-card[data-game="tankduel"]:active {
    box-shadow: 0 0 26px rgba(224, 162, 92, 0.68);
}
.game-card[data-game="chess"] {
    border-color: #8f959e;
    box-shadow: 0 0 14px rgba(173, 181, 191, 0.34);
}

.game-card[data-game="chess"]:hover,
.game-card[data-game="chess"]:active {
    box-shadow: 0 0 22px rgba(189, 197, 208, 0.52);
}

.game-card[data-game="chess"] .game-icon {
    color: #f1f3f6;
    text-shadow: 0 0 8px rgba(196, 203, 214, 0.45);
}

.game-card[data-game="chess"] .chess-icon {
    width: 44px;
    height: 44px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    transform: translate(0px, 2px);
}

.chess-icon-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(11, 14, 18, 0.52));
}

.game-card[data-game="othello"] {
    border-color: #00b25a;
    background: rgba(0, 133, 61, 0.16);
    box-shadow: 0 0 14px rgba(0, 133, 61, 0.38);
}

.game-card[data-game="othello"]:hover,
.game-card[data-game="othello"]:active {
    box-shadow: 0 0 22px rgba(0, 168, 78, 0.54);
}

.game-card[data-game="othello"] .game-icon {
    color: #e2ffef;
    text-shadow: 0 0 10px rgba(0, 133, 61, 0.62);
}

.game-card[data-game="othello"] .othello-icon {
    width: 37px;
    height: 37px;
    padding: 3px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    place-items: center;
    gap: 2px;
    border-radius: 5px;
    border: none;
    background: linear-gradient(180deg, #16bf66 0%, #0e8f4f 100%);
    box-shadow:
        inset 0 1px 0 rgba(232, 255, 243, 0.24),
        0 3px 9px rgba(0, 56, 24, 0.42);
    font-size: 0;
}

.game-card[data-game="othello"] .othello-disc {
    border-radius: 50%;
    display: block;
    width: 100%;
    height: 100%;
    transform: scale(var(--othello-hub-disc-scale));
    transform-origin: center;
}

.game-card[data-game="othello"] .othello-disc.white {
    background: #ffffff;
    border: none;
    box-shadow: none;
}

.game-card[data-game="othello"] .othello-disc.black {
    background: #000000;
    border: none;
    box-shadow: none;
}


.game-card[data-game="omok"] {
    border-color: #d8a254;
    box-shadow: 0 0 14px rgba(227, 169, 91, 0.36);
}

.game-card[data-game="omok"]:hover,
.game-card[data-game="omok"]:active {
    box-shadow: 0 0 22px rgba(238, 184, 110, 0.56);
}

.game-card[data-game="omok"] .game-icon {
    color: #f7d8a6;
    text-shadow: 0 0 10px rgba(220, 176, 107, 0.52);
}

/* 잠긴 게임 */
.game-card.locked {
    border-color: #444;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.5;
}

.game-card.locked:active {
    transform: none;
}

.game-icon {
    font-size: 2rem;
}

.tank-icon {
    position: relative;
    width: 62px;
    height: 62px;
    font-size: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.game-card[data-game="tankduel"] .tank-icon {
    margin-bottom: -12px;
}

.tank-icon-canvas {
    width: 100%;
    height: 100%;
    display: block;
    filter: none;
}

.game-title {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.game-desc {
    font-family: 'Jua', sans-serif;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ============================================
   설정 모달
   ============================================ */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.settings-modal.show {
    display: flex;
}

.settings-content {
    background: var(--bg-medium);
    border: 2px solid var(--neon-cyan);
    border-radius: 15px;
    padding: 20px 18px;
    text-align: center;
    width: 90%;
    max-width: 304px;
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.3);
}

.settings-content h3 {
    font-family: 'Jua', sans-serif;
    color: var(--neon-cyan);
    margin-bottom: 14px;
    font-size: 1.3rem;
}

.settings-content label {
    display: block;
    font-family: 'Jua', sans-serif;
    font-size: 0.95rem;
    margin-top: 12px;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.settings-content input[type="text"],
.settings-content select {
    width: 100%;
    padding: 10px;
    font-size: 1rem;
    font-family: 'Jua', sans-serif;
    background: var(--bg-dark);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--text-primary);
    text-align: center;
}

.settings-content input[type="text"]:focus,
.settings-content select:focus {
    outline: none;
    border-color: var(--neon-cyan);
}

.settings-content input[type="text"]:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    filter: grayscale(0.5);
}

.settings-content.p2-ai-locked .emoji-picker {
    opacity: 0.5;
    filter: grayscale(1);
    pointer-events: none;
}

.settings-content.p2-ai-locked .emoji-picker .emoji-option {
    cursor: not-allowed;
}

.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.emoji-option {
    font-size: 1.6rem;
    padding: 5px;
    cursor: pointer;
    border-radius: 7px;
    transition: all 0.2s;
}

.emoji-option:hover,
.emoji-option.selected {
    background: rgba(0, 255, 255, 0.2);
}

.settings-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 14px;
}

.settings-buttons button {
    padding: 10px 16px;
    font-size: 0.95rem;
    font-family: 'Jua', sans-serif;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-buttons .ai-toggle {
    display: none;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0 12px;
    height: 40px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    cursor: pointer;
}

.settings-buttons .ai-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--neon-cyan);
}

.settings-buttons .ai-toggle span {
    color: var(--text-primary);
}

#settings-save {
    background: var(--neon-cyan);
    color: var(--bg-dark);
}

#settings-cancel {
    background: #555;
    color: #fff;
}

#stats-reset {
    background: transparent;
    color: #ff6b6b;
    border: 1px solid #ff6b6b;
    font-size: 0.8rem;
    padding: 8px 14px;
    width: 100%;
    margin-top: 3px;
}

.settings-buttons button:active {
    transform: scale(0.95);
}

@media (max-height: 760px) {
    .player-section {
        padding: 12px;
    }

    .player-card {
        padding: 8px 12px;
    }

    .player-emoji {
        font-size: 2.2rem;
    }
}

@media (max-height: 700px) {
    .player-section {
        padding: 9px 10px;
    }

    .player-card {
        padding: 7px 10px;
    }

    .player-emoji {
        font-size: 2rem;
    }

    .settings-btn {
        width: 36px;
        height: 36px;
        font-size: 1.05rem;
    }
}

/* ============================================
   터치 제스처 차단
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    .game-card:hover {
        transform: none;
        box-shadow: 0 0 15px rgba(255, 107, 53, 0.3);
    }
}
