/* ===== VARIABLES ===== */
:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --bg-hover: #242424;
    --bg-input: #0f0f0f;
    --accent-green: #4ade80; 
    --accent-green-dark: #3fc16f;
    --accent-red: #8b2525;
    --accent-red-dark: #691212;
    --accent-purple: #60a5fa;
    --accent-purple-dark: #407dc8;
    --accent-yellow: #f59e0b;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border-color: #27272a;
    --border-light: #3f3f46;
    --radius: 10px;
    --radius-sm: 6px;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== PAGE ===== */
.page {
    display: none;
    min-height: 100vh;
    padding: 12px;
    padding-bottom: 70px;
}

.page.active {
    display: block;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 4px;
}

/* ===== LANDING ===== */
.game-title {
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -0.3px;
}

.name-inputs {
    background: var(--bg-card);
    padding: 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
}

.name-inputs h2 {
    text-align: center;
    margin-bottom: 14px;
    font-size: 0.85rem;
    font-weight: 600;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.input-group label {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.input-group input {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.2s;
    width: 100%;
}

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

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

.landing-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

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

.btn-success {
    background: var(--accent-green);
    color: white;
}

.btn-success:hover {
    background: var(--accent-green-dark);
}

.btn-secondary {
    background: var(--accent-purple);
    color: #ffffff;
}

.btn-secondary:hover {
    background: var(--accent-purple-dark);
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover {
    background: var(--accent-red-dark);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.7rem;
}

/* ===== GAME PAGE ===== */
.role-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

.role-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.role-btn:hover:not(.viewed) {
    border-color: var(--accent-green);
}

.role-btn.viewed {
    border-color: var(--text-muted);
    cursor: default;
    opacity: 0.7;
}

.role-btn .eye-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.role-btn .eye-icon svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.role-btn.viewed .eye-icon {
    color: var(--text-muted);
}

.role-btn .player-name-btn {
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ===== GAME HEADER ===== */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    gap: 10px;
}

.game-header h2 {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.game-header .btn {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 0.7rem;
}

/* ===== GUESS PHASE ===== */
.guess-phase {
    background: var(--bg-card);
    padding: 16px 12px;
    border-radius: var(--radius);
    text-align: center;
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.hidden {
    display: none !important;
}

.reveal-info {
    margin-bottom: 12px;
}

.reveal-info p {
    font-size: 0.8rem;
    padding: 8px 10px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-weight: 500;
}

.find-culprit {
    margin-bottom: 14px;
}

.find-culprit h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-yellow);
    line-height: 1.4;
}

.guess-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.btn-guess {
    width: 100%;
    max-width: 200px;
    padding: 10px 16px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-guess:hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    color: #1a1a1a;
}

.timer {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-red);
    font-variant-numeric: tabular-nums;
}

/* ===== TABLE - MOBILE FIRST ===== */
.table-container {
    width: 100%;
    overflow-x: hidden;
    margin-bottom: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    table-layout: fixed;
}

th, td {
    padding: 6px 3px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.65rem;
}

thead th {
    background: var(--bg-hover);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}

th:first-child,
td:first-child {
    width: 14%;
}

th:not(:first-child),
td:not(:first-child) {
    width: 21.5%;
}

.player-header {
    color: var(--text-primary) !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.total-row {
    background: var(--bg-hover) !important;
}

.total-row td {
    font-weight: 600;
}

.total-points {
    font-size: 0.7rem;
}

/* ===== RESULTS ===== */
.results-title {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 18px;
}

.final-standings {
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    border: 1px solid var(--border-color);
}

.standing-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
}

.standing-row.first {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid var(--accent-yellow);
}

.standing-row .rank {
    font-weight: 600;
    color: var(--accent-yellow);
    min-width: 26px;
    font-size: 0.7rem;
}

.standing-row .player-name {
    flex: 1;
    margin-left: 6px;
    font-weight: 500;
}

.standing-row .score {
    font-weight: 600;
    color: var(--accent-purple);
}

.winner-announcement {
    text-align: center;
    font-size: 1rem;
    margin-bottom: 16px;
    padding: 14px;
    background: rgba(245, 158, 11, 0.04);
    border: 1px solid rgba(245, 158, 11, 0.15);
    border-radius: var(--radius);
    font-weight: 600;
}

.winner-announcement strong {
    color: var(--accent-yellow);
}

.results-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.results-buttons .btn {
    width: 100%;
    max-width: 180px;
}

/* ===== MODALS ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: flex-start;
    z-index: 1000;
    padding: 12px;
    overflow-y: auto;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    padding: 18px 14px;
    border-radius: var(--radius);
    max-width: 320px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border-color);
    margin: auto;
    margin-top: 20px;
}

.modal-content h2 {
    margin-bottom: 10px;
    font-size: 0.95rem;
    font-weight: 700;
}

.role-modal-content p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

#role-player-name {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 2px;
}

.role-display {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 12px 0;
    padding: 10px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
}

.role-display.chor { color: #f87171; border-color: #f87171; }
.role-display.dakat { color: #fb923c; border-color: #fb923c; }
.role-display.babu { color: #4ade80; border-color: #4ade80; }
.role-display.pulish { color: #60a5fa; border-color: #60a5fa; }

.auto-close-text {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 6px;
    margin-bottom: 10px;
}

#result-details p {
    margin: 4px 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#result-details span {
    color: var(--text-primary);
    font-weight: 600;
}

.result-outcome {
    margin: 10px 0;
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
}

.result-outcome.correct {
    background: rgba(16, 185, 129, 0.1);
    color: #4ade80;
}

.result-outcome.wrong {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

.points-breakdown {
    background: var(--bg-secondary);
    padding: 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    text-align: left;
}

.points-breakdown h4 {
    margin-bottom: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-align: center;
}

#points-list div {
    padding: 4px 8px;
    margin: 3px 0;
    background: var(--bg-hover);
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
}

#points-list span:last-child {
    color: #4ade80;
    font-weight: 600;
}

.result-buttons,
.quit-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.result-buttons .btn,
.quit-buttons .btn {
    width: 100%;
}

/* Rules Modal */
.rules-modal-content {
    max-width: 100%;
    max-height: 75vh;
    overflow-y: auto;
    text-align: left;
}

.rules-content h3 {
    font-size: 0.8rem;
    font-weight: 600;
    margin: 12px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.rules-content h3:first-child { margin-top: 0; }

.rules-content ul,
.rules-content ol {
    padding-left: 14px;
}

.rules-content li {
    margin: 4px 0;
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.rules-content p {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.7rem;
}

.rules-content strong { color: var(--text-primary); }

/* ===== FOOTER ===== */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary, #f8f9fa); /* Fallback color if variable is missing */
    border-top: 1px solid var(--border-color, #e7e7e7);
    padding: 10px 12px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary, #666);
    z-index: 100;
}

.footer p {
    margin: 0; /* Removes default paragraph spacing */
}

.author-link {
    color: var(--accent-green, #4ade80); /* Matches your "BABU" green */
    text-decoration: none;
    font-weight: 600;
    transition: opacity 0.15s ease;
}

.author-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.author-link:visited {
    color: var(--accent-green, #4ade80);
}

/* ===== RESPONSIVE - TABLET & DESKTOP ===== */
@media (min-width: 500px) {
    .container {
        max-width: 560px;
        padding: 10px;
    }
    
    .page {
        padding: 16px;
        padding-bottom: 70px;
    }
    
    .game-title {
        font-size: 1.6rem;
        margin-bottom: 28px;
    }
    
    .name-inputs {
        padding: 24px 28px;
    }
    
    .name-inputs h2 {
        font-size: 0.95rem;
        margin-bottom: 18px;
    }
    
    .input-group {
        flex-direction: row;
        align-items: center;
        gap: 14px;
        margin-bottom: 14px;
    }
    
    .input-group label {
        min-width: 80px;
        font-size: 0.85rem;
    }
    
    .input-group input {
        flex: 1;
        padding: 12px 14px;
        font-size: 0.9rem;
    }
    
    .landing-buttons {
        flex-direction: row;
        justify-content: center;
        gap: 12px;
    }
    
    .btn {
        padding: 11px 24px;
        font-size: 0.8rem;
    }
    
    .role-buttons {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .role-btn {
        padding: 11px 16px;
        font-size: 0.8rem;
    }
    
    .role-btn .eye-icon svg {
        width: 18px;
        height: 18px;
    }
    
    .game-header {
        padding: 12px 16px;
    }
    
    .game-header h2 {
        font-size: 0.9rem;
    }
    
    .game-header .btn {
        padding: 10px 18px;
        font-size: 0.75rem;
    }
    
    .guess-phase {
        padding: 20px;
    }
    
    .reveal-info p {
        display: inline-block;
        margin: 5px;
        font-size: 0.9rem;
    }
    
    .find-culprit h3 {
        font-size: 0.95rem;
    }
    
    .guess-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .btn-guess {
        width: auto;
        max-width: none;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 0.7rem;
    }
    
    thead th {
        font-size: 0.65rem;
    }
    
    .player-header {
        font-size: 0.72rem;
    }
    
    .total-points {
        font-size: 0.75rem;
    }
    
    .results-buttons .btn {
        width: 180px;
    }
    
    .result-buttons,
    .quit-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .result-buttons .btn,
    .quit-buttons .btn {
        width: auto;
    }
}

@media (min-width: 700px) {
    .page {
        padding: 24px;
        padding-bottom: 75px;
    }
    
    .container {
        max-width: 640px;
    }
    
    .game-title {
        font-size: 1.9rem;
        margin-bottom: 36px;
    }
    
    .name-inputs {
        padding: 32px 36px;
    }
    
    .name-inputs h2 {
        font-size: 1rem;
        margin-bottom: 22px;
    }
    
    .input-group {
        margin-bottom: 16px;
    }
    
    .input-group input {
        padding: 14px 16px;
        font-size: 0.95rem;
    }
    
    .btn {
        padding: 12px 28px;
        font-size: 0.85rem;
    }
    
    .role-btn {
        padding: 12px 20px;
    }
    
    .results-title {
        font-size: 1.5rem;
    }
    
    .final-standings {
        padding: 18px;
    }
    
    .standing-row {
        padding: 12px 16px;
        font-size: 0.9rem;
    }
    
    .winner-announcement {
        font-size: 1.2rem;
        padding: 18px;
    }
    
    .modal-content {
        padding: 24px;
        max-width: 380px;
    }
    
    .modal-content h2 {
        font-size: 1.1rem;
    }
    
    .role-display {
        font-size: 1.6rem;
        padding: 14px;
    }
    
    .rules-modal-content {
        max-width: 440px;
    }
    
    .footer {
        padding: 12px 16px;
        font-size: 0.8rem;
    }
}

/* Safe area for notch devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .page { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
    .footer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}