/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: url('../images/08d8b3d9-1239-4326-979a-700899d32587.webp') center center / cover no-repeat fixed;
    color: #333;
    overflow-x: hidden;
    min-height: 100vh;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Fallback for mobile devices that don't support fixed backgrounds */
@media (max-width: 768px) {
    body {
        background-attachment: scroll;
    }
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1;
}

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

/* Loading Screen */
#loading-screen {
    background: rgba(0, 0, 0, 0.8);
    text-align: center;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    color: white;
    font-size: 18px;
    font-weight: 500;
}

/* Main Menu */
#main-menu {
    background: rgba(0, 0, 0, 0.6);
    padding: 20px;
}

.menu-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 700;
    color: white;
    margin-bottom: 20px;
    text-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
    letter-spacing: -1px;
}

.menu-topbar {
    display: contents;
}

.language-selector {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 3;
}

#user-badge {
    position: absolute;
    top: 20px;
    left: 20px;
    display: none;
    align-items: center;
    gap: 7px;
    z-index: 3;
    max-width: calc(100% - 110px);
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 22px;
    background: rgba(17, 24, 39, 0.48);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(12px);
    white-space: nowrap;
}

#user-avatar {
    width: 36px;
    height: 36px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
}

#user-name {
    display: inline-block;
    max-width: calc(100vw - 215px);
    overflow: hidden;
    color: #fff;
    font-weight: 600;
    text-overflow: ellipsis;
    vertical-align: middle;
}

#logout-btn {
    margin-left: 1px;
    vertical-align: middle;
}

.diamond-balance-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 54px;
    min-height: 32px;
    padding: 5px 10px;
    border: 1px solid rgba(148, 231, 255, 0.64);
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(20, 184, 218, 0.94), rgba(79, 70, 229, 0.94));
    color: #fff;
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.38);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.diamond-balance-pill[hidden] {
    display: none !important;
}

.diamond-balance-icon {
    font-size: 15px;
    filter: drop-shadow(0 1px 2px rgba(12, 38, 90, 0.45));
}

.diamond-balance-pill strong {
    font-size: 14px;
    font-weight: 850;
}

.language-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.language-btn:hover {
    background: white;
    color: #667eea;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 40px;
}

/* Avatar grid in profile */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
    justify-items: center;
}

.avatar-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    background: #fff;
}

.avatar-option.selected {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

/* Profile top bar with Save/Back */
.profile-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.profile-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
}

.profile-avatar-large {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 2px solid #dee2e6;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.profile-name-edit {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
}

.profile-progress-card {
    position: relative;
    display: grid;
    gap: 16px;
    margin-bottom: 22px;
    padding: 22px;
    overflow: hidden;
    border: 1px solid rgba(137, 188, 255, 0.36);
    border-radius: 24px;
    background:
        radial-gradient(circle at 88% 8%, rgba(91, 209, 255, 0.24), transparent 34%),
        linear-gradient(145deg, #17264b 0%, #253b74 52%, #29306a 100%);
    box-shadow: 0 18px 38px rgba(24, 39, 82, 0.3);
    color: #fff;
}

.profile-progress-card::after {
    position: absolute;
    right: -38px;
    bottom: -72px;
    width: 180px;
    height: 180px;
    border: 22px solid rgba(255, 255, 255, 0.035);
    border-radius: 50%;
    content: '';
    pointer-events: none;
}

.profile-progress-hero {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 16px;
}

.profile-level-orb {
    display: grid;
    place-items: center;
    width: 92px;
    aspect-ratio: 1;
    border: 3px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    background: linear-gradient(145deg, #69d6ff, #5267ed 62%, #7348c9);
    box-shadow:
        0 10px 24px rgba(23, 47, 112, 0.42),
        inset 0 2px 7px rgba(255, 255, 255, 0.45);
    text-align: center;
}

.profile-level-orb span {
    align-self: end;
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.profile-level-orb strong {
    align-self: start;
    margin-top: -1px;
    font-size: 38px;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 3px 8px rgba(24, 36, 92, 0.36);
}

.profile-xp-summary {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.profile-progress-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.profile-progress-heading > strong {
    font-size: 18px;
}

.profile-progress-heading > span {
    color: #bceeff;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.profile-xp-track {
    height: 12px;
    padding: 2px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.19);
    border-radius: 999px;
    background: rgba(7, 15, 39, 0.48);
}

#profile-xp-progress {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #5ce1ff, #8d8bff, #ffb657);
    box-shadow: 0 0 12px rgba(92, 225, 255, 0.72);
    transition: width 500ms cubic-bezier(0.22, 0.8, 0.24, 1);
}

#profile-xp-next {
    color: rgba(231, 240, 255, 0.72);
    font-size: 11px;
}

.profile-economy-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.profile-economy-tile {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 1px 9px;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(7px);
}

.profile-economy-icon {
    grid-row: 1 / span 2;
    font-size: 28px;
    filter: drop-shadow(0 3px 4px rgba(8, 20, 56, 0.36));
}

.profile-economy-tile > span:not(.profile-economy-icon) {
    color: rgba(228, 238, 255, 0.74);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.profile-economy-tile strong {
    font-size: 23px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
}

.profile-economy-diamonds {
    background: linear-gradient(135deg, rgba(22, 187, 222, 0.22), rgba(76, 81, 214, 0.18));
}

.profile-economy-boxes {
    background: linear-gradient(135deg, rgba(255, 183, 75, 0.21), rgba(190, 77, 125, 0.14));
}

.open-box-btn {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 50px;
    padding: 11px 16px;
    border: 1px solid #ffe4a1;
    border-radius: 15px;
    background: linear-gradient(135deg, #ffd057, #f28c28);
    color: #402006;
    box-shadow: 0 8px 20px rgba(238, 145, 36, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    font-weight: 850;
    cursor: pointer;
    transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.open-box-btn:hover:not(:disabled) {
    filter: saturate(1.1) brightness(1.06);
    transform: translateY(-2px);
    box-shadow: 0 11px 25px rgba(238, 145, 36, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.open-box-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.99);
}

.open-box-btn:disabled {
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(230, 237, 251, 0.15);
    color: rgba(255, 255, 255, 0.54);
    box-shadow: none;
    cursor: not-allowed;
}

.open-box-icon {
    font-size: 20px;
}

.open-box-arrow {
    font-size: 20px;
    transition: transform 180ms ease;
}

.open-box-btn:hover:not(:disabled) .open-box-arrow {
    transform: translateX(3px);
}

.menu-btn {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-btn.primary {
    background: white;
    color: #667eea;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.menu-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.menu-btn.secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid white;
}

.menu-btn.secondary:hover {
    background: white;
    color: #000;
}

/* Make the 'Show Results' quick button clearly visible in black */
#show-results-now-btn.menu-btn.secondary {
    background: #000 !important;
    color: #fff !important;
    border-color: #000 !important;
}

#show-results-now-btn.menu-btn.secondary:hover {
    background: #111 !important;
    color: #fff !important;
    border-color: #111 !important;
}

.menu-btn.tertiary {
    background: transparent;
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.menu-btn.tertiary:hover {
    border-color: white;
    background: rgba(255, 255, 255, 0.1);
    color: #000;
}

/* Input Screens */
#name-input, #room-code-input {
    background: rgba(0, 0, 0, 0.7);
    padding: 20px;
}

.input-container {
    width: 100%;
    max-width: 350px;
    text-align: center;
    background: white;
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.input-container h2 {
    color: #333;
    margin-bottom: 30px;
    font-size: 24px;
    font-weight: 600;
}

.input-container input {
    width: 100%;
    padding: 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 18px;
    margin-bottom: 25px;
    text-align: center;
    font-weight: 500;
}

/* Auth specific small inputs spacing fix */
#auth-screen .input-container input { margin-bottom: 12px; }

.input-container input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Waiting Screen */
#waiting-screen {
    background: rgba(0, 0, 0, 0.7);
    text-align: center;
    padding: 20px;
}

.waiting-container {
    color: white;
    max-width: 350px;
}

.waiting-container h2 {
    font-size: 24px;
    margin-bottom: 20px;
    font-weight: 600;
}

#room-code-display {
    background: rgba(255, 255, 255, 0.2);
    padding: 15px 25px;
    border-radius: 10px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 2px;
    margin: 20px 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Game Screen */
#game-screen {
    background: rgba(248, 249, 250, 0.7);
    display: none;
    flex-direction: column;
    position: relative;
    padding: 5px;
    height: 100vh;
    overflow: hidden;
}

#game-screen.active {
    display: flex;
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: linear-gradient(135deg, #2c3e50, #34495e);
    border-radius: 10px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.game-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.game-info #current-round {
    font-size: 18px;
    font-weight: bold;
    color: #ecf0f1;
}

.game-info #turn-text {
    font-size: 14px;
    color: #bdc3c7;
}

.game-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
}

.game-diamond-balance {
    min-width: 48px;
    min-height: 29px;
    padding: 4px 8px;
    border-color: rgba(178, 236, 255, 0.45);
    background: linear-gradient(135deg, rgba(14, 165, 202, 0.9), rgba(72, 61, 197, 0.94));
    box-shadow: 0 4px 11px rgba(0, 0, 0, 0.23);
}

.game-diamond-balance strong {
    font-size: 13px;
}

/* Timer container adjustments */
.timer-container {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.timer-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #28a745, #20c997);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
    box-shadow: 0 3px 10px rgba(40, 167, 69, 0.3);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.timer-circle::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: conic-gradient(from 0deg, transparent 0%, #dc3545 100%);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.timer-circle.warning {
    background: linear-gradient(135deg, #ffc107, #fd7e14);
    animation: pulse-warning 1s infinite;
}

.timer-circle.danger {
    background: linear-gradient(135deg, #dc3545, #e74c3c);
    animation: pulse-danger 0.5s infinite;
}

.timer-circle.danger::before {
    opacity: 0.3;
}

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

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

#timer-text {
    position: relative;
    z-index: 2;
}

/* Game Notifications */
.game-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 300px;
    text-align: center;
}

.game-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.game-notification.info {
    background: rgba(23, 162, 184, 0.95);
}

.game-notification.warning {
    background: rgba(255, 193, 7, 0.95);
    color: #212529;
}

.game-notification.danger {
    background: rgba(220, 53, 69, 0.95);
}

/* Player Areas */
.board-container {
    display: grid;
    grid-template-rows: 1fr 1fr;
    grid-template-columns: 1fr;
    gap: 8px;
    height: calc(100vh - 90px);
    overflow: hidden;
}

.opponent-area, .player-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.opponent-area { flex-direction: row-reverse; }
.opponent-area .columns-container { transform: rotate(180deg); }

.player-info {
    font-weight: 600;
    color: #495057;
    font-size: 16px;
    min-width: 100px;
    text-align: center;
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

/* Avatar placed outside the name box */
.player-info-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.avatar-outside {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid #dee2e6;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.throw-menu {
    position: fixed;
    transform: translateY(-100%);
    display: flex;
    gap: 5px;
    padding: 6px;
    border: 1px solid rgba(255, 210, 92, 0.7);
    border-radius: 14px;
    background: rgba(30, 35, 45, 0.94);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(10px);
    z-index: 3000;
}

.throw-item-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 54px;
    height: 56px;
    padding: 3px;
    overflow: visible;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 11px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.throw-item-btn:hover,
.throw-item-btn:focus-visible {
    border-color: rgba(255, 210, 92, 0.95);
    background: linear-gradient(145deg, rgba(255, 210, 92, 0.22), rgba(255, 255, 255, 0.06));
    transform: translateY(-3px) scale(1.04);
}

.throw-item-btn:disabled {
    opacity: 0.55;
    cursor: wait;
    transform: none;
}

.throw-item-icon {
    width: 43px;
    height: 43px;
    object-fit: contain;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.38));
}

.throw-cost {
    position: absolute;
    right: -3px;
    bottom: -4px;
    display: inline-flex;
    align-items: center;
    gap: 1px;
    min-width: 25px;
    height: 18px;
    padding: 0 5px 0 3px;
    border: 1px solid rgba(181, 225, 255, 0.8);
    border-radius: 999px;
    background: #172b4d;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.32);
}

.throw-cost-diamond {
    font-size: 10px;
    filter: saturate(1.25);
}

.columns-container {
    display: flex;
    gap: 8px;
    justify-content: center;
    width: 100%;
    max-width: 560px;
}

.column {
    min-height: 200px;
    width: 90px;
    background: rgba(255, 255, 255, 0.6);
    border: 2px solid #dee2e6;
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    transition: all 0.3s ease;
}

.column.clickable {
    cursor: pointer;
}

.column.clickable:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
}

.column.valid-placement {
    border-color: #28a745;
    background: rgba(40, 167, 69, 0.1);
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.3);
}

.column.invalid-placement {
    border-color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
    opacity: 0.6;
    cursor: not-allowed;
}

.column.winning-column {
    border-color: #ffd700;
    background: rgba(255, 215, 0, 0.2);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
    animation: winning-glow 2s infinite;
}

@keyframes winning-glow {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
        border-color: #ffd700;
    }
    50% { 
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.9);
        border-color: #ffed4e;
    }
}

.column-crown {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 24px;
    z-index: 10;
    animation: crown-bounce 1.5s infinite;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

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

/* Column Tooltip */
.column-tooltip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #ffd700;
    border-radius: 12px;
    padding: 16px;
    z-index: 5000; /* ensure above everything */
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    min-width: 220px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    pointer-events: none;
}

.column.winning-column:hover .column-tooltip,
.column.winning-column.tooltip-active .column-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1.05);
    pointer-events: auto;
}

/* Rotate opponent tooltips so player can read them normally */
.opponent-columns .column-tooltip {
    transform: translate(-50%, -50%) rotate(180deg);
}

.opponent-columns .column.winning-column:hover .column-tooltip,
.opponent-columns .column.winning-column.tooltip-active .column-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) rotate(180deg) scale(1.05);
    pointer-events: auto;
}

.tooltip-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: white;
}

.winning-hand, .losing-hand {
    text-align: center;
    width: 100%;
}

.hand-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    opacity: 0.8;
}

.hand-value {
    font-size: 14px;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.hand-value.winner {
    color: #28a745;
    background: rgba(40, 167, 69, 0.2);
    border-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.3);
}

.hand-value.loser {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.2);
    border-color: #dc3545;
}

.vs-divider {
    font-size: 16px;
    font-weight: 800;
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    padding: 4px 0;
}

/* Responsive tooltip for mobile */
@media (max-width: 480px) {
    .column-tooltip {
        min-width: 180px;
        padding: 12px;
    }
    
    .hand-value {
        font-size: 12px;
        padding: 6px 8px;
    }
    
    .vs-divider {
        font-size: 14px;
    }
}

/* Current Card Area */
.current-card-area {
    position: fixed;
    display: flex;
    flex-direction: column;
    z-index: 2000;
    pointer-events: none; /* avoid estorbar clics en tablero */
}
#current-card-container { pointer-events: auto; }
/* Center the current card area during swap phase for better UX */
.current-card-area.centered {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -40%);
}

#current-card-container { text-align: center; }

.card-instruction {
    margin-top: 15px;
    font-size: 14px;
    color: #6c757d;
    font-weight: 500;
}

/* Cards */
.card {
    width: 78px;
    height: 108px;
    background: white;
    border: 2px solid #333;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 4px;
    font-weight: 700;
    font-size: 16px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    position: relative;
    transition: all 0.3s ease;
    cursor: pointer;
}

.card.large {
    width: 96px;
    height: 136px;
    font-size: 22px;
    padding: 8px;
}

.card.red {
    color: #dc3545;
}

.card.black {
    color: #333;
}

/* Card elements - make text even bigger */
.card .card-rank {
    font-size: 18px;
    font-weight: 800;
}

.card .card-suit {
    font-size: 22px;
    font-weight: 700;
}

.card.large .card-rank {
    font-size: 22px;
    font-weight: 800;
}

.card.large .card-suit {
    font-size: 26px;
    font-weight: 700;
}

.card.face-down {
    background: linear-gradient(135deg, #4a6cf7 0%, #667eea 100%);
    color: white;
    border-color: #4a6cf7;
}

.card.face-down::before {
    content: '?';
    font-size: 24px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Cards revealed during swap phase */
.card.swap-revealed {
    background: white;
    border: 2px solid #28a745;
    box-shadow: 0 0 15px rgba(40, 167, 69, 0.5);
    animation: swap-reveal 0.5s ease-out;
}

@keyframes swap-reveal {
    0% {
        transform: rotateY(180deg);
        opacity: 0.5;
    }
    100% {
        transform: rotateY(0deg);
        opacity: 1;
    }
}

.card-rank {
    font-size: inherit;
    line-height: 1;
}

.card-suit {
    font-size: 1.2em;
    line-height: 1;
}

/* Swap Phase - Use same area as current card */
.swap-phase-content {
    text-align: center;
}

/* Ensure swap content is clickable despite parent pointer-events none */
#swap-phase-content {
    pointer-events: auto;
}

.swap-instruction {
    margin: 10px 0;
    font-size: 14px;
    color: #6c757d;
    font-weight: 500;
}

#pass-swap-btn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    border: 2px solid #6c757d;
    border-radius: 10px;
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    cursor: pointer;
    transition: all 0.3s ease;
    display: block;
    margin: 10px auto 5px auto; /* center horizontally */
    position: relative;
    z-index: 100;
}

#pass-swap-btn:hover {
    background: #6c757d;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(108, 117, 125, 0.3);
}

/* Results Screen */
#results-screen {
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
}

.results-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

#game-result-title {
    color: white;
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 30px;
}

.results-summary {
    background: white;
    border-radius: 20px;
    padding: 30px 20px;
    margin-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* History list rows */
#history-list .history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #e9ecef;
}
#history-list .history-row:last-child { border-bottom: none; }
#history-list .result-win { color: #28a745; font-weight: 700; }
#history-list .result-loss { color: #dc3545; font-weight: 700; }
#history-list .result-draw { color: #ffc107; font-weight: 700; }

.winner-display {
    font-size: 24px;
    font-weight: 700;
    color: #28a745;
    margin-bottom: 25px;
}

.results-header {
    font-size: 18px;
    font-weight: 600;
    color: #495057;
    margin-bottom: 20px;
}

.column-result {
    padding: 12px 0;
    border-bottom: 1px solid #e9ecef;
}

.column-result:last-child {
    border-bottom: none;
}

.hands-container {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    text-align: center;
}

.hands-container .winner {
    font-weight: 700;
    color: #28a745;
}

.hands-container .loser {
    color: #6c757d; /* keep neutral color */
    opacity: 1; /* ensure not faded */
}

/* Keep tooltip hand values crisp on hover/tap */
.column-tooltip .hand-value.loser,
.column-tooltip .hand-value.winner {
    opacity: 1;
}

/* Prevent opacity reduction on winning column hover tooltips */
.column.winning-column:hover .column-tooltip .hand-value,
.column.winning-column.tooltip-active .column-tooltip .hand-value {
    opacity: 1;
}

.hands-container .tie {
    color: #ffc107;
    font-weight: 600;
}

.vs-text {
    margin: 0 10px;
    color: #495057;
    font-weight: 600;
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Paid projectile animations */
.throw-projectile {
    position: fixed;
    pointer-events: none;
    transform-origin: center;
    will-change: transform, opacity;
    z-index: 5200;
}

.throw-projectile::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 65%;
    width: 42px;
    height: 14px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, rgba(255, 225, 126, 0.65));
    filter: blur(4px);
    opacity: 0.7;
    transform: translateY(-50%);
    z-index: -1;
}

.throw-projectile img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 8px 7px rgba(0, 0, 0, 0.35));
}

.throw-projectile--bomb img,
.throw-projectile--dynamite img {
    filter: drop-shadow(0 0 7px rgba(255, 174, 49, 0.42))
            drop-shadow(0 8px 7px rgba(0, 0, 0, 0.35));
}

.throw-impact {
    position: fixed;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 5250;
}

.throw-impact-mark {
    position: absolute;
    top: 0;
    left: 0;
    width: 66px;
    height: 66px;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0.2);
    animation: projectile-impact 700ms cubic-bezier(0.15, 0.78, 0.28, 1) forwards;
}

.throw-impact-mark::before,
.throw-impact-mark::after {
    content: '';
    position: absolute;
    inset: 50%;
    width: 100%;
    height: 100%;
    border: 3px solid currentColor;
    border-radius: 50%;
    opacity: 0.8;
    transform: translate(-50%, -50%) scale(0.25);
    animation: projectile-shockwave 720ms ease-out forwards;
}

.throw-impact-mark::after {
    animation-delay: 100ms;
}

.throw-impact--tomato .throw-impact-mark {
    width: 54px;
    height: 44px;
    border-radius: 42% 58% 48% 52% / 55% 43% 57% 45%;
    background:
        radial-gradient(circle at 68% 34%, #ff9b80 0 6%, transparent 7%),
        radial-gradient(circle at 46% 48%, #ef4a36 0 30%, #a81414 72%);
    color: #d82c27;
    box-shadow: 0 0 20px rgba(214, 30, 30, 0.38);
}

.throw-impact--bomb .throw-impact-mark,
.throw-impact--dynamite .throw-impact-mark {
    background: radial-gradient(circle, #fffbd0 0 12%, #ffd351 22%, #ff7a18 48%, #cf2418 66%, transparent 72%);
    color: #ff9e2d;
    box-shadow: 0 0 34px rgba(255, 104, 20, 0.8);
}

.throw-impact--dynamite .throw-impact-mark {
    width: 102px;
    height: 102px;
    box-shadow: 0 0 54px rgba(255, 104, 20, 0.9);
}

.throw-impact-particle {
    position: absolute;
    top: -3px;
    left: -3px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e9412c;
    opacity: 0;
    transform: rotate(var(--particle-angle)) translateX(8px) scale(1);
    animation: projectile-particle 680ms cubic-bezier(0.1, 0.72, 0.2, 1) var(--particle-delay) forwards;
}

.throw-impact--bomb .throw-impact-particle,
.throw-impact--dynamite .throw-impact-particle {
    background: #ffc247;
    box-shadow: 0 0 8px #ff7b1c;
}

.throw-impact--dynamite .throw-impact-particle {
    width: 9px;
    height: 9px;
}

.avatar-outside.projectile-hit {
    animation: projectile-target-hit 560ms cubic-bezier(0.2, 0.78, 0.2, 1);
}

#game-screen.projectile-shake {
    animation: projectile-screen-shake 360ms ease-out;
}

#game-screen.projectile-shake-strong {
    animation: projectile-screen-shake-strong 480ms ease-out;
}

@keyframes projectile-impact {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(-18deg); }
    38% { opacity: 1; transform: translate(-50%, -50%) scale(1.28) rotate(7deg); }
    72% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.94) rotate(0); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.08); }
}

@keyframes projectile-shockwave {
    0% { opacity: 0.8; transform: translate(-50%, -50%) scale(0.2); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.75); }
}

@keyframes projectile-particle {
    0% {
        opacity: 0;
        transform: rotate(var(--particle-angle)) translateX(8px) scale(0.4);
    }
    18% { opacity: 1; }
    100% {
        opacity: 0;
        transform: rotate(var(--particle-angle)) translateX(var(--particle-distance)) scale(0);
    }
}

@keyframes projectile-target-hit {
    0%, 100% { transform: translate(0, 0) rotate(0) scale(1); filter: brightness(1); }
    22% { transform: translate(-5px, 2px) rotate(-8deg) scale(1.12); filter: brightness(1.5); }
    45% { transform: translate(5px, -2px) rotate(7deg) scale(0.96); }
    68% { transform: translate(-2px, 1px) rotate(-3deg) scale(1.04); }
}

@keyframes projectile-screen-shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-3px, 2px); }
    50% { transform: translate(3px, -2px); }
    75% { transform: translate(-2px, -1px); }
}

@keyframes projectile-screen-shake-strong {
    0%, 100% { transform: translate(0, 0); }
    14% { transform: translate(-6px, 3px) rotate(-0.3deg); }
    28% { transform: translate(6px, -4px) rotate(0.3deg); }
    44% { transform: translate(-5px, -2px); }
    62% { transform: translate(4px, 3px); }
    80% { transform: translate(-2px, 1px); }
}

/* Card Deal Animation */
.dealing-card {
    position: absolute;
    width: 60px;
    height: 85px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    pointer-events: none;
    transform-origin: center center;
    transition: none;
}

@keyframes deal-to-column {
    0% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        opacity: 1;
    }
    50% {
        transform: translate(var(--mid-x, 0px), var(--mid-y, 0px)) rotate(15deg) scale(1.1);
        opacity: 0.9;
    }
    100% {
        transform: translate(var(--target-x), var(--target-y)) rotate(0deg) scale(1);
        opacity: 1;
    }
}

.dealing-card.animate {
    animation: deal-to-column 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

/* Dealing card content styles */
.dealing-card .card-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding: 5px;
    font-size: 16px;
    font-weight: bold;
}

/* Color classes for dealing cards */
.dealing-card.red {
    color: #dc3545;
}

.dealing-card.black {
    color: #333;
}

.dealing-card .card-rank {
    text-align: left;
}

.dealing-card .card-suit {
    text-align: center;
    font-size: 20px;
}

.dealing-card .card-back {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    font-size: 32px;
    color: white;
}

/* Instructions Screen */
#instructions-screen {
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    height: 100vh;
    box-sizing: border-box;
}

.instructions-container {
    width: 100%;
    max-width: 450px;
    background: white;
    border-radius: 20px;
    padding: 30px 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    margin: 20px auto;
    max-height: none;
    overflow: visible;
}

.instructions-container h2 {
    color: #333;
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 25px;
    text-align: center;
}

.instruction-section {
    margin-bottom: 25px;
}

.instruction-section h3 {
    color: #495057;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.instruction-section p {
    color: #6c757d;
    font-size: 16px;
    line-height: 1.6;
    margin-bottom: 10px;
}

.instruction-section ul {
    margin-left: 20px;
    color: #6c757d;
    font-size: 16px;
    line-height: 1.6;
}

.instruction-section li {
    margin-bottom: 8px;
}

#instructions-back-btn {
    width: 100%;
    margin-top: 20px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px 25px;
    border-radius: 15px;
    max-width: 350px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    color: #dc3545;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 15px;
}

.modal-content p {
    color: #495057;
    font-size: 16px;
    margin-bottom: 25px;
    line-height: 1.5;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Player card hover effects - only for player's own cards */
.player-columns .card.face-down:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.player-columns .card.face-down.own-card {
    position: relative;
}

.player-columns .card.face-down.own-card:hover::after {
    content: attr(data-card-info);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 100;
    opacity: 1;
    pointer-events: none;
    margin-bottom: 5px;
}

.player-columns .card.face-down.own-card::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    margin-bottom: -1px;
}

.player-columns .card.face-down.own-card:hover::before {
    opacity: 1;
}

/* Rotate opponent cards 180 degrees */
.opponent-columns .card {
    transform: rotate(180deg);
}

/* Opponent cards should not show details on hover */
.opponent-columns .card.face-down:hover {
    background: linear-gradient(135deg, #4a6cf7 0%, #667eea 100%);
    cursor: not-allowed;
    transform: rotate(180deg); /* Maintain rotation on hover */
}

.valid-placement {
    animation: pulse 1.5s infinite;
}

/* Responsive Design */
@media (max-width: 480px) {
    .game-title {
        font-size: 2.8rem;
    }
    
    .columns-container {
        gap: 6px;
        max-width: 320px;
    }
    
    .column {
        width: 55px;
        min-height: 130px;
    }
    
    .card {
        width: 45px;
        height: 65px;
        font-size: 11px;
    }
    
    .card.large {
        width: 70px;
        height: 98px;
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .columns-container {
        gap: 4px;
        max-width: 300px;
    }
    
    .column {
        width: 50px;
        min-height: 120px;
    }
    
    .card {
        width: 42px;
        height: 60px;
        font-size: 10px;
    }
}

/* Landscape Mode (Optional) */
@media (orientation: landscape) and (max-height: 600px) {
    .game-header {
        padding: 10px 20px;
        margin-bottom: 10px;
    }
    
    .opponent-area, .player-area {
        margin: 5px 0;
    }
    
    .current-card-area {
        margin: 10px 0;
    }
    
    .column {
        min-height: 100px;
    }
}

/* Resilient viewport layout ------------------------------------------------ */
:root {
    --safe-top: max(4px, env(safe-area-inset-top));
    --safe-right: max(4px, env(safe-area-inset-right));
    --safe-bottom: max(4px, env(safe-area-inset-bottom));
    --safe-left: max(4px, env(safe-area-inset-left));
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    min-height: 100dvh;
}

button,
input {
    font: inherit;
}

button:focus-visible,
input:focus-visible,
.column.clickable:focus-visible {
    outline: 3px solid #ffd54f;
    outline-offset: 3px;
}

.screen {
    height: 100dvh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.screen.active {
    justify-content: safe center;
}

#main-menu,
#name-input,
#room-code-input,
#auth-screen,
#wager-select-screen,
#computer-difficulty-screen,
#friends-screen,
#profile-screen,
#leaderboard-screen,
#waiting-screen,
#results-screen,
#instructions-screen {
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
        max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.menu-container,
.input-container,
.results-container,
.instructions-container {
    margin-block: auto;
}

.menu-buttons {
    gap: clamp(8px, 1.8vh, 15px);
    margin-top: clamp(18px, 4vh, 40px);
}

.menu-btn {
    min-height: 44px;
    padding: clamp(10px, 1.8vh, 16px) 24px;
}

.history-meta {
    color: #6c757d;
    font-size: 12px;
}

.history-result {
    text-align: right;
}

.leaderboard-rank,
.leaderboard-name,
.leaderboard-elo {
    padding: 12px;
}

.leaderboard-rank {
    color: #6c757d;
}

.leaderboard-name {
    font-weight: 600;
}

.leaderboard-elo {
    text-align: right;
}

/* The game screen never scrolls; its three rows scale within the viewport. */
#game-screen,
#game-screen.active {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    align-items: stretch;
    justify-content: flex-start;
}

.game-header {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    gap: clamp(6px, 2vw, 20px);
    min-height: 48px;
    margin-bottom: 4px;
    padding: 6px clamp(8px, 2vw, 20px);
    width: 100%;
    max-width: 100%;
}

.game-info {
    flex-direction: row;
    align-items: baseline;
    gap: 5px;
    white-space: nowrap;
}

.game-info .round-label {
    color: #bdc3c7;
    font-size: 13px;
}

.game-info #current-round {
    color: #fff;
    font-size: 18px;
    font-weight: 800;
}

.turn-indicator {
    min-width: 0;
    overflow: hidden;
    color: #fff;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.timer-container {
    position: static;
    inset: auto;
    z-index: 1;
    padding: 0;
    transform: none;
}

.timer-circle {
    width: 38px;
    height: 38px;
    font-size: 14px;
}

.board-container {
    flex: 1 1 auto;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 1320px;
    height: auto;
    min-height: 0;
    margin-inline: auto;
    overflow: visible;
}

.opponent-area,
.player-area {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(64px, 12vw, 120px);
    gap: clamp(4px, 1.5vw, 12px);
    min-width: 0;
    min-height: 0;
    margin: 0;
}

.opponent-area .columns-container,
.player-area .columns-container {
    grid-row: 1;
    grid-column: 1;
}

.opponent-area .player-info-block,
.player-area .player-info-block {
    grid-row: 1;
    grid-column: 2;
}

.player-info-block {
    min-width: 0;
    align-self: center;
}

.player-info {
    width: 100%;
    min-width: 0;
    max-width: 120px;
    padding: 6px 8px;
    overflow: hidden;
}

.player-info span {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.columns-container {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    justify-self: center;
    gap: clamp(2px, 1vw, 8px);
    width: 100%;
    max-width: 720px;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

/* Mirror the rival's five columns without rotating card contents. */
.opponent-area .columns-container {
    direction: rtl;
    transform: none;
}

.opponent-columns .column {
    direction: ltr;
}

/* Mirror the player's card order: new rival cards extend away from the center. */
.opponent-columns .column > .card {
    top: auto;
    bottom: calc(var(--card-index, 0) * var(--card-step));
    z-index: calc(var(--card-count, 1) - var(--card-index, 0));
}

.column {
    --card-step: clamp(28px, 3.8vh, 40px);
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    padding: 3px;
    overflow: visible;
    touch-action: manipulation;
}

.column > .card {
    position: absolute;
    top: calc(var(--card-index, 0) * var(--card-step));
    left: 50%;
    width: min(calc(100% - 6px), 78px);
    height: auto;
    aspect-ratio: 0.72;
    transform: translateX(-50%);
    z-index: calc(var(--card-index, 0) + 1);
}

/* Keep the poker information of every overlapped card in its visible strip. */
.column > .card:not(.face-down):not(.front-card) {
    flex-direction: row;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 3px;
}

.column > .card:not(.face-down):not(.front-card) .card-rank,
.column > .card:not(.face-down):not(.front-card) .card-suit {
    flex: 0 0 auto;
    line-height: 1;
}

.column > .card.front-card:not(.face-down) {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0;
}

.column > .card.front-card:not(.face-down) .card-rank {
    align-self: flex-start;
}

.column > .card.front-card:not(.face-down) .card-suit {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: clamp(18px, 3.7vw, 26px);
    transform: translate(-50%, -50%);
}

.column > .card:hover,
.player-columns .card.face-down:hover {
    transform: translateX(-50%) translateY(-2px);
}

.opponent-columns .card,
.opponent-columns .card.face-down:hover {
    transform: translateX(-50%);
}

.opponent-columns .card:hover {
    transform: translateX(-50%) translateY(-2px);
}

.opponent-columns .column-tooltip,
.opponent-columns .column.winning-column:hover .column-tooltip,
.opponent-columns .column.winning-column.tooltip-active .column-tooltip {
    transform: translate(-50%, -50%);
}

.current-card-area,
.current-card-area.centered {
    position: relative;
    inset: auto !important;
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: clamp(88px, 13vh, 120px);
    pointer-events: none;
    transform: none;
    z-index: 20;
}

.current-card-area.inactive {
    min-height: 0;
    height: 0;
    overflow: hidden;
}

#current-card-container,
#swap-phase-content {
    pointer-events: auto;
    text-align: center;
}

#current-card-container .card,
#swap-phase-content .card {
    margin-inline: auto;
}

.card-instruction,
.swap-instruction {
    max-width: min(80vw, 420px);
    margin: 5px auto 0;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.88);
    color: #343a40;
    font-size: clamp(11px, 1.6vw, 14px);
    line-height: 1.25;
}

.swap-phase-content.waiting {
    max-width: min(80vw, 420px);
}

#pass-swap-btn {
    min-height: 40px;
    margin: 5px auto;
    padding: 8px 20px;
}

.results-container {
    padding-block: 12px;
}

#results-screen.active {
    justify-content: safe center;
}

@media (min-width: 601px) {
    .opponent-area .columns-container,
    .player-area .columns-container {
        transform: translateX(clamp(32px, 6.5vw, 66px));
    }
}

@media (max-width: 600px) {
    .game-header {
        grid-template-columns: auto auto minmax(0, 1fr) auto;
        gap: 5px;
        min-height: 44px;
        padding: 4px 6px;
    }

    .game-info .round-label {
        font-size: 11px;
    }

    .game-info #current-round {
        font-size: 15px;
    }

    .turn-indicator {
        font-size: 12px;
    }

    .timer-circle {
        width: 34px;
        height: 34px;
        font-size: 12px;
    }

    #show-results-now-btn.menu-btn {
        min-height: 34px;
        padding: 4px 7px !important;
        font-size: 11px !important;
    }

    .opponent-area,
    .player-area {
        grid-template-columns: minmax(0, 1fr) clamp(52px, 18vw, 70px);
    }

    .avatar-outside {
        width: 34px;
        height: 34px;
    }

    .player-info {
        padding: 4px;
        font-size: 11px;
    }

    .column {
        --card-step: clamp(22px, 3.2vh, 28px);
        border-width: 1px;
        border-radius: 7px;
        padding: 2px;
    }

    .column > .card {
        width: min(calc(100% - 4px), 52px);
        border-width: 1px;
    }

    .column > .card .card-rank {
        font-size: 14px;
    }

    .column > .card .card-suit {
        font-size: 18px;
    }

    .current-card-area,
    .current-card-area.centered {
        min-height: 96px;
    }

    #current-card-container .card.large,
    #swap-phase-content .card.large {
        width: 60px;
        height: 84px;
        padding: 4px;
    }

    #current-card-container .card.large .card-rank,
    #swap-phase-content .card.large .card-rank {
        font-size: 17px;
    }

    #current-card-container .card.large .card-suit,
    #swap-phase-content .card.large .card-suit {
        font-size: 22px;
    }

    .card-instruction,
    .swap-instruction {
        font-size: 10px;
    }

    .game-title {
        font-size: clamp(2.2rem, 12vw, 2.8rem);
        margin-bottom: 8px;
    }

    .input-container,
    .results-summary,
    .instructions-container {
        padding: 22px 16px;
    }
}

@media (orientation: landscape) and (max-height: 600px) {
    .game-header {
        min-height: 38px;
        margin-bottom: 2px;
        padding: 2px 6px;
    }

    .timer-circle {
        width: 30px;
        height: 30px;
    }

    .opponent-area,
    .player-area {
        grid-template-columns: minmax(0, 1fr) 48px;
        gap: 3px;
    }

    .avatar-outside {
        width: 26px;
        height: 26px;
    }

    .player-info {
        padding: 2px;
        font-size: 9px;
    }

    .column {
        --card-step: clamp(13px, 3.8vh, 16px);
        border-radius: 5px;
        padding: 1px;
    }

    .column > .card {
        width: min(calc(100% - 2px), 41px);
        padding: 2px;
        border-radius: 4px;
    }

    .column > .card .card-rank {
        font-size: 11px;
    }

    .column > .card .card-suit {
        font-size: 14px;
    }

    .current-card-area,
    .current-card-area.centered {
        min-height: 52px;
    }

    #current-card-container .card.large,
    #swap-phase-content .card.large {
        width: 41px;
        height: 57px;
        padding: 2px;
    }

    #current-card-container .card.large .card-rank,
    #swap-phase-content .card.large .card-rank {
        font-size: 12px;
    }

    #current-card-container .card.large .card-suit,
    #swap-phase-content .card.large .card-suit {
        font-size: 15px;
    }

    .card-instruction,
    .swap-instruction {
        max-width: 260px;
        margin-top: 1px;
        padding: 1px 5px;
        font-size: 8px;
    }

    #pass-swap-btn {
        min-height: 26px;
        margin: 1px auto;
        padding: 2px 12px;
        font-size: 10px;
    }
}

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

/* Cashu wager opt-in, selection, funding, and payout surfaces. */
.cashu-settings[hidden] {
    display: none !important;
}

.wager-quick-btn {
    border: 2px solid #ffe18a;
    background: linear-gradient(135deg, #ffca28, #ffec8b);
    color: #352400;
    box-shadow: 0 7px 22px rgba(255, 193, 7, 0.28);
}

.wager-quick-btn:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #ffd54f, #fff1a8);
}

#wager-select-screen,
#computer-difficulty-screen {
    background: rgba(7, 10, 20, 0.88);
}

.wager-select-container {
    max-width: 520px;
}

.wager-select-container h2 {
    margin-bottom: 12px;
}

.wager-select-container > p {
    color: #475569;
    line-height: 1.45;
}

.wager-preset-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin: 22px 0;
}

.wager-preset {
    min-height: 52px;
    padding: 8px 4px;
    border: 2px solid #d5dae3;
    border-radius: 10px;
    background: #fff;
    color: #27364a;
    font-weight: 800;
    cursor: pointer;
}

.wager-preset.selected {
    border-color: #d89d00;
    background: #fff1b8;
    color: #4d3400;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2);
}

.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 22px 0 14px;
}

.difficulty-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 72px;
    padding: 10px 8px;
    border: 2px solid #d5dae3;
    border-radius: 10px;
    background: #fff;
    color: #27364a;
    cursor: pointer;
}

.difficulty-option strong {
    font-size: 17px;
    font-weight: 800;
}

.difficulty-option small {
    font-size: 12px;
    opacity: 0.75;
}

.difficulty-option.selected {
    border-color: #d89d00;
    background: #fff1b8;
    color: #4d3400;
    box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.2);
}

.wager-selection-note {
    font-size: 12px;
}

.wager-select-container .menu-btn {
    width: 100%;
    margin-top: 8px;
}

.wager-select-container .menu-btn.secondary {
    border-color: #65758b;
    color: #334155;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0;
    color: #667085;
    font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    height: 1px;
    flex: 1;
    background: #d8dee8;
}

.nostr-btn {
    width: 100%;
    background: #5b21b6;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.nostr-btn:hover,
.nostr-btn:focus-visible {
    background: #6d28d9;
    color: #fff;
}

.nostr-btn img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    padding: 3px;
    border-radius: 50%;
    background: #fff;
}

.auth-mode-toggle {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 12px;
}

.auth-mode-toggle .menu-btn {
    flex: 1;
    background: #e2e8f0;
    border: 2px solid #64748b;
    color: #1f2937;
}

.auth-mode-toggle .menu-btn:hover {
    background: #cbd5e1;
    color: #111827;
}

.auth-mode-toggle .menu-btn.selected {
    background: #111827;
    border-color: #111827;
    color: #fff;
}

#auth-btn.menu-btn.secondary {
    background: #111827;
    border-color: #fff;
    color: #fff;
}

#auth-btn.menu-btn.secondary:hover {
    background: #273449;
    color: #fff;
}

#auth-submit-btn.menu-btn.primary {
    width: 100%;
    background: #1d4ed8;
    color: #fff;
    box-shadow: 0 6px 18px rgba(29, 78, 216, 0.3);
}

#auth-submit-btn.menu-btn.primary:hover {
    background: #1e40af;
    color: #fff;
}

.auth-help {
    margin: 8px 0 12px;
    color: #667085;
    font-size: 11px;
    line-height: 1.35;
}

.nostr-auth-content h3 {
    color: #5b21b6;
}

.nostr-auth-content,
.nostr-backup-content {
    width: min(92vw, 430px);
    max-width: 430px;
    max-height: 90dvh;
    overflow-y: auto;
}

.nostr-modal-logo {
    width: 92px;
    height: 64px;
    object-fit: contain;
    margin-bottom: 8px;
}

.nostr-auth-content .menu-btn {
    width: 100%;
    margin-top: 9px;
}

.nostr-method {
    padding: 12px;
    border: 1px solid #d8dee8;
    border-radius: 12px;
    background: #f8fafc;
    text-align: left;
}

.nostr-method h4 {
    margin: 0 0 4px;
    color: #1f2937;
    font-size: 15px;
}

.nostr-method p {
    margin: 0 0 10px;
    font-size: 13px;
}

.nostr-method label {
    display: block;
    margin-bottom: 7px;
    color: #1f2937;
    font-weight: 700;
}

#nostr-nsec-input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 2px solid #94a3b8;
    border-radius: 9px;
    color: #111827;
    background: #fff;
    font: 14px/1.3 ui-monospace, SFMono-Regular, Consolas, monospace;
    user-select: text;
    -webkit-user-select: text;
}

#nostr-nsec-input:focus {
    outline: none;
    border-color: #5b21b6;
    box-shadow: 0 0 0 3px rgba(91, 33, 182, 0.16);
}

.nostr-button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.nostr-choice-btn {
    background: #5b21b6;
    border: 2px solid #5b21b6;
    color: #fff;
}

.nostr-choice-btn.secondary {
    background: #111827;
    border-color: #111827;
    color: #fff;
}

.nostr-choice-btn:hover,
.nostr-choice-btn.secondary:hover {
    background: #6d28d9;
    border-color: #6d28d9;
    color: #fff;
}

.nostr-create-key-btn {
    background: #087f5b;
    border: 2px solid #087f5b;
    color: #fff;
}

.nostr-create-key-btn:hover {
    background: #066448;
    border-color: #066448;
}

.nostr-create-key-btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.nostr-cancel-btn {
    background: #e2e8f0;
    border: 2px solid #94a3b8;
    color: #1f2937;
}

.nostr-cancel-btn:hover {
    background: #cbd5e1;
}

.nostr-backup-content h3 {
    color: #b45309;
}

.nostr-secret-warning {
    padding: 10px;
    border: 1px solid #f59e0b;
    border-radius: 9px;
    background: #fffbeb;
    color: #78350f !important;
    font-weight: 650;
}

#nostr-generated-nsec {
    width: 100%;
    min-height: 82px;
    padding: 10px;
    border: 2px solid #b45309;
    border-radius: 9px;
    resize: none;
    color: #111827;
    background: #fff;
    font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
    overflow-wrap: anywhere;
    user-select: text;
    -webkit-user-select: text;
}

.nostr-backup-content .menu-btn {
    width: 100%;
    margin-top: 9px;
}

.nostr-backup-check {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    margin: 14px 0 4px;
    color: #1f2937;
    text-align: left;
    line-height: 1.35;
}

.nostr-backup-check input {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
}

@media (max-width: 420px) {
    .nostr-button-row {
        grid-template-columns: 1fr;
    }
}

.cashu-settings {
    display: grid;
    gap: 10px;
    margin-bottom: 20px;
    text-align: left;
}

.cashu-settings h3 {
    margin: 0;
    text-align: center;
}

.cashu-balance-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid #f0cc61;
    border-radius: 10px;
    background: #fff7d6;
    color: #4d3400;
}

.cashu-balance-card strong {
    font-size: 20px;
    white-space: nowrap;
}

.cashu-private-balance {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.cashu-balance-visibility-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid #ddb84a;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    color: #654600;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    transition: background 160ms ease, transform 160ms ease;
}

.cashu-balance-visibility-btn:hover {
    background: #fff;
    transform: translateY(-1px);
}

.cashu-eye-icon {
    font-size: 15px;
    line-height: 1;
}

.cashu-balance-card.compact {
    margin: 10px 0;
}

.diamond-shop-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid #99d7ff;
    border-radius: 12px;
    background: linear-gradient(135deg, #edf9ff, #eef1ff);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.diamond-pack-icon {
    font-size: 28px;
    filter: drop-shadow(0 2px 3px rgba(29, 108, 176, 0.25));
}

.diamond-pack-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
    color: #17324d;
}

.diamond-pack-copy strong,
.diamond-pack-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.diamond-pack-copy small {
    color: #52667a;
    font-size: 11px;
}

#buy-diamonds-btn {
    min-height: 36px;
    margin: 0;
    padding: 7px 12px;
    font-size: 12px;
}

.diamond-purchase-status {
    min-height: 16px;
    margin: -4px 2px 0;
    color: #1d6f42;
    font-size: 12px;
    line-height: 1.35;
}

.diamond-purchase-status.error {
    color: #a62222;
}

.cashu-wallet-actions {
    display: grid;
    gap: 8px;
}

.cashu-wallet-actions label {
    margin-top: 6px;
    font-weight: 700;
}

#cashu-deposit-token {
    width: 100%;
    user-select: text;
    -webkit-user-select: text;
}

.cashu-withdraw-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.cashu-withdraw-row input,
.cashu-withdraw-row button {
    min-width: 0;
    margin: 0;
}

#cashu-withdraw-btn.menu-btn.secondary {
    background: #111827 !important;
    border: 2px solid #111827 !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.24);
}

#cashu-withdraw-btn.menu-btn.secondary:hover {
    background: #273449 !important;
    border-color: #273449 !important;
    color: #fff !important;
}

#cashu-withdraw-btn.menu-btn.secondary:disabled {
    background: #64748b !important;
    border-color: #64748b !important;
    color: #fff !important;
    cursor: not-allowed;
    opacity: 0.7;
}

.cashu-toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    line-height: 1.35;
}

.cashu-toggle-row input[type="checkbox"] {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 1px;
}

#cashu-deposit-token,
#wager-payout-token {
    width: 100%;
    user-select: text;
    -webkit-user-select: text;
}

.cashu-warning {
    color: #8a4b00;
    font-size: 12px;
    line-height: 1.4;
}

.cashu-mint-label,
.wager-mint-url {
    display: block;
    overflow-wrap: anywhere;
    color: #334155;
    font-size: 11px;
}

#wager-funding-screen {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overflow: auto;
    background: rgba(7, 10, 20, 0.82);
}

.wager-funding-container {
    max-width: 500px;
    max-height: none;
    margin: auto;
}

.wager-terms-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.wager-terms-grid div {
    display: grid;
    gap: 3px;
    padding: 9px 6px;
    border-radius: 9px;
    background: #f1f5f9;
    text-align: center;
}

.wager-terms-grid span {
    font-size: 11px;
}

.wager-payment-status {
    display: grid;
    gap: 5px;
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 9px;
    background: #eef2ff;
    font-weight: 700;
}

.wager-payment-status .paid {
    color: #087f5b;
}

.wager-mint-url {
    margin: 8px 0;
    padding: 8px;
    border-radius: 7px;
    background: #111827;
    color: #f8fafc;
}

#cashu-deposit-token,
#wager-payout-token {
    min-height: 92px;
    padding: 10px;
    border: 1px solid #94a3b8;
    border-radius: 8px;
    resize: vertical;
    font: 12px/1.35 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.wager-funding-container .menu-btn,
.wager-payout-content .menu-btn {
    width: 100%;
    margin-top: 8px;
}

.wager-funding-container .menu-btn.secondary,
.wager-payout-content .menu-btn.secondary {
    border-color: #475569;
    color: #334155;
}

.wager-payout-content {
    width: min(92vw, 520px);
}

@media (max-width: 600px) {
    .wager-preset-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .wager-terms-grid {
        gap: 5px;
    }

    .wager-funding-container {
        padding: 18px 14px;
    }

    .wager-funding-container .menu-btn,
    .wager-payout-content .menu-btn {
        min-height: 42px;
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Back buttons must remain visible on both light cards and dark screens. */
.screen .menu-btn[id$="-back-btn"] {
    background: #1f2937;
    color: #fff;
    border: 2px solid #475569;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
}

.screen .menu-btn[id$="-back-btn"]:hover {
    background: #111827;
    color: #fff;
    border-color: #64748b;
    transform: translateY(-2px);
}

.screen .menu-btn[id$="-back-btn"]:focus-visible {
    outline: 3px solid #fbbf24;
    outline-offset: 3px;
}

/* Installed-app and modern mobile viewport behavior. */
html {
    height: 100%;
    background: #1a1a2e;
    overscroll-behavior: none;
}

body {
    min-height: 100dvh;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
    touch-action: manipulation;
}

@supports (height: 100dvh) {
    .screen {
        min-height: 100dvh;
    }

    #game-screen {
        height: 100dvh;
    }
}

@media (display-mode: standalone) {
    html {
        background: #4b240f url('../images/08d8b3d9-1239-4326-979a-700899d32587.webp')
            center center / cover no-repeat;
    }

    .screen {
        inset: 0;
        width: auto;
        height: auto;
        min-height: 100%;
    }

    #main-menu,
    #profile-screen,
    #wager-funding-screen {
        padding-top: max(20px, calc(env(safe-area-inset-top) + 12px));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
    }

    #main-menu {
        background:
            linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)),
            url('../images/08d8b3d9-1239-4326-979a-700899d32587.webp') center center / cover no-repeat;
    }

    .menu-topbar.authenticated {
        position: absolute;
        top: max(32px, calc(env(safe-area-inset-top) + 12px));
        left: max(20px, env(safe-area-inset-left));
        right: max(20px, env(safe-area-inset-right));
        z-index: 3;
        display: flex;
        align-items: center;
        gap: 7px;
        min-width: 0;
    }

    .menu-topbar.authenticated #user-badge {
        position: static;
        flex: 0 1 auto;
        align-items: center;
        min-width: 0;
        max-width: none;
    }

    .menu-topbar.authenticated #user-name {
        min-width: 0;
        max-width: calc(100vw - 235px);
    }

    .menu-topbar.authenticated #logout-btn {
        flex: 0 0 auto;
        margin-left: 7px;
    }

    .menu-topbar.authenticated .language-selector {
        position: static;
        flex: 0 0 auto;
    }

    .language-selector {
        top: max(32px, calc(env(safe-area-inset-top) + 16px));
        right: max(20px, env(safe-area-inset-right));
    }
}

@media (max-width: 600px) {
    #user-badge {
        left: max(8px, env(safe-area-inset-left));
        gap: 5px;
        max-width: calc(100% - 66px);
        padding: 4px 5px;
    }

    #user-avatar {
        width: 32px;
        height: 32px;
    }

    #user-name {
        max-width: 25vw;
        font-size: 12px;
    }

    #logout-btn.language-btn {
        min-height: 32px;
        padding: 5px 8px;
        font-size: 10px;
    }

    #menu-diamonds {
        min-width: 46px;
        min-height: 29px;
        padding: 4px 7px;
    }

    .profile-progress-card {
        gap: 13px;
        padding: 17px 14px;
        border-radius: 20px;
    }

    .profile-progress-hero {
        gap: 12px;
    }

    .profile-level-orb {
        width: 76px;
    }

    .profile-level-orb strong {
        font-size: 31px;
    }

    .profile-progress-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 2px;
    }

    .profile-progress-heading > strong {
        font-size: 15px;
    }

    .profile-economy-tile {
        gap: 1px 6px;
        padding: 10px;
    }

    .profile-economy-icon {
        font-size: 23px;
    }

    .profile-economy-tile strong {
        font-size: 19px;
    }

    .cashu-balance-card:not(.compact) {
        align-items: flex-start;
        flex-direction: column;
    }

    .cashu-private-balance {
        justify-content: space-between;
        width: 100%;
    }

    .game-diamond-balance {
        min-width: 43px;
        min-height: 27px;
        padding: 3px 6px;
    }

    .game-diamond-balance .diamond-balance-icon {
        font-size: 12px;
    }

    .game-diamond-balance strong {
        font-size: 11px;
    }
}

@media (max-width: 370px) {
    #user-name {
        display: none;
    }

    .profile-economy-grid {
        grid-template-columns: 1fr;
    }
}
