:root {
    --bg-dark: #0a0a0f;
    --bg-panel: #12121a;
    --border-glow: #1a1a2e;
    --player-color: #00d4ff;
    --player-glow: rgba(0, 212, 255, 0.3);
    --player-fill: rgba(0, 212, 255, 0.15);
    --ai-color: #ff3366;
    --ai-glow: rgba(255, 51, 102, 0.3);
    --ai-fill: rgba(255, 51, 102, 0.15);
    --text-primary: #ffffff;
    --text-secondary: #8888aa;
    --accent-gold: #ffd700;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Rajdhani', sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(0, 212, 255, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(255, 51, 102, 0.08) 0%, transparent 50%),
        repeating-linear-gradient(0deg,
            transparent,
            transparent 50px,
            rgba(255, 255, 255, 0.01) 50px,
            rgba(255, 255, 255, 0.01) 51px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 50px,
            rgba(255, 255, 255, 0.01) 50px,
            rgba(255, 255, 255, 0.01) 51px);
    pointer-events: none;
    z-index: -1;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    width: 100%;
}

.header-title {
    text-align: center;
    flex: 1;
}

.header-link {
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border: 1px solid var(--border-glow);
    border-radius: 6px;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.header-link:hover {
    color: var(--player-color);
    border-color: var(--player-color);
    box-shadow: 0 0 10px var(--player-glow);
}

.header-spacer {
    width: 80px;
}

.title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--player-color), var(--ai-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px var(--player-glow);
    animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.2);
    }
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    letter-spacing: 0.5em;
    margin-top: 5px;
}

/* Main content */
.main-content {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: center;
}

/* Game area (canvas + message) */
.game-area {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 600px;
    max-width: 100%;
}

/* Message area */
.message-area {
    width: 100%;
}

.message-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    padding: 15px 25px;
    text-align: center;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message {
    font-size: 1.4rem;
    color: var(--text-primary);
    animation: messageFade 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@keyframes messageFade {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.highlight {
    color: var(--accent-gold);
    font-weight: 600;
}

.message.player-win {
    color: var(--player-color);
    font-weight: 700;
    font-size: 1.3rem;
}

.message.ai-win {
    color: var(--ai-color);
    font-weight: 700;
    font-size: 1.3rem;
}

/* Canvas container */
.canvas-container {
    position: relative;
    background: var(--bg-panel);
    border: 2px solid var(--border-glow);
    border-radius: 8px;
    box-shadow:
        0 0 30px rgba(0, 0, 0, 0.5),
        inset 0 0 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.canvas-container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, var(--player-color), transparent, var(--ai-color));
    border-radius: 10px;
    z-index: -1;
    opacity: 0.3;
}

#gameCanvas {
    display: block;
}

/* Side panel */
.side-panel {
    width: 280px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.panel-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-glow);
    border-radius: 8px;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.panel-box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--player-color), transparent);
}

.panel-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    letter-spacing: 0.3em;
    color: var(--text-secondary);
    margin-bottom: 15px;
    text-transform: uppercase;
}

/* Turn indicator */
.turn-indicator {
    text-align: center;
}

.current-turn {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    transition: all 0.3s ease;
}

.current-turn.player {
    color: var(--player-color);
    text-shadow: 0 0 20px var(--player-glow);
}

.current-turn.ai {
    color: var(--ai-color);
    text-shadow: 0 0 20px var(--ai-glow);
}

/* Dice section */
.dice-section {
    text-align: center;
}

.dice-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 15px;
}

.dice {
    width: 180px;
    height: 180px;
    background: linear-gradient(145deg, #1a1a2e, #0f0f1a);
    border: 4px solid var(--border-glow);
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: sans-serif;
    font-size: 9rem;
    font-weight: 900;
    color: var(--accent-gold);
    text-shadow: 0 0 25px rgba(255, 215, 0, 0.7);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.dice:hover:not(.disabled) {
    transform: scale(1.05);
    border-color: var(--accent-gold);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

.dice.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dice.rolling {
    animation: diceRoll 0.1s linear infinite;
}

@keyframes diceRoll {
    0% {
        transform: rotate(0deg) scale(1.1);
    }

    25% {
        transform: rotate(5deg) scale(1.05);
    }

    50% {
        transform: rotate(0deg) scale(1.1);
    }

    75% {
        transform: rotate(-5deg) scale(1.05);
    }

    100% {
        transform: rotate(0deg) scale(1.1);
    }
}

.remaining-moves {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.remaining-moves span {
    color: var(--accent-gold);
    font-weight: 700;
    font-size: 1.3rem;
}

.roll-btn {
    background: linear-gradient(135deg, var(--player-color), #0099cc);
    border: none;
    border-radius: 6px;
    padding: 12px 30px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.roll-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px var(--player-glow);
}

.roll-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* Score section */
.score-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.score-row.player {
    background: var(--player-fill);
    border-left: 3px solid var(--player-color);
}

.score-row.ai {
    background: var(--ai-fill);
    border-left: 3px solid var(--ai-color);
}

.score-label {
    font-size: 1rem;
    font-weight: 500;
}

.score-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    font-weight: 900;
}

.score-row.player .score-value {
    color: var(--player-color);
}

.score-row.ai .score-value {
    color: var(--ai-color);
}

.triangle-icon {
    display: inline-block;
    margin-left: 5px;
    opacity: 0.7;
}

/* Reset button */
.reset-btn {
    background: transparent;
    border: 1px solid var(--text-secondary);
    border-radius: 6px;
    padding: 12px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

.reset-btn:hover {
    border-color: var(--ai-color);
    color: var(--ai-color);
    box-shadow: 0 0 15px var(--ai-glow);
}

/* Modal overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-panel);
    border: 2px solid var(--border-glow);
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 400px;
    animation: modalSlide 0.4s ease;
}

@keyframes modalSlide {
    from {
        transform: scale(0.8) translateY(-20px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 20px;
}

.modal-title.player-win {
    color: var(--player-color);
    text-shadow: 0 0 30px var(--player-glow);
}

.modal-title.ai-win {
    color: var(--ai-color);
    text-shadow: 0 0 30px var(--ai-glow);
}

.modal-title.draw {
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

.modal-score {
    font-size: 2rem;
    color: #ffffff;
    margin-bottom: 30px;
    font-weight: 600;
}

.modal-btn {
    background: linear-gradient(135deg, var(--player-color), var(--ai-color));
    border: none;
    border-radius: 8px;
    padding: 15px 40px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px var(--player-glow);
}

/* Instructions */
.instructions {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.instructions p {
    margin-bottom: 8px;
}

.instructions strong {
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 900px) {
    .main-content {
        flex-direction: column;
        align-items: center;
    }

    .side-panel {
        width: 100%;
        max-width: 600px;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .panel-box {
        flex: 1;
        min-width: 200px;
    }

    .title {
        font-size: 1.8rem;
    }
}

/* Smartphone portrait */
@media (max-width: 640px) {
    .game-container {
        padding: 10px;
    }

    .header {
        margin-bottom: 10px;
    }

    .title {
        font-size: 1.4rem;
        letter-spacing: 0.15em;
    }

    .subtitle {
        font-size: 0.75rem;
        letter-spacing: 0.3em;
    }

    .header-spacer {
        display: none;
    }

    .header-link {
        font-size: 0.8rem;
        padding: 6px 12px;
    }

    .main-content {
        gap: 15px;
    }

    .game-area {
        width: 100%;
        gap: 10px;
    }

    .canvas-container {
        width: 100%;
        max-width: 100vw;
    }

    #gameCanvas {
        display: block;
        max-width: 100%;
        height: auto;
    }

    .message-box {
        padding: 12px 15px;
        min-height: 44px;
    }

    .message {
        font-size: 1.2rem;
    }

    .side-panel {
        width: 100%;
        flex-direction: column;
        gap: 10px;
    }

    .panel-box {
        padding: 15px;
        min-width: unset;
    }

    .panel-title {
        font-size: 0.7rem;
        margin-bottom: 10px;
    }

    /* Turn indicator compact */
    .turn-indicator .current-turn {
        font-size: 1.2rem;
    }

    /* Dice section compact */
    .dice-section {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
    }

    .dice-section .panel-title {
        width: 100%;
    }

    .dice-container {
        margin-bottom: 0;
    }

    .dice {
        width: 55px;
        height: 55px;
        font-size: 1.6rem;
    }

    .remaining-moves {
        font-size: 1rem;
    }

    .remaining-moves span {
        font-size: 1.1rem;
    }

    .roll-btn {
        padding: 10px 20px;
        font-size: 0.8rem;
    }

    /* Score section horizontal layout */
    .score-section {
        flex-direction: row;
        gap: 10px;
    }

    .score-section .panel-title {
        display: none;
    }

    .score-row {
        flex: 1;
        flex-direction: column;
        text-align: center;
        padding: 10px;
        gap: 5px;
    }

    .score-value {
        font-size: 1.5rem;
    }

    /* Instructions hidden on mobile */
    .instructions-panel {
        display: none;
    }

    .reset-btn {
        padding: 10px;
        font-size: 0.85rem;
    }

    /* Modal adjustments */
    .modal-content {
        margin: 20px;
        padding: 25px;
    }

    .modal-title {
        font-size: 1.5rem;
    }

    .modal-score {
        font-size: 1rem;
    }

    .modal-btn {
        padding: 12px 30px;
        font-size: 0.9rem;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .title {
        font-size: 1.2rem;
    }

    .dice {
        width: 50px;
        height: 50px;
        font-size: 1.4rem;
    }

    .score-value {
        font-size: 1.3rem;
    }
}

/* Mobile overlay UI inside game area */
.mobile-overlay {
    display: none;
}

@media (max-width: 640px) {
    .mobile-overlay {
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        pointer-events: none;
        z-index: 100;
    }

    .mobile-overlay>* {
        pointer-events: auto;
    }

    /* Score display - top left */
    .mobile-overlay .score-display {
        position: absolute;
        top: 10px;
        left: 10px;
        display: flex;
        gap: 8px;
    }

    .mobile-overlay .score-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 5px 10px;
        border-radius: 6px;
        min-width: 55px;
    }

    .mobile-overlay .score-item.player {
        background: var(--player-fill);
        border: 1px solid var(--player-color);
    }

    .mobile-overlay .score-item.ai {
        background: var(--ai-fill);
        border: 1px solid var(--ai-color);
    }

    .mobile-overlay .score-item .label {
        font-size: 0.8rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        font-weight: 600;
    }

    .mobile-overlay .score-item .value {
        font-family: 'Orbitron', sans-serif;
        font-size: 1.2rem;
        font-weight: 700;
    }

    .mobile-overlay .score-item.player .value {
        color: var(--player-color);
    }

    .mobile-overlay .score-item.ai .value {
        color: var(--ai-color);
    }

    /* Turn badge - bottom left */
    .mobile-overlay .turn-badge {
        position: absolute;
        bottom: 10px;
        left: 10px;
        font-family: 'Orbitron', sans-serif;
        font-size: 0.9rem;
        font-weight: 700;
        padding: 8px 14px;
        border-radius: 8px;
        white-space: nowrap;
    }

    .mobile-overlay .turn-badge.player {
        background: var(--player-fill);
        color: var(--player-color);
        border: 1px solid var(--player-color);
    }

    .mobile-overlay .turn-badge.ai {
        background: var(--ai-fill);
        color: var(--ai-color);
        border: 1px solid var(--ai-color);
    }

    /* Dice area - default corner position */
    .mobile-overlay .dice-area {
        position: absolute;
        bottom: 10px;
        right: 10px;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        background: rgba(10, 10, 15, 0.85);
        padding: 8px 12px;
        border-radius: 10px;
        border: 1px solid var(--border-glow);
        transition: all 0.4s ease;
    }

    /* Dice area - centered when rolling */
    .mobile-overlay .dice-area.rolling-mode {
        bottom: 50%;
        right: 50%;
        transform: translate(50%, 50%);
        flex-direction: column;
        gap: 12px;
        padding: 20px 30px;
        border-radius: 16px;
        border: 2px solid var(--border-glow);
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
    }

    .mobile-overlay .mini-dice {
        width: 70px;
        height: 70px;
        background: linear-gradient(145deg, #1a1a2e, #0f0f1a);
        border: 2px solid var(--border-glow);
        border-radius: 10px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-family: sans-serif;
        font-size: 4rem;
        font-weight: 900;
        color: var(--accent-gold);
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
        transition: all 0.4s ease;
    }

    /* Large dice when rolling */
    .mobile-overlay .dice-area.rolling-mode .mini-dice {
        width: 180px;
        height: 180px;
        border: 4px solid var(--border-glow);
        border-radius: 20px;
        font-size: 9rem;
        text-shadow: 0 0 25px rgba(255, 215, 0, 0.7);
    }

    .mobile-overlay .mini-dice.rolling {
        animation: diceRoll 0.1s linear infinite;
    }

    /* Remaining - hidden in corner mode, visible when rolling */
    .mobile-overlay .remaining {
        display: none;
        font-size: 0.75rem;
        color: var(--text-secondary);
        text-align: center;
        line-height: 1.2;
    }

    .mobile-overlay .dice-area.rolling-mode .remaining {
        display: block;
        font-size: 1rem;
        line-height: 1.4;
    }

    .mobile-overlay .remaining span {
        color: var(--accent-gold);
        font-weight: 700;
        font-size: 1.5rem;
    }

    /* Mobile roll button - compact in corner */
    .mobile-overlay .mobile-roll-btn {
        background: linear-gradient(135deg, var(--player-color), #0099cc);
        border: none;
        border-radius: 8px;
        padding: 10px 16px;
        font-family: 'Orbitron', sans-serif;
        font-size: 0.8rem;
        font-weight: 700;
        letter-spacing: 0.05em;
        color: white;
        cursor: pointer;
        white-space: nowrap;
        transition: all 0.3s ease;
    }

    /* Large button when rolling mode */
    .mobile-overlay .dice-area.rolling-mode .mobile-roll-btn {
        border-radius: 12px;
        padding: 16px 28px;
        font-size: 1rem;
        letter-spacing: 0.1em;
        box-shadow: 0 4px 15px rgba(0, 212, 255, 0.4);
    }

    .mobile-overlay .mobile-roll-btn:not(:disabled) {
        animation: rollBtnPulse 1s ease-in-out infinite;
    }

    @keyframes rollBtnPulse {

        0%,
        100% {
            transform: scale(1);
        }

        50% {
            transform: scale(1.1);
        }
    }

    .mobile-overlay .mobile-roll-btn:disabled {
        opacity: 0.4;
        cursor: not-allowed;
        animation: none;
    }

    /* Hide side panel on mobile */
    .side-panel {
        display: none;
    }
}