/* ============================================
   CULO SUCIO ONLINE - STYLES
   Mobile-first design (320px base)
   ============================================ */

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

:root {
    /* Colors */
    --color-primary: #2D5A3D;
    --color-primary-dark: #1A3D2B;
    --color-secondary: #8B4513;
    --color-accent: #E74C3C;

    /* Card colors */
    --color-card-bg: #FFFEF0;
    --color-card-red: #C41E3A;
    --color-card-black: #1A1A1A;

    /* State colors */
    --color-my-turn: #27AE60;
    --color-opponent-turn: #7F8C8D;
    --color-selected: #F1C40F;
    --color-quema: #E74C3C;
    --color-out: #9B59B6;

    /* UI colors */
    --color-bg: #1A3D2B;
    --color-text: #FFFFFF;
    --color-text-secondary: #B8D4C0;
    --color-text-muted: #6B9080;

    /* Sizes */
    --card-width: 55px;
    --card-height: 80px;
    --card-width-sm: 45px;
    --card-height-sm: 65px;
    --transition-speed: 0.2s;
}

html, body {
    height: 100%;
    height: 100dvh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ============================================
   SCREENS
   ============================================ */

.screen {
    display: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

.title {
    font-size: 2rem;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--color-text-secondary);
    margin-bottom: 32px;
}

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

/* ============================================
   FORMS
   ============================================ */

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

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

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

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

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

.code-input {
    text-align: center;
    font-size: 1.5rem;
    font-family: monospace;
    letter-spacing: 8px;
    text-transform: uppercase;
}

/* Player count selector */
.player-count-selector {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.player-count-btn {
    width: 48px;
    height: 48px;
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.player-count-btn.selected {
    background: var(--color-my-turn);
    border-color: var(--color-my-turn);
}

.player-count-btn:active {
    transform: scale(0.95);
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    display: block;
    width: 100%;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 12px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all var(--transition-speed);
}

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

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

.btn-primary {
    background: var(--color-my-turn);
    color: white;
}

.btn-secondary {
    background: transparent;
    border: 2px solid var(--color-text-secondary);
    color: var(--color-text);
}

.btn-link {
    background: transparent;
    color: var(--color-text-muted);
    text-decoration: underline;
}

.btn-help {
    background: transparent;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 16px;
    text-decoration: underline;
}

/* ============================================
   WAITING ROOM
   ============================================ */

.room-code-display {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px 40px;
    margin-bottom: 20px;
}

.room-code-display span {
    font-size: 2.5rem;
    font-family: monospace;
    font-weight: bold;
    letter-spacing: 8px;
}

.waiting-text {
    color: var(--color-text-secondary);
    margin-bottom: 16px;
}

.players-list {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    text-align: left;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.player-item:last-child {
    border-bottom: none;
}

.player-item.waiting {
    color: var(--color-text-muted);
}

.player-item .player-icon {
    width: 24px;
    text-align: center;
}

.players-count {
    color: var(--color-text-secondary);
    margin-bottom: 20px;
}

/* ============================================
   GAME SCREEN
   ============================================ */

#screen-playing.active {
    padding: 8px;
    justify-content: flex-start;
}

.game-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 8px;
    margin: 0 auto;
}

/* Players Bar */
.players-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
}

.player-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    font-size: 0.75rem;
}

.player-chip.current-turn {
    background: var(--color-my-turn);
}

.player-chip.is-out {
    opacity: 0.5;
    text-decoration: line-through;
}

.player-chip.is-me {
    border: 2px solid var(--color-selected);
}

.player-chip .card-count {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
}

/* Pile Area */
.pile-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.pile-label {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    margin-bottom: 8px;
}

.pile {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: -20px;
    min-height: 70px;
}

.pile .card {
    margin-left: -25px;
}

.pile .card:first-child {
    margin-left: 0;
}

.pile-empty {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Turn Indicator */
.turn-indicator {
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.2);
}

.turn-indicator.my-turn {
    background: var(--color-my-turn);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

/* My Hand Section */
.my-hand-section {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 8px;
}

.my-hand-label {
    display: flex;
    justify-content: space-between;
    color: var(--color-text-secondary);
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.my-hand {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    max-height: 220px;
    overflow-y: auto;
    padding: 8px;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 12px;
    padding: 8px 0;
}

.action-buttons .btn {
    flex: 1;
    margin-bottom: 0;
    min-height: 48px;
}

/* Game Menu */
.game-menu {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 8px 0;
}

.btn-icon {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background var(--transition-speed);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* ============================================
   CARDS
   ============================================ */

.card {
    width: var(--card-width);
    height: var(--card-height);
    background: var(--color-card-bg);
    border-radius: 8px;
    box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.card .card-number {
    font-size: 20px;
    line-height: 1;
}

.card .card-suit {
    font-size: 18px;
    line-height: 1;
    margin-top: 4px;
}

/* Suit colors */
.card.espada, .card.basto {
    color: var(--color-card-black);
}

.card.oro, .card.copa {
    color: var(--color-card-red);
}

/* Card states */
.card.selectable {
    cursor: pointer;
}

.card.selectable:not(.selected) {
    box-shadow: 0 0 0 2px rgba(39, 174, 96, 0.5);
}

.card.selected {
    transform: translateY(-8px);
    box-shadow: 0 0 0 3px var(--color-selected), 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.card:active:not(.disabled) {
    transform: scale(0.95);
}

/* Small cards for crowded hands */
.my-hand.crowded .card {
    width: var(--card-width-sm);
    height: var(--card-height-sm);
    font-size: 14px;
}

.my-hand.crowded .card .card-number {
    font-size: 16px;
}

.my-hand.crowded .card .card-suit {
    font-size: 14px;
}

/* ============================================
   FINISHED SCREEN
   ============================================ */

.result-display {
    margin-bottom: 24px;
}

.result-emoji {
    font-size: 4rem;
    margin-bottom: 16px;
}

.result-detail {
    color: var(--color-text-secondary);
    margin-top: 8px;
}

.ranking {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
    text-align: left;
}

.ranking-title {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    text-align: center;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ranking-item:last-child {
    border-bottom: none;
}

.ranking-item .position {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    font-size: 0.8rem;
}

.ranking-item.winner .position {
    background: var(--color-my-turn);
}

.ranking-item.loser .position {
    background: var(--color-accent);
}

.ranking-item .name {
    flex: 1;
}

.ranking-item.is-me .name {
    font-weight: bold;
}

/* ============================================
   ERROR SCREEN
   ============================================ */

.error-display {
    margin-bottom: 32px;
}

.error-emoji {
    font-size: 4rem;
    margin-bottom: 16px;
}

/* ============================================
   MODAL
   ============================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-primary-dark);
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

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

.modal-content h2 {
    margin-bottom: 16px;
}

.help-section {
    margin-bottom: 20px;
    text-align: left;
}

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

.help-section p, .help-section ul {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

.help-section ul {
    padding-left: 20px;
}

.help-section li {
    margin-bottom: 6px;
}

.card-order {
    font-family: monospace;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 12px;
    border-radius: 4px;
    text-align: center;
}

.small {
    font-size: 0.8rem;
    margin-top: 4px;
}

/* ============================================
   TOAST
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.5s;
    white-space: nowrap;
}

.toast.toast-error {
    background: var(--color-accent);
}

.toast.toast-success {
    background: var(--color-my-turn);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

/* ============================================
   QUEMA OVERLAY
   ============================================ */

.quema-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(231, 76, 60, 0.9);
    z-index: 1002;
    align-items: center;
    justify-content: center;
}

.quema-overlay.active {
    display: flex;
    animation: quemaFlash 0.5s ease;
}

.quema-text {
    font-size: 2.5rem;
    font-weight: bold;
    animation: quemaScale 0.5s ease;
}

@keyframes quemaFlash {
    0%, 100% { background: rgba(231, 76, 60, 0.9); }
    50% { background: rgba(241, 196, 15, 0.9); }
}

@keyframes quemaScale {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (min-width: 375px) {
    :root {
        --card-width: 65px;
        --card-height: 95px;
    }
}

@media (min-width: 768px) {
    :root {
        --card-width: 85px;
        --card-height: 125px;
    }

    .card .card-number {
        font-size: 28px;
    }

    .card .card-suit {
        font-size: 24px;
    }
}

@media (min-width: 768px) {
    .my-hand {
        max-height: 300px;
        gap: 12px;
    }

    .pile-area {
        min-height: 180px;
    }
}

@media (min-width: 1024px) {
    :root {
        --card-width: 100px;
        --card-height: 145px;
    }

    .card .card-number {
        font-size: 34px;
    }

    .card .card-suit {
        font-size: 28px;
    }

    .title {
        font-size: 2.5rem;
    }

    .players-bar {
        gap: 10px;
    }

    .player-chip {
        font-size: 0.85rem;
        padding: 8px 14px;
    }

    .my-hand {
        max-height: 350px;
        gap: 16px;
    }

    .pile-area {
        min-height: 220px;
    }

    .pile .card {
        margin-left: -40px;
    }
}
