/* ============================================
   10.000 (Diez Mil) Online - Styles
   Mobile-first design (320px base)
   ============================================ */

/* CSS Variables */
:root {
    --color-bg: #1a1a2e;
    --color-surface: #16213e;
    --color-surface-light: #1f3251;
    --color-primary: #e94560;
    --color-secondary: #0f3460;
    --color-accent: #ffc107;
    --color-success: #4caf50;
    --color-danger: #e74c3c;
    --color-text: #ffffff;
    --color-text-muted: #a0a0a0;
    --color-dice: #fffef0;
    --color-dice-dots: #1a1a1a;
    --color-kept: #4caf50;
    --color-scoring: #ffc107;

    --transition-speed: 0.3s;
    --border-radius: 12px;
    --border-radius-sm: 8px;
}

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

/* Base */
html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    overflow: hidden;
}

.app {
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

.screen.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}

.screen.overlay.active {
    display: flex;
}

.screen-content {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.screen-content.center {
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 100%;
}

/* Typography */
.title {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 32px;
}

h2 {
    font-size: 1.5rem;
    margin-bottom: 16px;
}

h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--color-text-muted);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid var(--color-secondary);
    border-radius: var(--border-radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    outline: none;
    transition: border-color var(--transition-speed);
}

input[type="text"]:focus {
    border-color: var(--color-primary);
}

input[type="text"]::placeholder {
    color: var(--color-text-muted);
}

/* Buttons */
.btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 56px;
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-hint {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.8;
    margin-top: 2px;
}

.btn-points {
    font-size: 0.85rem;
    font-weight: 400;
    margin-top: 2px;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-text);
}

.btn-primary:hover:not(:disabled) {
    background: #d63c55;
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--color-secondary);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: #0d2a4d;
}

.btn-success {
    background: var(--color-success);
    color: var(--color-text);
}

.btn-success:hover:not(:disabled) {
    background: #3d9140;
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 12px;
    transition: color var(--transition-speed);
}

.btn-link:hover {
    color: var(--color-text);
}

.btn-link.danger {
    color: var(--color-danger);
}

/* Divider */
.divider {
    display: flex;
    align-items: center;
    margin: 24px 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-secondary);
}

.divider span {
    padding: 0 16px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Join Section */
.join-section {
    display: flex;
    gap: 12px;
}

.join-section input {
    flex: 1;
    text-align: center;
    text-transform: uppercase;
    font-size: 1.2rem;
    letter-spacing: 4px;
}

.join-section .btn {
    width: auto;
    padding: 12px 24px;
}

/* Room Code Display */
.room-code-display {
    background: var(--color-surface);
    border: 2px solid var(--color-accent);
    border-radius: var(--border-radius);
    padding: 20px;
    text-align: center;
    margin-bottom: 20px;
}

.room-code-display span {
    font-size: 2.5rem;
    font-weight: bold;
    letter-spacing: 8px;
    color: var(--color-accent);
}

/* Players List */
.players-section {
    margin: 24px 0;
}

.players-section h3 {
    display: flex;
    justify-content: space-between;
}

.players-list {
    list-style: none;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.players-list li {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--color-secondary);
}

.players-list li:last-child {
    border-bottom: none;
}

.players-list li.waiting {
    color: var(--color-text-muted);
    font-style: italic;
}

.players-list li.host::after {
    content: 'HOST';
    font-size: 0.7rem;
    background: var(--color-accent);
    color: var(--color-bg);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
}

.players-list li.current-turn {
    background: var(--color-surface-light);
}

.players-list li.current-turn::before {
    content: '▶';
    color: var(--color-accent);
}

.player-score {
    margin-left: auto;
    font-weight: bold;
    color: var(--color-accent);
}

/* Loading Spinner */
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-secondary);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

/* Playing Screen Layout */
.playing-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 12px;
}

/* Scoreboard */
.scoreboard {
    background: var(--color-surface);
    border-radius: var(--border-radius);
    padding: 12px;
    margin-bottom: 12px;
}

.scoreboard-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-secondary);
}

.scores-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.score-item {
    flex: 1 1 calc(50% - 4px);
    min-width: 120px;
    padding: 8px 12px;
    background: var(--color-secondary);
    border-radius: var(--border-radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.score-item.current {
    border: 2px solid var(--color-accent);
    background: var(--color-surface-light);
}

.score-item .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70px;
}

.score-item .score {
    font-weight: bold;
    color: var(--color-accent);
}

/* Game Area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
}

.turn-info {
    text-align: center;
    margin-bottom: 16px;
}

#turn-status {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 4px;
}

#turn-status.my-turn {
    color: var(--color-success);
}

#turn-status.waiting {
    color: var(--color-text-muted);
}

.turn-points {
    font-size: 1rem;
    color: var(--color-accent);
}

/* Dice Container */
.dice-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
    padding: 16px;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    max-width: 280px;
}

.die {
    width: 70px;
    height: 70px;
    background: var(--color-dice);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.die-face {
    font-size: 3rem;
    color: var(--color-dice-dots);
    line-height: 1;
}

.die.kept {
    background: var(--color-kept);
    transform: translateY(-8px);
    box-shadow: 0 8px 16px rgba(76, 175, 80, 0.4);
}

.die.kept .die-face {
    color: var(--color-text);
}

.die.selected {
    background: var(--color-scoring);
    transform: translateY(-8px);
    box-shadow: 0 8px 16px rgba(255, 193, 7, 0.4);
    border: 3px solid #ff9800;
}

.die.selected .die-face {
    color: var(--color-dice-dots);
}

.die.scoring {
    animation: pulse 0.5s ease-in-out;
    border: 3px solid var(--color-scoring);
}

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

.die.rolling {
    animation: roll 0.5s ease-out;
}

@keyframes roll {
    0% { transform: rotateX(0) rotateY(0); }
    25% { transform: rotateX(90deg) rotateY(45deg) scale(0.9); }
    50% { transform: rotateX(180deg) rotateY(90deg) scale(0.85); }
    75% { transform: rotateX(270deg) rotateY(135deg) scale(0.9); }
    100% { transform: rotateX(360deg) rotateY(180deg) scale(1); }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}

.dice-hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    text-align: center;
    margin-bottom: 16px;
    min-height: 20px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

.action-buttons .btn {
    flex: 1;
}

/* Farkle Animation */
.farkle-animation {
    font-size: 5rem;
    animation: farkleShake 0.5s ease-in-out;
    margin-bottom: 16px;
}

@keyframes farkleShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-20px) rotate(-5deg); }
    40% { transform: translateX(20px) rotate(5deg); }
    60% { transform: translateX(-15px) rotate(-3deg); }
    80% { transform: translateX(15px) rotate(3deg); }
}

.farkle-title {
    font-size: 2.5rem;
    color: var(--color-danger);
    margin-bottom: 8px;
}

.farkle-lost {
    font-size: 1.2rem;
    color: var(--color-danger);
    margin-top: 8px;
}

/* Winner */
.winner-emoji {
    font-size: 5rem;
    animation: winner 1s ease-in-out infinite;
    margin-bottom: 16px;
}

@keyframes winner {
    0%, 100% { transform: scale(1) rotate(0); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

.winner-name {
    font-size: 1.5rem;
    color: var(--color-accent);
    margin-bottom: 8px;
}

.winner-score {
    font-size: 1.1rem;
    color: var(--color-text-muted);
}

.final-scores {
    width: 100%;
    max-width: 320px;
    margin: 24px 0;
}

.finished-buttons {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Error */
.error-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--border-radius);
    padding: 24px;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
}

.modal-content h2 {
    margin-bottom: 20px;
    padding-right: 40px;
}

.rules-section {
    margin-bottom: 20px;
}

.rules-section h3 {
    color: var(--color-accent);
    font-size: 1rem;
    margin-bottom: 8px;
}

.rules-section p,
.rules-section li {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--color-text-muted);
}

.rules-section ol {
    padding-left: 20px;
}

.rules-section li {
    margin-bottom: 4px;
}

.scoring-table {
    width: 100%;
    font-size: 0.85rem;
}

.scoring-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-secondary);
}

.scoring-table td:first-child {
    color: var(--color-text-muted);
}

.scoring-table td:last-child {
    text-align: right;
    color: var(--color-accent);
    font-weight: bold;
}

/* Responsive */
@media (min-width: 480px) {
    .dice-container {
        gap: 16px;
        padding: 24px;
        max-width: 320px;
    }

    .die {
        width: 80px;
        height: 80px;
    }

    .die-face {
        font-size: 3.5rem;
    }
}

@media (min-width: 768px) {
    .playing-layout {
        max-width: 600px;
        margin: 0 auto;
    }

    .scores-list {
        flex-wrap: nowrap;
    }

    .score-item {
        flex: 1;
        min-width: auto;
    }
}
