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

:root {
    --bg-primary: var(--t-bg);
    --bg-secondary: var(--t-panel);
    --bg-card: var(--t-panel);
    --bg-card-hover: #1d1d4a;
    --bg-input: var(--t-panel-deep);
    --chrom-bg: rgba(10, 10, 26, 0.78);
    --well: rgba(0, 0, 0, 0.28);
    --hairline: rgba(255, 255, 255, 0.09);
    --tint: rgba(255, 255, 255, 0.05);

    --text-primary: var(--t-ink);
    --text-secondary: var(--t-muted);
    --text-muted: var(--t-muted); /* 4.5:1 hint/placeholder text (was --t-dim, 2.16–3.43:1) */
    --text-bright: #ffffff;
    /* Ink on accent (both themes use the light #b9ea62 accent): dark ink passes
       on every accent surface (~13:1). Do not use --t-ink here (light in dark). */
    --on-accent: #161613;

    /* Results identity colors, per theme so both stop + badge usages pass AA */
    /* (light: deep blue/red on pale tinted banners; dark: pale blue/red on dark). */
    --results-crew: #1e5f9e;
    --results-imp: #b23b32;
    --vote-red: #b23b32;

    --accent: var(--t-accent);
    --accent-light: #a29bfe;
    --accent-2: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.4);
    --title-end: #ff6b9d;

    --danger: #ff6b6b;
    --danger-glow: rgba(255, 107, 107, 0.3);
    --success: #51cf66;
    --success-glow: rgba(81, 207, 102, 0.3);
    --warning: #ffd43b;
    --impostor-red: #ff4757;
    --impostor-glow: rgba(255, 71, 87, 0.3);
    --crewmate-blue: #45aaf2;
    --crewmate-glow: rgba(69, 170, 242, 0.3);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);

    --transition: 0.2s ease;
    --transition-slow: 0.4s ease;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

/* Per-theme re-themeing of the purple/navy identity aliases.
   --t-* tokens come from theme.css; only the game-identity aliases flip. */
html[data-theme="light"] {
    --bg-card-hover: #e9e9e1;
    --bg-input: var(--t-panel-deep);
    --chrom-bg: rgba(255, 255, 255, 0.85);
    --well: rgba(0, 0, 0, 0.05);
    --hairline: rgba(0, 0, 0, 0.09);
    --tint: rgba(0, 0, 0, 0.04);
    --text-bright: #191918;
    --on-accent: #161613;
    --accent-light: #5b4fd4;
    --accent-2: #7a6ce8;
    --warning: var(--t-warn);
    --title-end: #b23b57;
    --results-crew: #15416b;
    --results-imp: #7d2721;
    --vote-red: #7d2721;
}

html[data-theme="dark"] {
    --bg-input: #1a1a3e;
    --on-accent: #161613;
    --accent-light: #b3aaff;
    --warning: var(--t-warn);
    --results-crew: #8fd0ff;
    --results-imp: #ffb4ba;
    --vote-red: #ffd3d8;
}

html, body {
    height: 100%;
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    height: 100%;
    position: relative;
}

.games-home-link {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border: 1px solid var(--hairline);
    border-radius: 10px;
    color: var(--text-secondary);
    background: var(--chrom-bg);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    backdrop-filter: blur(10px);
    transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.games-home-link:hover,
.games-home-link:focus-visible {
    color: var(--text-bright);
    border-color: var(--accent-light);
    background: var(--bg-secondary);
    outline: none;
}

/* ===== PARTICLES ===== */
.particles {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.15;
    animation: float linear infinite;
}

@keyframes float {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 0.15; }
    90% { opacity: 0.15; }
    100% { transform: translateY(-100px) rotate(720deg); opacity: 0; }
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 1;
    /* overflow-y auto already computes overflow-x to auto; force hidden so a
       wide child can never create a horizontal scrollbar (scrollWidth > width). */
    overflow-y: auto;
    overflow-x: hidden;
}

/* Screen-reader-only live region (polite announcements). */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: screenIn var(--t-speed, 200ms) ease;
}

/* Phase transitions: crossfade with an 8px rise on the incoming screen. */
@keyframes screenIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

/* Solid accent, not a gradient: dark ink passes on the accent stop but only
   ~2.9:1 on the purple end, so a two-stop gradient can't host one text color.
   #161613 on #b9ea62 measures ~13:1 in both themes. */
.btn-primary {
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--accent-glow);
}

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(108, 92, 231, 0.3);
}

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

.btn-danger {
    background: linear-gradient(135deg, #c0392b, #8f1f13);
    color: white;
    box-shadow: 0 4px 15px var(--danger-glow);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px var(--danger-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--hairline);
}

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

.btn-toggle {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--hairline);
    padding: 8px 16px;
    font-size: 13px;
}

.btn-toggle.active {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
    box-shadow: 0 2px 10px var(--accent-glow);
}

.btn-lg {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
}

.btn-icon {
    font-size: 18px;
}

.btn-icon-only {
    background: none;
    border: 1px solid var(--hairline);
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
}

.btn-icon-only:hover {
    background: var(--tint);
    color: var(--text-primary);
}

.btn-group {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* ===== INPUTS ===== */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"] {
    background: var(--bg-input);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 15px;
    transition: all var(--transition);
    outline: none;
    width: 100%;
}

input[type="text"]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.number-input {
    display: flex;
    align-items: center;
    gap: 12px;
}

.number-input label {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 30px;
}

.number-input span {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-bright);
    min-width: 24px;
    text-align: center;
    font-family: var(--font-display);
}

.btn-num {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--hairline);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-num:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.range-inputs {
    display: flex;
    gap: 20px;
}

.number-input.small span {
    font-size: 16px;
}

/* ===== HOME SCREEN ===== */
.home-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    max-width: 420px;
    width: 100%;
    padding: 20px;
}

.logo-section {
    text-align: center;
}

.logo-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 14px;
}

.logo-mark {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    animation: pulse 3s ease-in-out infinite;
}

.logo-mark svg {
    width: 100%;
    height: 100%;
    display: block;
}

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

.game-title {
    font-family: var(--font-display);
    font-size: 48px;
    font-weight: 800;
    letter-spacing: 8px;
    background: linear-gradient(135deg, var(--accent-light), var(--title-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    margin-top: 8px;
}

.home-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 13px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--hairline);
}

/* ===== LOBBY SCREEN ===== */
.lobby-container {
    width: 100%;
    max-width: 1100px;
    height: 100%;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    overflow-y: auto;
}

.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.lobby-title-section {
    display: flex;
    align-items: center;
    gap: 20px;
}

.lobby-title-section h2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
}

.game-code-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(108, 92, 231, 0.2);
}

.code-label {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.code-value {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: 3px;
}

.lobby-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.name-change-section {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 6px 12px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(108, 92, 231, 0.15);
}

.change-name-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--hairline);
    color: var(--text-primary);
    font-size: 13px;
    padding: 5px 10px;
    border-radius: 4px;
    min-width: 0;
}

.timer-config {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.timer-bar {
    width: 100%;
    height: 28px;
    background: var(--tint);
    border-radius: var(--radius-sm);
    position: relative;
    overflow: hidden;
    margin-top: 8px;
}

.timer-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: var(--radius-sm);
    transition: width 1s linear;
    width: 100%;
}

.timer-fill.warning {
    background: linear-gradient(90deg, #e17055, #d63031);
}

.timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    background: var(--t-panel);
    padding: 0 6px;
    border-radius: 4px;
}

.lobby-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.lobby-left > .btn {
    flex-shrink: 0;
}

.lobby-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ===== PLAYERS ===== */
.players-section h3,
.config-section h3,
.chat-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.player-count {
    background: var(--accent);
    color: var(--on-accent);
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 100px;
    margin-left: 8px;
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
    transition: all var(--transition);
}

.player-item:hover {
    background: var(--bg-card-hover);
}

.player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: white;
    flex-shrink: 0;
}

.player-name {
    flex: 1;
    font-weight: 500;
    font-size: 14px;
}

.player-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
    background: var(--accent);
    color: var(--on-accent);
}

.player-badge.you {
    background: rgba(81, 207, 102, 0.28);
    color: var(--on-accent);
}

/* ===== CONFIG ===== */
.config-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 1px solid var(--hairline);
}

.config-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-item > label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.impostor-config {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ===== CHAT ===== */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.chat-header h3 {
    margin-bottom: 0;
}

.chat-toggle-btn {
    background: transparent;
    border: 1px solid var(--hairline);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 9px;
    cursor: pointer;
}

.chat-toggle-btn:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.3);
}

.chat-section.collapsed .chat-messages,
.chat-section.collapsed .chat-input-row,
.chat-section.collapsed .chat-reply-preview,
.chat-section.collapsed .chat-mention-dropdown {
    display: none;
}

.chat-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 16px;
    border: 1px solid var(--hairline);
    position: relative;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 4px;
    min-height: 80px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--tint);
    border-radius: 2px;
}

.chat-msg {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.4;
    animation: slideIn 0.2s ease;
    position: relative;
}

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

.chat-msg .chat-sender {
    font-weight: 600;
    margin-right: 6px;
}

.chat-msg.system {
    background: rgba(108, 92, 231, 0.1);
    color: var(--text-secondary);
    font-style: italic;
    font-size: 12px;
}

.chat-msg.user {
    background: var(--tint);
}

.chat-msg.user:hover .chat-reply-btn {
    opacity: 1;
}

.chat-msg.mention-highlight {
    background: rgba(108, 92, 231, 0.12);
    border-left: 2px solid var(--accent);
}

/* Chat @mention styling */
.chat-mention {
    color: var(--accent-light);
    font-weight: 600;
    background: rgba(108, 92, 231, 0.15);
    padding: 0 3px;
    border-radius: 3px;
    cursor: default;
}

/* Chat reply button */
.chat-reply-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    background: rgba(108, 92, 231, 0.2);
    border: none;
    color: var(--accent-light);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: opacity 0.15s ease, background 0.15s ease;
}

.chat-reply-btn:hover {
    background: rgba(108, 92, 231, 0.35);
}

/* Chat reply reference in message */
.chat-reply-ref {
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(108, 92, 231, 0.08);
    border-left: 2px solid var(--accent);
    padding: 2px 6px;
    margin-bottom: 4px;
    border-radius: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Chat reply preview bar above input */
.chat-reply-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: rgba(108, 92, 231, 0.1);
    border-left: 2px solid var(--accent);
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.chat-reply-preview .reply-preview-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-cancel {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
}

.reply-cancel:hover {
    color: var(--danger);
}

/* Chat mention autocomplete dropdown */
.chat-mention-dropdown {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid rgba(108, 92, 231, 0.3);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 150px;
    overflow-y: auto;
    z-index: 50;
}

.mention-item {
    padding: 6px 12px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s ease;
}

.mention-item:hover {
    background: rgba(108, 92, 231, 0.15);
}

.chat-input-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-shrink: 0;
}

.chat-input-row input {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
}

/* ===== COUNTDOWN ===== */
.countdown-container {
    text-align: center;
}

.countdown-number {
    font-family: var(--font-display);
    font-size: 140px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--title-end) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: countdownPulse 1s ease-in-out infinite;
    line-height: 1;
}

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

.countdown-text {
    font-size: 20px;
    color: var(--text-secondary);
    margin-top: 20px;
}

/* ===== ROLE REVEAL ===== */
.role-container {
    perspective: 1000px;
}

/* 3D flip on load: the card starts edge-on with the patterned back facing the
   viewer, then rotates 90deg -> 0deg so the back swings away and the face lands. */
.role-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 40px;
    text-align: center;
    /* overflow:hidden clips the 3D back face mid-flip (it projected past the
       card's left edge, x=-122 at 390). max-width:100% keeps a long word
       from growing the card beyond its container. */
    overflow: hidden;
    max-width: min(400px, 100%);
    border: 1px solid var(--hairline);
    box-shadow: var(--shadow-lg);
    transform-style: preserve-3d;
}

.role-card.flip {
    animation: cardFlip 500ms cubic-bezier(.2, .7, .3, 1) both;
}

@keyframes cardFlip {
    from { transform: rotateY(90deg); }
    to { transform: rotateY(0deg); }
}

.role-card-face {
    display: contents;
}

.role-card-back {
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    border: 1px solid var(--hairline);
    background: var(--bg-input);
    background-image: repeating-linear-gradient(45deg, var(--accent-glow) 0 14px, transparent 14px 28px);
    display: grid;
    place-items: center;
    gap: 10px;
    transform: rotateY(-90deg);
    transform-origin: left center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    pointer-events: none;
}

.role-card-back .card-back-mark {
    width: 56px;
    height: 56px;
}

.role-card-back .card-back-mark svg {
    width: 100%;
    height: 100%;
}

.role-card-back span {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--text-bright);
    opacity: 0.75;
}

/* Role artwork row: 96-120px 2-tone silhouette + small emoji badge */
.role-art-row {
    position: relative;
    width: 120px;
    margin: 0 auto 20px;
}

.role-art {
    width: 120px;
    height: 120px;
}

.role-art svg {
    width: 100%;
    height: 100%;
    display: block;
}

.role-badge {
    position: absolute;
    right: -8px;
    bottom: -8px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    background: var(--bg-input);
    border: 2px solid var(--t-panel);
}

#role-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--accent-light);
}

.role-word-container {
    /* Solid theme well (was rgba(0,0,0,.3): a fixed overlay that breaks label
       contrast in light theme) keeps the secret box readable in both themes. */
    background: var(--well);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.role-word-container.blurred .role-info-value,
.role-word-container.blurred .role-info-label {
    filter: blur(12px);
    transition: filter 0.15s ease;
}

.role-word-container.peeking .role-info-value,
.role-word-container.peeking .role-info-label {
    filter: blur(0);
    transition: filter 0.15s ease;
}

/* Solid readable overlay (was a low-alpha wash: label measured 1.19-3.66). */
.role-peek-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    font-size: 14px;
    font-weight: 600;
    color: var(--t-ink);
    cursor: pointer;
    background: var(--t-panel-deep);
    border: 1px solid var(--t-line);
    border-radius: var(--radius-md);
    transition: opacity 0.15s ease;
}

.role-word-container.peeking .role-peek-overlay {
    opacity: 0;
    pointer-events: none;
}

.role-info-line {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 36px;
    overflow: hidden;
}

.role-info-label {
    font-size: 12px;
    color: var(--t-ink);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 48px;
    flex-shrink: 0;
}

.role-info-value {
    font-family: var(--font-display);
    /* Clamped by viewport so a long secret word truncates inside the card
       instead of widening it (measured 465px card at 320). */
    font-size: clamp(13px, 5.5vw, 20px);
    font-weight: 700;
    color: var(--warning);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.role-timer {
    height: 4px;
    background: var(--tint);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 16px;
}

.role-timer-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    width: 100%;
    transition: width 0.1s linear;
}

.role-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== PLAYING SCREEN ===== */
.playing-container {
    width: 100%;
    max-width: 1100px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    overflow-y: auto;
}

.playing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}

.playing-header h2 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
}

.turn-indicator {
    background: var(--bg-card);
    padding: 8px 20px;
    border-radius: var(--radius-md);
    font-weight: 500;
    border: 1px solid rgba(108, 92, 231, 0.2);
}

.playing-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.playing-left {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.playing-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.play-order-section h3,
.submitted-words-section h3,
.words-recap h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.play-order-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.play-order-item {
    padding: 6px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 13px;
    border: 1px solid var(--hairline);
    transition: all var(--transition);
}

.play-order-item.current {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.play-order-item.done {
    opacity: 0.5;
    text-decoration: line-through;
}

.play-order-item.disconnected {
    opacity: 0.35;
    font-style: italic;
}

.play-order-item.disconnected::after {
    content: " (offline)";
    font-size: 11px;
    opacity: 0.7;
}

.submitted-words-list,
.words-recap-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 176px;
    overflow-y: auto;
    padding-right: 4px;
}

.word-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 18px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 14px;
    border: 1px solid var(--hairline);
    transition: background 0.2s;
}

.word-item:hover {
    background: var(--tint);
}

.word-item.history {
    opacity: 0.85;
}

.round-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 8px 0 4px;
    border-bottom: 1px solid var(--hairline);
    margin-bottom: 4px;
}

.round-header.current {
    color: var(--accent-light);
    border-bottom-color: rgba(108, 92, 231, 0.2);
}

.word-item .word-player {
    color: var(--text-secondary);
    font-weight: 600;
    min-width: 90px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.word-item .word-value {
    font-weight: 700;
    color: #fff;
    font-size: 16px;
    background: linear-gradient(90deg, var(--accent-light), var(--accent-light));
}

html[data-theme="dark"] .word-item .word-value {
    background: linear-gradient(90deg, var(--accent-light) 0%, var(--accent-light) 60%, var(--accent-2) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Secret word peek box - same size for crewmate and impostor */
.secret-word-peek {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-sm);
    margin: 0 0 16px;
    cursor: default;
    user-select: none;
    width: 280px;
    height: 48px;
    box-sizing: border-box;
}

.secret-word-peek .peek-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.secret-word-peek .peek-word {
    font-size: 14px;
    font-weight: 700;
    color: transparent;
    background: var(--tint);
    border-radius: 4px;
    padding: 2px 10px;
    transition: color 0.15s, background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 120px;
    max-width: 120px;
    text-align: center;
}

.secret-word-peek:hover .peek-word {
    color: var(--accent-light);
    background: rgba(108, 92, 231, 0.15);
}

.voting-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
    /* Sticky bottom action bar so Lock In / Force Finalize never scroll out of view. */
    position: sticky;
    bottom: 0;
    z-index: 10;
    padding: 12px 4px 8px;
    background: linear-gradient(180deg, transparent, var(--bg-primary) 40%);
}

.btn-skip-active {
    border-color: var(--accent) !important;
    background: rgba(108, 92, 231, 0.2) !important;
    color: var(--accent-light) !important;
}

.btn-locked {
    background: rgba(81, 207, 102, 0.15) !important;
    border-color: var(--t-success) !important;
    color: var(--t-success) !important;
    cursor: default !important;
}

.lock-in-status {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
}

.vote-card.locked {
    border-color: rgba(81, 207, 102, 0.3);
}

.word-submit-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    border: 2px solid var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
    animation: pulseGlow 2s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 20px var(--accent-glow); }
    50% { box-shadow: 0 0 40px var(--accent-glow); }
}

.your-turn-badge {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-light);
    margin-bottom: 12px;
}

.word-input-row {
    display: flex;
    gap: 10px;
}

.word-input-row input {
    flex: 1;
}

/* ===== VOTING SCREEN ===== */
.voting-container {
    width: 100%;
    max-width: 1100px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    overflow-y: auto;
}

.voting-header {
    text-align: center;
    flex-shrink: 0;
    position: relative;
}

/* Was an inline position:absolute in the markup; moved to CSS so the
   mobile media query can flow it back into the header. */
#btn-leave-voting {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

.voting-header h2 {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.voting-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.voting-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.voting-left {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.voting-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.words-recap {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 16px;
    border: 1px solid var(--hairline);
}

.voting-players {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.vote-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
}

/* Vote cards are <button> elements (keyboard-operable); reset UA defaults. */
button.vote-card {
    font-family: inherit;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    text-align: left;
    width: 100%;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
}

button.vote-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button.vote-card:disabled {
    cursor: default;
}

.vote-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 71, 87, 0.3);
}

.vote-card.voted {
    border-color: var(--impostor-red);
    background: rgba(255, 71, 87, 0.08);
}

.vote-card.self {
    cursor: default;
    pointer-events: none;
}

.vote-card.self .vote-name,
.vote-card.self .vote-word {
    color: var(--t-muted);
}

.vote-card.disconnected {
    opacity: 0.4;
    border-style: dashed;
}

.vote-card.disconnected .vote-name::after {
    content: " (offline)";
    font-size: 11px;
    font-style: italic;
    opacity: 0.7;
}

.vote-card.self:hover {
    border-color: transparent;
    background: var(--bg-card);
    transform: none;
}

.vote-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.vote-info {
    flex: 1;
}

/* Block, so overflow/ellipsis on the lines can clip; inline spans would
   stretch past the card and collide with the vote count badge. */
.vote-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
}

.vote-word {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.vote-count {
    background: rgba(255, 71, 87, 0.15);
    color: var(--vote-red);
    font-weight: 700;
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
}

.vote-count.majority {
    /* White on the brand red measures 3.3:1; this darker red passes in both themes. */
    background: #8f1f29;
    color: #fff;
    box-shadow: 0 0 10px var(--impostor-glow);
}

/* ===== RESULTS ===== */
.results-container {
    text-align: center;
    max-width: 700px;
    width: 100%;
    padding: 20px;
}

.results-banner {
    padding: 30px;
    border-radius: var(--radius-xl);
    margin-bottom: 24px;
}

.results-banner.crewmates-win {
    background: linear-gradient(135deg, rgba(69, 170, 242, 0.15), rgba(81, 207, 102, 0.15));
    border: 2px solid var(--crewmate-blue);
    box-shadow: 0 0 40px var(--crewmate-glow);
}

.results-banner.impostors-win {
    background: linear-gradient(135deg, rgba(255, 71, 87, 0.15), rgba(255, 107, 107, 0.15));
    border: 2px solid var(--impostor-red);
    box-shadow: 0 0 40px var(--impostor-glow);
}

#results-title {
    font-family: var(--font-display);
    font-weight: 800;
    /* Clamped so the title can't force horizontal overflow at 320 (measured wide at fixed 36px). */
    font-size: clamp(24px, 4vw + 14px, 36px);
}

/* Per-theme title colors so the large 36px text clears 3:1 on the pale banner
   tint in BOTH light and dark (the raw faction colors measured 2.3:1 in light). */
.results-banner.crewmates-win #results-title {
    color: var(--results-crew);
}

.results-banner.impostors-win #results-title {
    color: var(--results-imp);
}

#results-subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    margin-top: 8px;
}

.results-word {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 24px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--hairline);
}

.results-word-label {
    color: var(--text-secondary);
    font-size: 14px;
}

.results-word-value {
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    color: var(--warning);
}

.results-players {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 28px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.result-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
}

.result-player.impostor {
    border-color: var(--impostor-red);
    background: rgba(255, 71, 87, 0.06);
}

.result-player.voted-out {
    /* 0.85 keeps the "voted out" de-emphasis while keeping name + speech
       text >= 4.5:1 in dark (0.6 composites to ~3.2:1, audit round 5). */
    opacity: 0.85;
}

.result-player.voted-out small {
    color: var(--text-primary);
}

.result-player .result-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
    font-size: 14px;
    flex-shrink: 0;
}

.result-player .result-name {
    flex: 1;
    text-align: left;
}

.result-player .result-name span {
    display: block;
    font-weight: 600;
    font-size: 14px;
}

.result-player .result-name small {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.result-role-badge {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Badge ink per theme: faction colors measured 2.4-2.9:1 on their tint at 10-11px;
   these pass 4.5:1 in both themes. */
.result-role-badge.crewmate {
    background: rgba(69, 170, 242, 0.15);
    color: var(--results-crew);
}

.result-role-badge.impostor {
    background: rgba(255, 71, 87, 0.15);
    color: var(--results-imp);
}

.result-voted-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
    background: rgba(255, 71, 87, 0.2);
    color: var(--results-imp);
}

.result-score-change {
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 100px;
    margin-left: auto;
}

.result-score-change.positive {
    color: var(--success);
    background: rgba(81, 207, 102, 0.12);
}

.result-score-change.negative {
    color: var(--danger);
    background: rgba(255, 107, 107, 0.12);
}

.result-total-score {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-light);
    min-width: 50px;
    text-align: right;
}

.results-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ===== POINTS MODE: SCOREBOARD & ROUND INFO ===== */
.results-scoreboard {
    max-width: 480px;
    margin: 0 auto 24px;
}

.results-scoreboard h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    text-align: center;
}

.scoreboard-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.scoreboard-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--hairline);
    transition: background 0.2s ease;
}

.scoreboard-row:first-child {
    border-color: var(--warning);
    background: rgba(255, 212, 59, 0.06);
}

.scoreboard-rank {
    font-size: 16px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.scoreboard-name {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
}

.scoreboard-score-change {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
}

.scoreboard-score-change.positive {
    color: var(--success);
    background: rgba(81, 207, 102, 0.12);
}

.scoreboard-score-change.negative {
    color: var(--danger);
    background: rgba(255, 107, 107, 0.12);
}

.scoreboard-score-change.zero {
    color: var(--text-muted);
    background: var(--tint);
}

.scoreboard-total {
    font-size: 16px;
    font-weight: 700;
    min-width: 36px;
    text-align: right;
    color: var(--accent-light);
}

.results-round-info {
    text-align: center;
    margin-bottom: 20px;
    padding: 12px 20px;
    background: rgba(108, 92, 231, 0.08);
    border-radius: var(--radius-md);
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.results-round-info p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 4px 0;
}

.results-round-info #results-round-progress {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
}

/* Copy link icon button in game code area */
.btn-icon-link {
    background: none;
    border: none;
    color: var(--accent-light);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    transition: color 0.15s ease, background 0.15s ease;
}

.btn-icon-link:hover {
    color: var(--accent);
    background: rgba(108, 92, 231, 0.15);
}

/* ===== TOAST ===== */
#toast-container {
    position: fixed;
    top: max(6px, calc(env(safe-area-inset-top, 0px) + 6px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: min(92vw, 420px);
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-md);
    padding: 12px 20px;
    color: var(--text-primary);
    font-size: 14px;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.25s ease, toastOut 0.3s ease 2.7s forwards;
    width: 100%;
    box-sizing: border-box;
}

.toast.error {
    border-color: var(--danger);
    background: rgba(255, 71, 87, 0.12);
}

.toast.success {
    border-color: var(--success);
    background: rgba(81, 207, 102, 0.12);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* Desktop: keep screen headers below the fixed "All games" / "Sign in" chrome. */
@media (min-width: 769px) {
    .lobby-container,
    .playing-container,
    .voting-container {
        padding-top: calc(68px + env(safe-area-inset-top, 0px));
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .games-home-link {
        top: 12px;
        left: 12px;
        padding: 7px 9px;
    }

    .playing-content,
    .voting-content {
        grid-template-columns: 1fr;
    }

    /* Lobby: stack the blocks (players / settings / start, then chat) as
       full-width, natural-height rows. The 2-col grid inside a height-bound
       container collapses its auto rows into unusable 10px slivers, so the
       page scrolls instead. */
    .lobby-content {
        display: block;
        width: 100%;
    }

    .lobby-left {
        width: 100%;
        gap: 12px;
    }

    .lobby-right {
        width: 100%;
        margin-top: 12px;
    }

    .game-title {
        font-size: 32px;
        letter-spacing: 4px;
    }

    .countdown-number {
        font-size: 100px;
    }

    .lobby-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .lobby-title-section {
        flex-wrap: wrap;
        gap: 10px;
    }

    .name-change-section {
        flex-wrap: wrap;
    }

    .timer-config {
        flex-direction: column;
        align-items: flex-start;
    }

    .playing-header h2 {
        font-size: 18px;
    }

    .voting-header h2 {
        font-size: 22px;
    }

    /* Reserve room under the floating sticky action bar so the last
       vote card / status line can scroll fully above it. */
    .voting-left {
        padding-bottom: calc(140px + env(safe-area-inset-bottom, 0px));
    }

    .lobby-container,
    .playing-container,
    .voting-container {
        padding: 12px;
        gap: 12px;
        /* Clear the fixed top chrome (All games / Sign in) + safe area. */
        padding-top: calc(52px + env(safe-area-inset-top, 0px));
    }

    .countdown-container,
    .results-container,
    .home-container {
        padding-top: calc(48px + env(safe-area-inset-top, 0px));
    }

    .lobby-right,
    .playing-right,
    .voting-right {
        min-height: 250px;
    }
}
.impostor-account-button{position:fixed;z-index:120;right:24px;top:20px;padding:9px 14px;border:1px solid var(--hairline);border-radius:999px;background:var(--chrom-bg);color:var(--text-bright);font:600 12px Inter,sans-serif;cursor:pointer;backdrop-filter:blur(10px)}
.impostor-account-dialog{display:none}
.impostor-account-dialog[open]{display:grid;place-items:center;place-content:center;position:absolute;inset:0;width:100%;height:100%;margin:0;padding:14px;border:0;background:transparent;color:var(--text-primary);overflow:auto}
.impostor-account-dialog::backdrop{background:rgba(3,4,8,.8);backdrop-filter:blur(7px)}
.impostor-account-card{position:relative;margin:auto;width:min(560px,100%);max-height:85vh;overflow:auto;padding:30px;border:1px solid var(--hairline);border-radius:20px;background:var(--t-panel);box-shadow:var(--t-shadow)}
.impostor-account-card .account-close{position:absolute;right:16px;top:12px;border:0;background:none;color:var(--text-secondary);font-size:26px;cursor:pointer}
.impostor-account-card form{display:grid;gap:10px}
.impostor-account-card input{padding:12px;border:1px solid var(--hairline);border-radius:9px;background:var(--bg-input);color:var(--text-primary)}
.impostor-account-card h2{font-family:var(--font-display);font-size:22px;font-weight:700;margin-bottom:8px}
.impostor-account-card p{color:var(--text-secondary);font-size:14px;margin-bottom:4px}
.account-tabs,.account-actions{display:flex;gap:8px;flex-wrap:wrap;margin:14px 0}
.impostor-account-card .account-actions .btn-secondary,.impostor-account-card .account-actions .btn-ghost{color:var(--text-primary)}
.account-item{display:flex;justify-content:space-between;gap:15px;padding:13px 0;border-top:1px solid var(--hairline)}
.account-item span{color:var(--text-secondary)}
.account-error{color:var(--t-danger);min-height:20px;font-size:13px}
.impostor-account-card form .google{text-decoration:none;color:var(--text-primary)}

/* ===== COUNTDOWN RING (conic depletion) + per-second pop ===== */
@property --cd-pct {
    syntax: "<number>";
    inherits: false;
    initial-value: 100;
}

.countdown-ring {
    position: relative;
    width: 250px;
    height: 250px;
    margin: 0 auto 26px;
    display: grid;
    place-items: center;
}

.countdown-ring::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(var(--accent) calc(var(--cd-pct, 100) * 1%), transparent 0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 8px), #000 calc(100% - 7px));
    transition: --cd-pct 1s linear;
}

.countdown-number.cd-pop {
    animation: cdPop 250ms ease;
}

@keyframes cdPop {
    0% { transform: scale(1); }
    40% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ===== ACTIVE TURN PULSE RING (1.2s) ===== */
.play-order-item {
    position: relative;
}

.play-order-item.current::after {
    content: "";
    position: absolute;
    inset: -5px;
    border-radius: 100px;
    border: 2px solid var(--accent);
    animation: pulseRing 1.2s ease-out infinite;
    pointer-events: none;
}

@keyframes pulseRing {
    0% { transform: scale(0.95); opacity: 0.9; }
    70% { transform: scale(1.14); opacity: 0; }
    100% { transform: scale(1.14); opacity: 0; }
}

/* ===== VOTE CARD SELECT POP + COUNT BUMP ===== */
.vote-card {
    transform: scale(1);
}

.vote-card.voted {
    transform: scale(1.02);
}

.vote-card.pop {
    animation: votePop 250ms cubic-bezier(.2, .7, .3, 1);
}

@keyframes votePop {
    0% { transform: scale(1); }
    45% { transform: scale(1.04); }
    100% { transform: scale(1.02); }
}

.vote-count {
    transition: transform 150ms ease;
}

.vote-count.bump {
    animation: countBump 200ms ease;
}

@keyframes countBump {
    0% { transform: scale(1); }
    40% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ===== LOCKED-IN CHECK POP ===== */
.btn-locked.just-locked .ic {
    animation: checkPop 200ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes checkPop {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ===== RESULTS BANNER POP ===== */
.results-banner.pop {
    animation: bannerPop 250ms cubic-bezier(.2, .7, .3, 1);
}

@keyframes bannerPop {
    from { transform: scale(0.9); opacity: 0.4; }
    to { transform: scale(1); opacity: 1; }
}

/* ===== CONFETTI ===== */
#confetti-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* ===== EMPTY LOBBY ILLUSTRATION ===== */
.lobby-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 18px 0;
    text-align: center;
}

.lobby-empty-art {
    color: var(--text-muted);
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.lobby-empty-art svg {
    width: 54px;
    height: 54px;
    display: block;
}

.lobby-empty-art .slot-empty {
    opacity: 0.55;
}

.lobby-empty .lobby-empty-label {
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
}

.lobby-empty .lobby-empty-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -8px;
}

/* ===== FACTION EMBLEMS (16px role silhouettes) ===== */
.emblem {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.emblem svg {
    width: 100%;
    height: 100%;
    display: block;
}

.result-role-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* ===== MONOLINE ICON SET ===== */
.ic {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: -2px;
}

.ic svg {
    width: 16px;
    height: 16px;
    display: block;
}

/* ===== LIGHT-THEME POLISH ===== */
html[data-theme="light"] .chat-toggle-btn:hover {
    border-color: var(--t-dim);
}

/* ===== ≤480 (320/390 phone) LAYOUT REWORK =====
   Stacks recap above vote cards in a single scroll, de-absolute's the Leave
   button, keeps the toast inside the top chrome strip (never over the h1),
   and ellipsizes every row that used to clip. Must come after the
   .impostor-account-button rule above so it wins. */
@media (max-width: 480px) {
    .games-home-link {
        top: 8px;
        left: 8px;
        padding: 5px 8px;
        font-size: 11px;
    }

    .impostor-account-button {
        top: 8px;
        right: 8px;
        padding: 5px 10px;
        font-size: 11px;
    }

    /* Toast lives in the top chrome strip (above the 52px content padding),
       so it can never cover a screen title. */
    #toast-container {
        top: 4px;
        width: calc(100% - 16px);
    }

    .toast {
        padding: 7px 12px;
        font-size: 12px;
        line-height: 1.2;
    }

    .playing-content,
    .voting-content {
        grid-template-columns: minmax(0, 1fr);
    }

    /* One scrollable area (the screen) instead of nested scrollers. */
    .playing-left,
    .voting-left {
        overflow: visible;
    }

    /* In-flow action bar: no sticky floating card over recap/list. */
    .voting-actions {
        position: static;
        justify-content: center;
    }

    .voting-left {
        padding-bottom: 8px;
    }

    #btn-leave-voting {
        position: static;
        width: auto;
        margin: 10px auto 0;
    }

    /* margin:auto keeps short screens centered and top-aligns content that
       overflows the viewport (nothing unreachable above the fold). Top chrome
       clearance already comes from the 768px block's padding-top. */
    .voting-container,
    .playing-container,
    .results-container {
        margin: auto;
    }

    .turn-indicator {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .vote-info {
        min-width: 0;
    }

    .vote-name,
    .vote-word {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .word-item {
        flex-wrap: wrap;
    }

    .word-player {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .word-value {
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Role reveal: card can't exceed viewport; long word truncates inside. */
    .role-container {
        width: 100%;
        max-width: 448px;
        margin: 0 auto;
        padding: 0 16px;
    }

    .role-card {
        padding: 28px 20px;
    }

    /* Results: fit inside 320 with wrap instead of clip. */
    .results-container {
        width: calc(100% - 16px);
        max-width: 640px;
    }

    .results-word {
        flex-wrap: wrap;
        justify-content: center;
    }

    .result-player {
        flex-wrap: wrap;
    }

    .result-name {
        min-width: 0;
        flex: 1 1 60%;
    }

    .result-name span,
    .result-name small {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Action buttons: full-width rows instead of a clipped 2-across row. */
    .results-actions {
        flex-wrap: wrap;
    }

    .results-actions > .btn {
        flex: 1 1 100%;
    }
}

