/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors */
    --color-primary: #8B4513;
    --color-primary-dark: #654321;
    --color-secondary: #D2691E;
    --color-accent: #FFD700;
    --color-success: #28a745;
    --color-error: #dc3545;
    --color-warning: #ffc107;

    /* Board colors */
    --board-dark: #5D4037;
    --board-light: #D7CCC8;
    --board-border: #3E2723;
    --checker-white: #FAFAFA;
    --checker-black: #212121;

    /* UI colors */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1f2940;
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --border-color: #2d3748;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

/* === Header === */
.header {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-md) 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    text-decoration: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
}

.logo-icon {
    font-size: 2rem;
}

.nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.nav-link--primary {
    background: var(--color-primary);
    color: white;
}

.nav-link--primary:hover {
    background: var(--color-primary-dark);
}

.rating {
    background: var(--color-accent);
    color: #000;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
}

/* === Main === */
.main {
    flex: 1;
    padding: var(--spacing-xl) 0;
}

/* === Footer === */
.footer {
    background: rgba(0, 0, 0, 0.3);
    padding: var(--spacing-lg) 0;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* === Messages === */
.messages {
    position: fixed;
    top: 80px;
    right: var(--spacing-md);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.message {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
    animation: slideIn 0.3s ease;
    min-width: 300px;
}

.message--success { background: var(--color-success); }
.message--error { background: var(--color-error); }
.message--warning { background: var(--color-warning); color: #000; }
.message--info { background: var(--color-primary); }

.message-close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
}

.message-close:hover { opacity: 1; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* === Cards === */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
}

.card-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--spacing-lg);
    text-align: center;
}

/* === Forms === */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-input {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-input::placeholder {
    color: var(--text-secondary);
}

.form-error {
    color: var(--color-error);
    font-size: 0.875rem;
    margin-top: var(--spacing-xs);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn--primary {
    background: var(--color-primary);
    color: white;
}

.btn--primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn--secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn--secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn--success {
    background: var(--color-success);
    color: white;
}

.btn--danger {
    background: var(--color-error);
    color: white;
}

.btn--block {
    width: 100%;
}

.btn--lg {
    padding: var(--spacing-lg) var(--spacing-xl);
    font-size: 1.125rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* === Game Board === */
.game-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--spacing-xl);
    max-width: 1200px;
    margin: 0 auto;
}

.board-wrapper {
    background: var(--board-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-lg);
}

#game-board {
    display: block;
    width: 100%;
    border-radius: var(--radius-md);
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.player-info {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-color);
}

.player-info--active {
    border-color: var(--color-accent);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

.player-name {
    font-weight: 700;
    font-size: 1.125rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.player-rating {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dice {
    width: 80px;
    height: 80px;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    border-radius: var(--radius-lg);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    padding: 6px;
    box-shadow: var(--shadow-lg), inset 0 2px 4px rgba(255,255,255,0.5);
    transition: transform 0.3s ease;
    border: 3px solid #ccc;
}

.dice-dot {
    border-radius: 50%;
    background: #333;
}

/* Dice value 1 - center dot */
.dice[data-value="1"] .dice-dot:nth-child(1) { grid-area: 2 / 2; }

/* Dice value 2 - diagonal */
.dice[data-value="2"] .dice-dot:nth-child(1) { grid-area: 1 / 3; }
.dice[data-value="2"] .dice-dot:nth-child(2) { grid-area: 3 / 1; }

/* Dice value 3 - diagonal with center */
.dice[data-value="3"] .dice-dot:nth-child(1) { grid-area: 1 / 3; }
.dice[data-value="3"] .dice-dot:nth-child(2) { grid-area: 2 / 2; }
.dice[data-value="3"] .dice-dot:nth-child(3) { grid-area: 3 / 1; }

/* Dice value 4 - corners */
.dice[data-value="4"] .dice-dot:nth-child(1) { grid-area: 1 / 1; }
.dice[data-value="4"] .dice-dot:nth-child(2) { grid-area: 1 / 3; }
.dice[data-value="4"] .dice-dot:nth-child(3) { grid-area: 3 / 1; }
.dice[data-value="4"] .dice-dot:nth-child(4) { grid-area: 3 / 3; }

/* Dice value 5 - corners + center */
.dice[data-value="5"] .dice-dot:nth-child(1) { grid-area: 1 / 1; }
.dice[data-value="5"] .dice-dot:nth-child(2) { grid-area: 1 / 3; }
.dice[data-value="5"] .dice-dot:nth-child(3) { grid-area: 2 / 2; }
.dice[data-value="5"] .dice-dot:nth-child(4) { grid-area: 3 / 1; }
.dice[data-value="5"] .dice-dot:nth-child(5) { grid-area: 3 / 3; }

/* Dice value 6 - two columns */
.dice[data-value="6"] .dice-dot:nth-child(1) { grid-area: 1 / 1; }
.dice[data-value="6"] .dice-dot:nth-child(2) { grid-area: 1 / 3; }
.dice[data-value="6"] .dice-dot:nth-child(3) { grid-area: 2 / 1; }
.dice[data-value="6"] .dice-dot:nth-child(4) { grid-area: 2 / 3; }
.dice[data-value="6"] .dice-dot:nth-child(5) { grid-area: 3 / 1; }
.dice[data-value="6"] .dice-dot:nth-child(6) { grid-area: 3 / 3; }

/* Unknown/waiting state */
.dice[data-value="0"] {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #999;
}

.dice--rolling {
    animation: rollDice 0.5s ease-in-out;
}

.dice--used {
    opacity: 0.4;
    transform: scale(0.9);
}

.dice--active {
    border-color: var(--color-success);
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.5);
}

@keyframes rollDice {
    0%, 100% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(90deg) scale(1.1); }
    50% { transform: rotate(180deg) scale(1); }
    75% { transform: rotate(270deg) scale(1.1); }
}

.dice-container {
    display: flex;
    gap: var(--spacing-lg);
    justify-content: center;
    padding: var(--spacing-xl);
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.game-actions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.game-chat {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 180px;
    max-height: 180px;
}

.chat-messages {
    flex: 1;
    padding: var(--spacing-sm);
    overflow-y: auto;
    height: 140px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.chat-message {
    margin-bottom: var(--spacing-sm);
    font-size: 0.875rem;
}

.chat-message strong {
    color: var(--color-secondary);
}

.chat-input-wrapper {
    display: flex;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    padding: var(--spacing-md);
    background: transparent;
    border: none;
    color: var(--text-primary);
}

.chat-input:focus { outline: none; }

.chat-send {
    padding: var(--spacing-md);
    background: var(--color-primary);
    border: none;
    color: white;
    cursor: pointer;
}

/* === Lobby === */
.lobby-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-lg);
}

.game-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.game-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.game-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.game-type {
    background: var(--color-secondary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.game-card-body {
    margin-bottom: var(--spacing-md);
}

.game-creator {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* === Profile === */
.profile-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-xl);
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-full);
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-lg);
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-accent);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: var(--spacing-xs);
}

.stat-sublabel {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 2px;
}

/* === Home Page === */
.hero {
    text-align: center;
    padding: var(--spacing-xl) 0;
}

.hero-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: var(--spacing-md);
    background: linear-gradient(135deg, var(--color-accent), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.hero-actions {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
}

.features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-xl);
    margin-top: var(--spacing-xl);
}

.feature-card {
    text-align: center;
    padding: var(--spacing-xl);
}

.feature-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
}

.feature-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
}

.feature-desc {
    color: var(--text-secondary);
}

/* === Responsive === */
@media (max-width: 768px) {
    .game-container {
        grid-template-columns: 1fr;
    }

    .profile-header {
        flex-direction: column;
        text-align: center;
    }

    .profile-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .features {
        grid-template-columns: 1fr;
    }

    .hero-title {
        font-size: 2rem;
    }

    .nav {
        gap: var(--spacing-sm);
    }

    .hero-actions {
        flex-direction: column;
    }
}

/* === Utilities === */
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mt-1 { margin-top: var(--spacing-md); }
.mt-2 { margin-top: var(--spacing-lg); }
.mb-1 { margin-bottom: var(--spacing-md); }
.mb-2 { margin-bottom: var(--spacing-lg); }

/* === Loading === */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Turn Timer === */
.turn-timer {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
}

.timer-bar {
    height: 8px;
    background: var(--border-color);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin-bottom: var(--spacing-xs);
}

.timer-fill {
    height: 100%;
    background: var(--color-success);
    border-radius: var(--radius-full);
    transition: width 1s linear, background-color 0.3s;
    width: 100%;
}

.timer-fill.warning {
    background: var(--color-warning);
}

.timer-fill.danger {
    background: var(--color-error);
}

.timer-text {
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#timer-value {
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--text-primary);
}

/* === Missed Turns Warning === */
.missed-turns {
    background: rgba(220, 53, 69, 0.2);
    border: 1px solid var(--color-error);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.missed-warning {
    color: var(--color-error);
    font-weight: bold;
    font-size: 0.875rem;
}

/* === Surrender Button (small) === */
.btn-surrender {
    display: block;
    width: 100%;
    padding: 0.4rem 0.75rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    opacity: 0.7;
}

.btn-surrender:hover:not(:disabled) {
    opacity: 1;
    color: var(--color-error);
    border-color: var(--color-error);
    background: rgba(220, 53, 69, 0.1);
}

.btn-surrender:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
