/* ==================
   CSS VARIABLES
   ================== */
:root {
    --color-bg: #1a1a2e;
    --color-surface: #16213e;
    --color-card: #0f3460;
    --color-primary: #e94560;
    --color-primary-hover: #c73e54;
    --color-secondary: #533483;
    --color-success: #28a745;
    --color-success-hover: #218838;
    --color-danger: #dc3545;
    --color-warning: #ffc107;
    --color-silver: #adb5bd;
    --color-gold: #ffd700;
    --color-text: #f0f0f0;
    --color-text-muted: #8892a4;
    --color-green: #28a745;
    --color-red: #e94560;
    --color-border: #2a2a4a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html {
    font-size: 16px;
}

body {
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

/* ==================
   LAYOUT
   ================== */
.container {
    max-width: 480px;
    margin: 0 auto;
    padding: 1rem;
    padding-bottom: 2rem;
}

.mt-1 { margin-top: 1rem; }
.text-center { text-align: center; }
.text-large { font-size: 1.2rem; }
.text-muted { color: var(--color-text-muted); }
.text-red { color: var(--color-red); }
.text-green { color: var(--color-green); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ==================
   NAVBAR
   ================== */
.navbar {
    background: var(--color-surface);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--color-primary);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    color: var(--color-text);
    font-weight: 700;
    font-size: 1.1rem;
}

.nav-brand i { color: var(--color-primary); }

.nav-links {
    display: flex;
    gap: 1.25rem;
}

.nav-link {
    color: var(--color-text-muted);
    font-size: 1.1rem;
    transition: color 0.2s;
}

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

/* ==================
   CARDS
   ================== */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
}

.card h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--color-text-muted);
}

.card h2 i { color: var(--color-primary); }

.card-link {
    display: block;
    color: var(--color-text);
    transition: transform 0.2s, border-color 0.2s;
    margin-bottom: 0.5rem;
}

.card-link:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary);
}

.card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.card-players {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.card-notes {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-style: italic;
}

.card-total {
    font-weight: 700;
    color: var(--color-primary);
}

.card-list { display: flex; flex-direction: column; gap: 0.5rem; }

/* ==================
   BUTTONS
   ================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.btn-secondary { background: var(--color-secondary); }
.btn-secondary:hover { opacity: 0.9; }

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

.btn-stop { background: var(--color-danger); }
.btn-stop:hover { background: #c82333; }

.btn-silver { background: var(--color-silver); color: #333; }
.btn-silver:hover { background: #9ca3af; }

.btn-rebuy {
    background: var(--color-success);
    flex: 1;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
}
.btn-ghost:hover { color: var(--color-text); }

.btn-full { width: 100%; }
.btn-large { padding: 1rem 1.5rem; font-size: 1.2rem; }
.btn-small { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
.btn-tiny { padding: 0.3rem 0.5rem; font-size: 0.75rem; }

/* ==================
   FORMS
   ================== */
.form-group {
    margin-bottom: 1rem;
}

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

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
select {
    width: 100%;
    padding: 0.75rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 1rem;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--color-primary);
}

.input-small {
    width: 80px;
    padding: 0.4rem;
    font-size: 0.9rem;
}

.input-time {
    width: 70px;
    padding: 0.3rem;
    font-size: 0.85rem;
    display: inline-block;
}

.time-range {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.input-tiny {
    width: 40px;
    padding: 0.3rem;
    font-size: 0.85rem;
    text-align: center;
    display: inline-block;
}

.row-timed td { background: rgba(233, 69, 96, 0.05); }
.row-rounds td { background: rgba(83, 52, 131, 0.1); }

/* ==================
   ALERTS
   ================== */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    transition: opacity 0.3s;
}

.alert-error {
    background: rgba(233, 69, 96, 0.2);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
}

/* ==================
   LOGIN
   ================== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header i { color: var(--color-primary); }
.login-header h1 {
    margin-top: 0.5rem;
    font-size: 1.5rem;
}

/* ==================
   HOME
   ================== */
.hero {
    text-align: center;
    padding: 2rem 0;
}

.hero i { color: var(--color-primary); }
.hero h1 { margin: 0.5rem 0 0.25rem; }
.hero p { color: var(--color-text-muted); }

.badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
}

.badge-setup { background: var(--color-warning); color: #333; }
.badge-playing { background: var(--color-success); }
.badge-finished { background: var(--color-text-muted); }

.game-list { list-style: none; }
.game-list li { border-bottom: 1px solid var(--color-border); }
.game-list li:last-child { border-bottom: none; }
.game-list a {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    color: var(--color-text);
}

.game-date { font-weight: 600; }
.game-location { color: var(--color-text-muted); font-size: 0.85rem; }

/* ==================
   SETUP
   ================== */
.setup h1 { text-align: center; }
.subtitle { text-align: center; color: var(--color-text-muted); margin-bottom: 1rem; }

.player-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.75rem;
}

.chip {
    background: var(--color-card);
    padding: 0.4rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    border: 2px solid transparent;
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    border-color: var(--color-primary);
}

.chip-active {
    border-color: var(--color-gold);
    background: rgba(255, 215, 0, 0.15);
    color: var(--color-gold);
}

.table-blinds {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table-blinds th,
.table-blinds td {
    padding: 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--color-border);
}

.table-blinds th {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
}

/* Seating */
.seating-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.seat {
    background: var(--color-card);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
    position: relative;
    cursor: grab;
    user-select: none;
    transition: transform 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.seat-dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.seat-dragover {
    box-shadow: 0 0 0 2px var(--color-primary);
    transform: scale(1.05);
}

.seat-ghost {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.85;
    transform: scale(1.08);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.text-small {
    font-size: 0.8rem;
}

.seat-dealer {
    border: 2px solid var(--color-gold);
}

.seat-position {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    display: block;
}

.seat-name {
    font-weight: 700;
    font-size: 1.1rem;
}

.dealer-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--color-gold);
    color: #333;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.7rem;
}

/* ==================
   PLAY SCREEN
   ================== */
.blind-bar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.blind-info, .blind-next {
    text-align: center;
}

.blind-label {
    display: block;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.blind-values {
    font-weight: 700;
    font-size: 1.1rem;
}

.blind-timer {
    background: var(--color-card);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.timer-warning {
    animation: pulse 1s infinite;
    color: var(--color-warning);
}

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

.round-counter {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.dealer-indicator {
    width: 100%;
    text-align: center;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
    color: var(--color-gold);
}

/* Player cards */
.player-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.player-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    transition: all 0.3s;
}

.player-card.player-stopped {
    opacity: 0.5;
    border-color: var(--color-text-muted);
}

.player-header h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.dealer-badge-small {
    background: var(--color-gold);
    color: #333;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
}

.player-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.stat { text-align: center; }
.stat-label {
    display: block;
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
}
.stat-value {
    font-weight: 700;
    font-size: 1rem;
}

.player-actions {
    display: flex;
    gap: 0.5rem;
}

.player-actions .btn {
    padding: 0.6rem;
    font-size: 0.8rem;
    flex: 1;
}

.player-undo {
    text-align: center;
    margin-top: 0.5rem;
}

.player-result {
    text-align: center;
    padding: 0.5rem;
}

.position {
    font-weight: 700;
    font-size: 0.9rem;
}

.position-1 { color: var(--color-gold); }
.position-2 { color: var(--color-silver); }
.position-out { color: var(--color-text-muted); }

/* Blind popup */
.blind-popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.blind-popup-content {
    background: var(--color-surface);
    border: 3px solid var(--color-warning);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    max-width: 320px;
    width: 90%;
    animation: popIn 0.3s ease-out;
}

.blind-popup-content i {
    color: var(--color-warning);
}

.blind-popup-content h2 {
    margin: 1rem 0;
}

.blind-popup-values {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--color-warning);
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Screen flash */
body.flash {
    animation: screenFlash 1s;
}

@keyframes screenFlash {
    0%, 20%, 40%, 60%, 80%, 100% { background: var(--color-bg); }
    10%, 30%, 50%, 70%, 90% { background: rgba(255, 193, 7, 0.3); }
}

/* ==================
   RESULTS
   ================== */
.podium {
    text-align: center;
    padding: 1.5rem 0;
}

.podium-winner {
    margin-bottom: 1rem;
}

.podium-winner h2 {
    margin: 0.5rem 0 0.25rem;
}

.podium-runner-up h3 {
    margin: 0.25rem 0;
}

.gold { color: var(--color-gold); }
.silver { color: var(--color-silver); }

.prize {
    display: block;
    color: var(--color-green);
    font-weight: 600;
}

.net {
    display: block;
    font-size: 0.9rem;
}

.table-results {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table-results th,
.table-results td {
    padding: 0.6rem 0.4rem;
    text-align: right;
    border-bottom: 1px solid var(--color-border);
}

.table-results th:first-child,
.table-results td:first-child {
    text-align: left;
}

.table-results.has-name th:nth-child(2),
.table-results.has-name td:nth-child(2) {
    text-align: left;
}

.table-results th {
    color: var(--color-text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
}

.table-results tfoot th {
    font-size: 0.85rem;
    color: var(--color-text);
}

.row-winner { background: rgba(255, 215, 0, 0.1); }
.row-runner-up { background: rgba(173, 181, 189, 0.1); }

/* Timeline */
.timeline {
    position: relative;
    padding-left: 1rem;
}

.timeline-item {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.5rem 0;
    border-left: 2px solid var(--color-border);
    padding-left: 1rem;
    margin-left: 0.5rem;
}

.timeline-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    min-width: 40px;
    font-variant-numeric: tabular-nums;
}

.timeline-icon {
    color: var(--color-primary);
    font-size: 0.85rem;
}

.timeline-blind .timeline-icon {
    color: var(--color-warning);
}

.timeline-text {
    font-size: 0.85rem;
}

/* ==================
   OVERALL / HISTORY
   ================== */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.stat-card {
    background: var(--color-card);
    border-radius: var(--radius-sm);
    padding: 1rem;
    text-align: center;
}

.stat-name {
    display: block;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.stat-amount {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
}

.stat-detail {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.table-history {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.table-history th,
.table-history td {
    padding: 0.4rem 0.3rem;
    border-bottom: 1px solid var(--color-border);
    text-align: right;
}

.table-history th {
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: 0.65rem;
    position: sticky;
    top: 0;
    background: var(--color-surface);
}

.table-history td:first-child,
.table-history th:first-child {
    text-align: left;
}

.cell-winner {
    background: rgba(255, 215, 0, 0.2);
    color: var(--color-gold);
    font-weight: 700;
}

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

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==================
   RESPONSIVE
   ================== */
@media (min-width: 768px) {
    .container {
        max-width: 640px;
    }

    .player-grid {
        grid-template-columns: 1fr 1fr 1fr 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr 1fr 1fr;
    }
}
