/* ============================================
   GENERALA - Styles
   Mobile-first, 320px base
   ============================================ */

/* Reset & Variables */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors - Green felt/casino theme */
    --color-bg: #0D2818;
    --color-surface: #1E3A2F;
    --color-surface-light: #2a4d3e;
    --color-primary: #D4AF37;
    --color-primary-dark: #b8941f;
    --color-secondary: #1B4D3E;
    --color-success: #4ADE80;
    --color-danger: #EF4444;
    --color-text: #FFFFFF;
    --color-text-muted: #A0AEC0;
    --color-text-dark: #1A1A1A;

    /* Dice */
    --color-dice: #FFFEF0;
    --color-dice-dots: #1A1A1A;
    --color-dice-kept: #FFD700;
    --color-dice-shadow: rgba(0, 0, 0, 0.3);

    /* Score table */
    --color-score-available: #4ADE80;
    --color-score-used: #6B7280;
    --color-score-highlight: rgba(212, 175, 55, 0.2);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.25rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;
    --font-size-3xl: 2.5rem;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 50%;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

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

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

.screen.active {
    display: flex;
    flex-direction: column;
}

.screen-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    gap: var(--spacing-md);
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-md);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    touch-action: manipulation;
    min-height: 48px;
    width: 100%;
}

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

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

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

.btn-primary:active:not(:disabled) {
    background: var(--color-primary-dark);
}

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

.btn-secondary:active:not(:disabled) {
    background: var(--color-secondary);
}

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

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

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

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

.btn-lg {
    padding: var(--spacing-lg);
    font-size: var(--font-size-lg);
    min-height: 56px;
}

.btn-icon {
    font-size: 1.2em;
}

.btn-icon-only {
    background: transparent;
    border: none;
    color: var(--color-text);
    font-size: var(--font-size-xl);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--radius-full);
}

.btn-icon-only:active {
    background: var(--color-surface-light);
}

/* ============================================
   SETUP SCREEN
   ============================================ */

.logo {
    text-align: center;
    margin-bottom: var(--spacing-xl);
}

.logo-dice {
    font-size: 4rem;
    display: block;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.logo h1 {
    font-size: var(--font-size-2xl);
    color: var(--color-primary);
    letter-spacing: 0.2em;
    margin: var(--spacing-sm) 0;
}

.logo-subtitle {
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    letter-spacing: 0.3em;
}

.form-group {
    width: 100%;
    margin-bottom: var(--spacing-md);
}

.form-group label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-xs);
}

.form-group input {
    width: 100%;
    padding: var(--spacing-md);
    border: 2px solid var(--color-surface-light);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-size-md);
    transition: border-color var(--transition-fast);
}

.form-group input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-group input::placeholder {
    color: var(--color-text-muted);
}

.player-count-selector {
    display: flex;
    gap: var(--spacing-sm);
}

.player-count-btn {
    flex: 1;
    padding: var(--spacing-md);
    border: 2px solid var(--color-surface-light);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: var(--font-size-lg);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.player-count-btn.active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-text-dark);
}

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

.player-inputs {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* ============================================
   PLAYING SCREEN
   ============================================ */

#screen-playing {
    padding: 0;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-surface-light);
}

.game-info {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.turn-indicator {
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
    background: var(--color-primary);
    color: var(--color-text-dark);
}

.turn-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
}

/* Dice Section */
.dice-section {
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-bg) 100%);
}

.dice-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
}

.die {
    width: 56px;
    height: 56px;
    background: var(--color-dice);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow:
        0 4px 8px var(--color-dice-shadow),
        inset 0 2px 4px rgba(255, 255, 255, 0.5);
    position: relative;
    border: 3px solid transparent;
}

.die:active {
    transform: scale(0.95);
}

.die.kept {
    border-color: var(--color-dice-kept);
    box-shadow:
        0 0 15px var(--color-dice-kept),
        0 4px 8px var(--color-dice-shadow);
}

.die.kept::after {
    content: '🔒';
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 14px;
}

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

.die-face {
    font-size: 0;
}

/* Dice faces with dots */
.die[data-value="1"] .die-face::before { content: '⚀'; font-size: 2.2rem; color: var(--color-dice-dots); }
.die[data-value="2"] .die-face::before { content: '⚁'; font-size: 2.2rem; color: var(--color-dice-dots); }
.die[data-value="3"] .die-face::before { content: '⚂'; font-size: 2.2rem; color: var(--color-dice-dots); }
.die[data-value="4"] .die-face::before { content: '⚃'; font-size: 2.2rem; color: var(--color-dice-dots); }
.die[data-value="5"] .die-face::before { content: '⚄'; font-size: 2.2rem; color: var(--color-dice-dots); }
.die[data-value="6"] .die-face::before { content: '⚅'; font-size: 2.2rem; color: var(--color-dice-dots); }

/* Rolling animation */
@keyframes roll {
    0% { transform: rotateX(0) rotateY(0) rotateZ(0) scale(1); }
    25% { transform: rotateX(180deg) rotateY(90deg) rotateZ(45deg) scale(1.1); }
    50% { transform: rotateX(360deg) rotateY(180deg) rotateZ(90deg) scale(1); }
    75% { transform: rotateX(540deg) rotateY(270deg) rotateZ(135deg) scale(1.1); }
    100% { transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg) scale(1); }
}

.die.rolling {
    animation: roll 0.6s ease-out;
    pointer-events: none;
}

.throws-display {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.throws-dots {
    display: flex;
    gap: var(--spacing-xs);
}

.throws-dots .dot {
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    background: var(--color-surface-light);
    transition: background var(--transition-fast);
}

.throws-dots .dot.used {
    background: var(--color-primary);
}

.btn-roll {
    width: auto;
    padding: var(--spacing-md) var(--spacing-xl);
}

.btn-roll:disabled {
    background: var(--color-surface-light);
    color: var(--color-text-muted);
}

/* Score Section */
.score-section {
    flex: 1;
    padding: var(--spacing-sm);
    overflow-x: auto;
}

.score-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    min-width: 280px;
}

.score-table th,
.score-table td {
    padding: var(--spacing-xs) var(--spacing-sm);
    text-align: center;
    border-bottom: 1px solid var(--color-surface-light);
    min-height: 40px;
    height: 40px;
}

.score-table th {
    background: var(--color-surface);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.score-table .cat-col {
    text-align: left;
    width: 50px;
}

.score-table .cat-name {
    text-align: left;
    font-weight: 500;
    color: var(--color-text-muted);
}

.score-table .combo-row .cat-name {
    color: var(--color-primary);
}

.score-table .generala-row .cat-name {
    color: var(--color-success);
}

.score-table .player-col {
    min-width: 55px;
}

.score-table .player-col.current {
    background: var(--color-score-highlight);
}

.score-cell {
    cursor: default;
    transition: all var(--transition-fast);
}

.score-cell.available {
    cursor: pointer;
    color: var(--color-score-available);
    font-weight: 600;
    background: rgba(74, 222, 128, 0.1);
}

.score-cell.available:active {
    background: rgba(74, 222, 128, 0.3);
}

.score-cell.used {
    color: var(--color-text);
}

.score-cell.crossed {
    color: var(--color-text-muted);
    text-decoration: line-through;
}

.score-table .total-row {
    background: var(--color-surface);
    font-weight: 700;
}

.score-table .total-row td {
    border-top: 2px solid var(--color-primary);
}

/* ============================================
   PASS SCREEN
   ============================================ */

.pass-content {
    text-align: center;
    justify-content: center;
}

.pass-icon {
    font-size: 5rem;
    animation: shake 0.5s ease-in-out infinite;
}

@keyframes shake {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}

.pass-label {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
    margin-top: var(--spacing-lg);
}

.pass-name {
    font-size: var(--font-size-3xl);
    color: var(--color-primary);
    margin: var(--spacing-md) 0 var(--spacing-xl);
}

/* ============================================
   RESULT SCREEN
   ============================================ */

.result-display {
    text-align: center;
    padding: var(--spacing-xl);
}

.result-emoji {
    font-size: 5rem;
    display: block;
    margin-bottom: var(--spacing-md);
}

.result-title {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
    margin-bottom: var(--spacing-xs);
}

.result-name {
    font-size: var(--font-size-2xl);
    color: var(--color-primary);
    font-weight: 700;
}

.result-score {
    font-size: var(--font-size-lg);
    color: var(--color-text);
    margin-top: var(--spacing-sm);
}

.final-scores {
    width: 100%;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
}

.final-scores h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

.final-scores-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.final-score-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--color-surface-light);
    border-radius: var(--radius-md);
}

.final-score-item.winner {
    background: var(--color-primary);
    color: var(--color-text-dark);
}

.final-score-item .rank {
    font-weight: 700;
    width: 30px;
}

.final-score-item .name {
    flex: 1;
}

.final-score-item .score {
    font-weight: 700;
    font-size: var(--font-size-lg);
}

.result-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* ============================================
   MODALS
   ============================================ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    color: var(--color-primary);
}

.modal-content h3 {
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.modal-small {
    max-width: 300px;
}

.modal-small .btn {
    margin-bottom: var(--spacing-sm);
}

.modal-celebration {
    text-align: center;
}

.celebration-emoji {
    font-size: 5rem;
    animation: celebrate 0.5s ease-in-out infinite alternate;
}

@keyframes celebrate {
    from { transform: scale(1) rotate(-5deg); }
    to { transform: scale(1.1) rotate(5deg); }
}

.modal-celebration h2 {
    color: var(--color-success);
    font-size: var(--font-size-2xl);
}

.modal-celebration p {
    margin: var(--spacing-md) 0;
}

#generala-winner-name {
    font-size: var(--font-size-xl);
    color: var(--color-primary);
    font-weight: 700;
}

.celebration-text {
    color: var(--color-text-muted);
}

.help-section {
    margin-bottom: var(--spacing-lg);
}

.help-section h3 {
    text-align: left;
    font-size: var(--font-size-md);
    margin-bottom: var(--spacing-sm);
}

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

.help-section ul {
    padding-left: var(--spacing-lg);
}

.help-section li {
    margin-bottom: var(--spacing-xs);
}

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

#toast-container {
    position: fixed;
    top: var(--spacing-md);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    pointer-events: none;
}

.toast {
    background: var(--color-surface);
    color: var(--color-text);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    max-width: 90vw;
}

.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast-error {
    border-left: 4px solid var(--color-danger);
}

.toast-info {
    border-left: 4px solid var(--color-primary);
}

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

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

/* ============================================
   RESPONSIVE - Tablet & Desktop
   ============================================ */

@media (min-width: 400px) {
    .die {
        width: 64px;
        height: 64px;
    }

    .die[data-value] .die-face::before {
        font-size: 2.5rem;
    }
}

@media (min-width: 480px) {
    .die {
        width: 70px;
        height: 70px;
    }

    .score-table {
        font-size: var(--font-size-md);
    }
}

@media (min-width: 768px) {
    .screen-content {
        max-width: 500px;
    }

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

    .die[data-value] .die-face::before {
        font-size: 3rem;
    }

    .score-section {
        padding: var(--spacing-md);
    }

    .score-table-wrapper {
        max-width: 600px;
        margin: 0 auto;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
