/* ============================================================
   AlkoKalk – Minimalist Blue Theme
   ============================================================ */

:root {
    --bg-primary: #0f1119;
    --bg-secondary: #1a1d2e;
    --bg-card: #1e2235;
    --bg-card-hover: #242840;
    --bg-input: #141724;
    --accent: #4a8fe7;
    --accent-hover: #5da0f5;
    --accent-glow: rgba(74, 143, 231, 0.15);
    --text-primary: #e0e4ef;
    --text-secondary: #8a90a8;
    --text-muted: #555870;
    --border: #2a2e42;
    --green: #4cb88a;
    --yellow: #e0b040;
    --red: #d45555;
    --radius: 10px;
    --transition: 0.2s ease;
}

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

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

/* ======================== TABS ======================== */

.tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab {
    padding: 8px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
}

.tab:hover {
    background: var(--accent-glow);
    color: var(--text-primary);
}

.tab.active {
    background: var(--accent);
    color: #fff;
}

.tab-title {
    margin-left: auto;
    font-size: 15px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
}

/* ======================== PANELS ======================== */

.panel {
    display: none;
    padding: 16px;
    min-height: calc(100vh - 52px);
}

.panel.active {
    display: block;
}

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

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 12px;
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(74, 143, 231, 0.3);
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* ======================== CALCULATOR LAYOUT ======================== */

.calc-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

@media (max-width: 800px) {
    .calc-grid {
        grid-template-columns: 1fr;
    }
}

/* ======================== FORM ======================== */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    align-items: center;
}

.form-grid label {
    font-size: 13px;
    color: var(--text-secondary);
}

input[type="number"],
select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    transition: var(--transition);
    outline: none;
}

input[type="number"]:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.radio-group {
    display: flex;
    gap: 14px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

input[type="radio"] {
    accent-color: var(--accent);
}

/* ======================== DRINK CONTROLS ======================== */

.drink-select {
    width: 100%;
    margin-bottom: 10px;
}

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

.drink-controls label {
    font-size: 13px;
    color: var(--text-secondary);
}

.drink-controls input {
    width: 60px;
}

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

.btn {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 143, 231, 0.3);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-remove {
    background: none;
    border: none;
    color: var(--red);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
}

.btn-remove:hover {
    background: rgba(212, 85, 85, 0.15);
}

/* ======================== TABLE ======================== */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: var(--bg-input);
    color: var(--text-secondary);
    font-weight: 600;
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

tbody tr:hover {
    background: var(--accent-glow);
}

/* ======================== RESULTS ======================== */

.total-alcohol {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.card-results {
    border-color: rgba(74, 143, 231, 0.3);
}

.bac-value {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.time-sober {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.drive-status {
    font-size: 14px;
    font-weight: 600;
}

.method-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
}

/* ======================== METHOD COMPARISON ======================== */

.method-comparison {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.method-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.method-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.method-bar-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.method-bar {
    flex: 1;
    height: 14px;
    background: var(--bg-input);
    border-radius: 7px;
    overflow: hidden;
}

.method-bar-fill {
    height: 100%;
    border-radius: 7px;
    transition: width 0.4s ease;
    min-width: 0;
}

.method-bac {
    font-size: 13px;
    font-weight: 600;
    min-width: 65px;
    text-align: right;
}

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

.game-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.game-controls label {
    font-size: 13px;
    color: var(--text-secondary);
}

.game-controls select {
    width: 140px;
}

.control-spacer {
    flex: 1;
}

.game-status {
    font-size: 13px;
    color: var(--text-secondary);
}

#game.active {
    display: flex;
    flex-direction: column;
    padding: 8px;
    height: calc(100vh - 52px);
}

.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0; /* Prevents flex children from overflowing vertically */
    width: 100%;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--radius);
    cursor: crosshair;
    background: #0c0e18;
    display: block;
    flex-shrink: 0;
}

/* ======================== SCORES ======================== */

.scores-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    background: rgba(12, 14, 24, 0.4);
    border-radius: 12px;
    border: 1px solid rgba(74, 143, 231, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.scores-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
    text-shadow: 0 2px 10px rgba(74, 143, 231, 0.2);
}

.current-record {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 24px;
    padding: 8px 16px;
    background: rgba(224, 176, 64, 0.1);
    border-radius: 20px;
    display: inline-block;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

.leaderboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 6px;
    font-size: 14px;
}

.leaderboard-table thead th {
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 12px;
}

.leaderboard-table tbody tr {
    background: rgba(22, 26, 40, 0.6);
    transition: transform 0.2s, background 0.2s;
}

.leaderboard-table tbody tr:hover {
    background: rgba(30, 36, 54, 0.8);
    transform: scale(1.01);
}

.leaderboard-table tbody td {
    padding: 14px 16px;
    border: none;
    color: var(--text-primary);
}

.leaderboard-table tbody td:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
    font-weight: 700;
    color: var(--text-secondary);
}

.leaderboard-table tbody td:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* Rank Highlights */
.leaderboard-table tbody tr.rank-1 {
    background: linear-gradient(90deg, rgba(224, 176, 64, 0.15) 0%, rgba(224, 176, 64, 0.05) 100%);
    border-left: 3px solid #e0b040;
}
.leaderboard-table tbody tr.rank-1 td:first-child { color: #e0b040; font-size: 16px; }

.leaderboard-table tbody tr.rank-2 {
    background: linear-gradient(90deg, rgba(160, 170, 190, 0.15) 0%, rgba(160, 170, 190, 0.05) 100%);
    border-left: 3px solid #a0aabe;
}
.leaderboard-table tbody tr.rank-2 td:first-child { color: #a0aabe; }

.leaderboard-table tbody tr.rank-3 {
    background: linear-gradient(90deg, rgba(200, 120, 80, 0.15) 0%, rgba(200, 120, 80, 0.05) 100%);
    border-left: 3px solid #c87850;
}
.leaderboard-table tbody tr.rank-3 td:first-child { color: #c87850; }

/* ======================== SCROLLBAR ======================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ======================== CHAT ======================== */

.chat-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    background: rgba(12, 14, 24, 0.4);
    border-radius: 12px;
    border: 1px solid rgba(74, 143, 231, 0.15);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    padding: 16px;
}

.chat-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.chat-disclaimer {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    line-height: 1.3;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-right: 8px;
    margin-bottom: 16px;
}

.chat-auth-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(14, 17, 27, 0.9);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    border-radius: var(--radius);
    text-align: center;
}

.chat-placeholder {
    text-align: center;
    color: var(--text-secondary);
    margin-top: auto;
    margin-bottom: auto;
    font-style: italic;
}

.chat-msg {
    display: flex;
    flex-direction: row;
    gap: 8px;
    max-width: 90%;
    animation: fadeIn 0.3s ease;
    align-items: flex-end;
}

.chat-msg.other {
    align-self: flex-start;
}

.chat-msg.self {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
}

.chat-msg-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

.chat-msg-header {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    gap: 8px;
}

.chat-msg.self .chat-msg-header {
    justify-content: flex-end;
}

.chat-msg-name {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-msg-delete {
    display: none;
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 12px;
    padding: 0 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.chat-msg-delete:hover {
    opacity: 1;
}

body.admin-mode .chat-msg-delete {
    display: block;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    word-break: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    position: relative;
}

.chat-msg.other .chat-msg-bubble {
    background: rgba(42, 47, 66, 0.8);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.chat-msg.self .chat-msg-bubble {
    background: rgba(74, 143, 231, 0.2);
    border: 1px solid rgba(74, 143, 231, 0.4);
    border-bottom-right-radius: 4px;
    color: #e6f0fa;
}

.chat-reactions-container {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.chat-reaction-badge {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.2s;
}

.chat-reaction-badge:hover {
    background: rgba(255,255,255,0.1);
}

.chat-msg-actions {
    display: none;
    position: absolute;
    bottom: -20px;
    top: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 10;
}

.chat-msg.other .chat-msg-actions {
    right: 0;
}

.chat-msg.self .chat-msg-actions {
    left: 0;
}

.chat-msg:hover .chat-msg-actions {
    display: flex;
}

.chat-action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 2px;
    border-radius: 4px;
    transition: background 0.2s;
}

.chat-action-btn:hover {
    background: rgba(255,255,255,0.1);
}

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

.chat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    gap: 8px;
}

.chat-img-preview-container {
    position: relative;
    align-self: flex-start;
    padding: 8px;
    background: rgba(22, 26, 40, 0.8);
    border-radius: 8px;
    border: 1px solid rgba(74, 143, 231, 0.3);
    margin-bottom: 4px;
}

#chatImagePreview {
    max-height: 80px;
    border-radius: 4px;
}

.btn-cancel-img {
    position: absolute;
    top: -6px;
    right: -6px;
    background: var(--red);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.btn-attach {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 16px;
    padding: 0 12px;
    transition: background 0.2s;
}

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

.chat-msg-image {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.chat-input-name,
.chat-input-msg {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
    transition: var(--transition);
}

.chat-input-name:focus,
.chat-input-msg:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(20, 24, 38, 0.8);
}

.chat-input-name {
    width: 120px;
}

.chat-input-msg {
    flex: 1;
}

.btn-send {
    padding: 0 16px;
    font-size: 18px;
}

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

@media (max-width: 600px) {
    .chat-container {
        height: calc(100vh - 160px);
    }
    .chat-input-row {
        flex-wrap: wrap;
    }
    .chat-input-name {
        width: 100%;
        margin-bottom: 4px;
    }
    .chat-input-msg {
        flex: 1;
    }
}

/* ======================== MOBILE ======================== */

@media (max-width: 600px) {
    .tabs {
        gap: 2px;
        padding: 8px 8px;
    }
    .tab {
        padding: 7px 12px;
        font-size: 12px;
    }
    .tab-title {
        display: none;
    }
    .panel {
        padding: 8px;
    }
    .card {
        padding: 14px;
    }
    .form-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }
    .drink-controls {
        flex-wrap: wrap;
    }
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }
    .bac-value {
        font-size: 18px;
    }
    input[type="number"],
    select {
        padding: 10px 12px;
        font-size: 15px;
    }
    .game-controls {
        gap: 6px;
        padding: 8px;
    }
    .game-controls .btn {
        flex: 1;
        min-width: 0;
    }
    .control-spacer {
        display: none;
    }
    .game-controls select {
        width: 100%;
    }
    .game-status {
        width: 100%;
        text-align: center;
        margin-top: 4px;
    }
    #gameCanvas {
        min-height: 350px;
        cursor: default;
        touch-action: none;
    }
    thead th, tbody td {
        padding: 6px 6px;
        font-size: 11px;
    }
    .scores-title {
        font-size: 18px;
    }
    .current-record {
        font-size: 14px;
    }
}

