/* ============================================
   CSS Variables
   ============================================ */
:root {
    --color-primary: #FFD700;
    --color-secondary: #FF6B35;
    --color-accent: #00D4FF;
    --color-success: #2ECC71;
    --color-error: #E74C3C;
    --color-bg: #0D1B2A;
    --color-card: #1B263B;
    --color-surface: #253649;
    --color-text: #FFFFFF;
    --color-text-muted: #8B8B8B;
    --color-gold: #FFD700;
    --color-silver: #C0C0C0;
    --color-bronze: #CD7F32;

    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition-speed: 0.3s;
    --border-radius: 12px;
}

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

html {
    font-size: 16px;
}

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

/* ============================================
   Screen System
   ============================================ */
.screen {
    display: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
}

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

.screen-content {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* ============================================
   Logo
   ============================================ */
.logo {
    text-align: center;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 56px;
    display: block;
    animation: pulse 2s ease-in-out infinite;
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 2px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    padding: 14px 24px;
    font-size: 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-primary {
    background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
    color: var(--color-bg);
}

.btn-primary:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.4);
}

.btn-primary:not(:disabled):active {
    transform: translateY(0);
}

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

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

.btn-large {
    min-height: 56px;
    font-size: 1.125rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-accent);
    font-size: 0.875rem;
    cursor: pointer;
    text-decoration: underline;
}

.btn-icon {
    font-size: 1.25rem;
}

.btn-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-add {
    width: 48px;
    min-height: 48px;
    padding: 0;
    font-size: 1.5rem;
    border-radius: var(--border-radius);
    background: var(--color-primary);
    color: var(--color-bg);
    flex-shrink: 0;
}

/* ============================================
   Inputs
   ============================================ */
input[type="text"] {
    width: 100%;
    height: 48px;
    padding: 12px 16px;
    font-size: 1rem;
    color: var(--color-text);
    background: var(--color-surface);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    outline: none;
    transition: all var(--transition-speed);
}

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

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

/* ============================================
   Players Setup
   ============================================ */
.players-setup {
    width: 100%;
}

.players-setup h2 {
    font-size: 1rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.add-player {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.add-player input {
    flex: 1;
}

.players-list {
    list-style: none;
    background: var(--color-card);
    border-radius: var(--border-radius);
    max-height: 200px;
    overflow-y: auto;
}

.players-list:empty {
    display: none;
}

.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-surface);
}

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

.player-item .player-name {
    font-weight: 500;
}

.player-item .btn-remove {
    background: none;
    border: none;
    color: var(--color-error);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
}

.hint {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-align: center;
    margin-top: 8px;
}

/* ============================================
   Countdown Screen
   ============================================ */
.countdown-content {
    text-align: center;
}

.turn-label {
    font-size: 1.25rem;
    color: var(--color-text-muted);
}

.countdown-player {
    font-size: 2rem;
    color: var(--color-primary);
    margin: 8px 0 40px;
}

.countdown-number {
    font-size: 8rem;
    font-weight: 800;
    color: var(--color-primary);
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.5);
    animation: countdown-pulse 1s ease-in-out infinite;
}

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

.prepare-text {
    font-size: 1.25rem;
    color: var(--color-secondary);
    margin-top: 40px;
}

/* ============================================
   Playing Screen
   ============================================ */
.playing-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--color-card);
    border-radius: var(--border-radius);
}

.player-info {
    display: flex;
    flex-direction: column;
}

.playing-name {
    font-weight: 600;
    font-size: 0.875rem;
}

.playing-score {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-primary);
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timer-icon {
    font-size: 1.25rem;
}

.timer-value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--color-primary);
    min-width: 50px;
    text-align: right;
}

.timer-value.low {
    color: var(--color-error);
    animation: shake 0.5s ease-in-out infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

.timer-bar {
    width: 100%;
    height: 8px;
    background: var(--color-surface);
    border-radius: 4px;
    overflow: hidden;
}

.timer-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    border-radius: 4px;
    transition: width 0.1s linear;
}

.timer-bar-fill.low {
    background: var(--color-error);
}

/* ============================================
   Question
   ============================================ */
.question-container {
    width: 100%;
    background: var(--color-card);
    border-radius: var(--border-radius);
    padding: 24px 20px;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.question-text {
    font-size: 1.375rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.4;
}

.answer-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#input-answer {
    font-size: 1.125rem;
    text-align: center;
    height: 56px;
}

/* ============================================
   Stats Display
   ============================================ */
.stats-display {
    display: flex;
    gap: 24px;
    justify-content: center;
}

.stat {
    font-size: 1.125rem;
    font-weight: 600;
}

.stat.correct {
    color: var(--color-success);
}

.stat.wrong {
    color: var(--color-error);
}

/* ============================================
   Feedback
   ============================================ */
.feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px 40px;
    border-radius: var(--border-radius);
    font-size: 1.25rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 50;
    animation: feedback-pop 0.3s ease-out;
}

.feedback.hidden {
    display: none;
}

.feedback.correct {
    background: var(--color-success);
    color: white;
}

.feedback.wrong {
    background: var(--color-error);
    color: white;
}

.feedback-icon {
    font-size: 1.5rem;
}

@keyframes feedback-pop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.1); }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ============================================
   Player Results Screen
   ============================================ */
.time-up {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--color-secondary);
    animation: time-up-pulse 0.5s ease-out;
}

@keyframes time-up-pulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.result-name {
    font-size: 1.5rem;
    color: var(--color-primary);
}

.result-score {
    text-align: center;
    padding: 24px;
    background: var(--color-card);
    border-radius: var(--border-radius);
    width: 100%;
}

.score-value {
    font-size: 4rem;
    font-weight: 800;
    color: var(--color-primary);
    display: block;
}

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

.result-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
}

.result-stat {
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    display: block;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.next-hint {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* ============================================
   Final Results Screen
   ============================================ */
.trophy {
    font-size: 80px;
    animation: bounce 1s ease-in-out;
}

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

#screen-final-results h2 {
    font-size: 1.5rem;
    text-align: center;
}

.final-ranking {
    width: 100%;
    background: var(--color-card);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.final-rank-item {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--color-surface);
}

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

.final-rank-item.first {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 107, 53, 0.1));
}

.final-rank-position {
    font-size: 1.5rem;
    width: 40px;
}

.final-rank-name {
    flex: 1;
    font-weight: 600;
}

.final-rank-details {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.final-rank-score {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-primary);
}

.final-rank-stats {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

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

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--color-card);
    border-radius: var(--border-radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    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;
    line-height: 1;
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 20px;
}

.help-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.help-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.help-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.help-item p {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* ============================================
   Toast
   ============================================ */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-card);
    color: var(--color-text);
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 200;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

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

/* ============================================
   Responsive
   ============================================ */
@media (min-width: 768px) {
    .screen-content {
        max-width: 480px;
    }

    .logo h1 {
        font-size: 2.25rem;
    }

    .question-text {
        font-size: 1.5rem;
    }
}

/* ============================================
   Hidden utility
   ============================================ */
.hidden {
    display: none !important;
}
