:root {
    --background: #f7f8fb;
    --foreground: #17171f;
    --card: #ffffff;
    --card-foreground: #17171f;
    --muted: #eef0f4;
    --muted-foreground: #687083;
    --primary: #fe2c55;
    --primary-foreground: #ffffff;
    --secondary: #111827;
    --secondary-foreground: #ffffff;
    --accent: #2563eb;
    --success: #15803d;
    --success-bg: #ecfdf3;
    --destructive: #dc2626;
    --border: #dfe3ea;
    --input: #d6dbe4;
    --ring: rgba(254, 44, 85, 0.22);
    --radius: 8px;
    --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 8px 22px rgba(17, 24, 39, 0.07);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--background);
    color: var(--foreground);
    font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
}

#app {
    min-height: 100vh;
}

.app-shell {
    width: min(1480px, 100%);
    min-height: 100vh;
    margin: 0 auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.app-shell.review-page {
    height: auto;
}

.app-header,
.header-actions,
.state-row,
.stats-strip,
.toolbar,
.section-heading,
.stream-panel-header,
.stream-panel-actions {
    display: flex;
    align-items: center;
}

.app-header {
    justify-content: space-between;
    gap: 18px;
}

.app-header h1 {
    margin: 0;
    font-size: clamp(1.5rem, 2.2vw, 2rem);
    line-height: 1.1;
    letter-spacing: 0;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted-foreground);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.header-actions,
.stats-strip,
.toolbar {
    gap: 8px;
    flex-wrap: wrap;
}

.control-bar {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 320px) auto auto auto;
    gap: 10px;
    align-items: center;
}

.control-copy {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.control-copy span,
.muted {
    color: var(--muted-foreground);
}

.username-input {
    width: 100%;
}

.state-row {
    min-height: 34px;
    justify-content: space-between;
    gap: 10px;
}

.status-text {
    margin: 0;
    color: var(--muted-foreground);
    font-size: 0.9rem;
}

.stream-grid {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
}

.stream-panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
}

.stream-panel-header {
    min-height: 48px;
    padding: 10px 12px;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.stream-panel-header h2,
.section-heading h2 {
    margin: 0;
    font-size: 0.86rem;
    color: var(--muted-foreground);
    font-weight: 800;
    text-transform: uppercase;
}

.stream-panel-actions {
    gap: 6px;
}

.stream-panel-body {
    min-height: 0;
    flex: 1;
}

.message-feed {
    height: 100%;
    overflow-y: auto;
    padding: 8px;
    scrollbar-width: thin;
    scrollbar-color: #c8ced8 transparent;
}

.chat-row,
.gift-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 8px;
    border-radius: 7px;
    font-size: 0.92rem;
}

.chat-row:hover,
.gift-row:hover {
    background: #f5f7fa;
}

.chat-row p,
.gift-body p {
    min-width: 0;
    margin: 0;
}

.chat-row {
    gap: 10px;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
}

.gift-avatar {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
}

.chat-body {
    min-width: 0;
    flex: 1 1 auto;
    display: grid;
    align-content: center;
}

.chat-author {
    display: flex;
    align-items: baseline;
    gap: 5px;
    min-width: 0;
    margin-right: 0;
    line-height: 1.08;
}

.chat-nickname,
.chat-message {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-nickname {
    font-size: 0.94rem;
}

.chat-username {
    color: var(--muted-foreground);
    font-size: 0.73rem;
    font-weight: 600;
    white-space: nowrap;
}

.chat-message {
    margin-top: 4px;
    font-size: 1.04rem;
    line-height: 1.22;
}

.chat-stickers {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    overflow: hidden;
}

.chat-sticker {
    width: 29px;
    height: 29px;
    flex: 0 0 auto;
    object-fit: contain;
}

.usernamelink {
    margin-right: 5px;
    color: var(--foreground);
    font-weight: 700;
    text-decoration: none;
}

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

.chat-author.usernamelink {
    margin-right: 0;
}

.userhandle {
    margin-left: 5px;
    color: var(--muted-foreground);
    font-size: 0.86em;
    font-weight: 600;
}

.avatar,
.miniprofilepicture {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    border-radius: 999px;
    object-fit: cover;
    background: var(--muted);
}

.gift-body {
    min-width: 0;
}

.gift-detail {
    display: grid;
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 10px;
    margin-top: 5px;
    color: var(--muted-foreground);
    font-size: 0.86rem;
}

.gift-detail strong {
    color: var(--foreground);
}

.gift-detail .pending {
    color: var(--destructive);
}

.gifticon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    object-fit: contain;
    background: var(--muted);
}

.ui-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--card-foreground);
    box-shadow: var(--shadow);
    padding: 12px;
}

.ui-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 7px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.ui-button:focus-visible,
.ui-input:focus,
.ui-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
    border-color: var(--primary);
}

.ui-button:disabled,
.ui-button[aria-disabled="true"] {
    opacity: 0.52;
    cursor: not-allowed;
}

.ui-button-md {
    min-height: 38px;
    padding: 0 14px;
    font-size: 0.9rem;
}

.ui-button-sm {
    min-height: 32px;
    padding: 0 10px;
    font-size: 0.84rem;
}

.ui-button-icon {
    width: 32px;
    height: 32px;
    padding: 0;
}

.ui-button-default {
    background: var(--primary);
    color: var(--primary-foreground);
}

.ui-button-default:hover {
    background: #e0264c;
}

.ui-button-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.ui-button-secondary:hover {
    background: #253044;
}

.ui-button-outline {
    border-color: var(--border);
    background: var(--card);
    color: var(--foreground);
}

.ui-button-outline:hover,
.ui-button-ghost:hover {
    background: var(--muted);
}

.ui-button-ghost {
    background: transparent;
    color: var(--foreground);
}

.ui-button-destructive {
    background: var(--destructive);
    color: #fff;
}

.ui-input,
.ui-select {
    min-height: 38px;
    border: 1px solid var(--input);
    border-radius: 7px;
    background: #fff;
    color: var(--foreground);
    padding: 0 11px;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.ui-input:disabled {
    opacity: 0.62;
    cursor: not-allowed;
}

.ui-select {
    min-width: 150px;
}

.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.ui-badge-default {
    background: var(--primary);
    color: #fff;
}

.ui-badge-secondary {
    background: var(--muted);
    color: var(--foreground);
}

.ui-badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #b7ebc6;
}

.ui-badge-outline {
    background: #fff;
    color: var(--muted-foreground);
    border: 1px solid var(--border);
}

.ui-badge strong {
    color: var(--foreground);
}

.ui-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.ui-switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.ui-switch-track {
    position: relative;
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: #cbd5e1;
    transition: background 150ms ease;
}

.ui-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    background: #fff;
    transition: transform 150ms ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.ui-switch input:checked + .ui-switch-track {
    background: var(--primary);
}

.ui-switch input:checked + .ui-switch-track .ui-switch-thumb {
    transform: translateX(14px);
}

.ui-switch-label {
    color: var(--muted-foreground);
    font-size: 0.9rem;
}

.review-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-heading {
    justify-content: space-between;
    gap: 10px;
}

.review-grid {
    display: grid;
    grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
    gap: 14px;
    align-items: start;
}

.tablewrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted-foreground);
    font-size: 0.76rem;
    text-transform: uppercase;
}

td span,
.errorcell {
    color: var(--muted-foreground);
}

.empty-table {
    color: var(--muted-foreground);
    text-align: center;
}

.session-list,
.event-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-row,
.event-row {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.session-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    color: var(--foreground);
    cursor: pointer;
    text-align: left;
}

.session-row.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

.event-row {
    padding: 11px 12px;
}

.event-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted-foreground);
    font-size: 0.82rem;
}

.event-summary {
    margin: 7px 0;
}

.event-row pre {
    max-height: 280px;
    overflow-x: auto;
    white-space: pre-wrap;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #f8fafc;
    padding: 9px;
}

.empty-state,
.error-banner {
    border-radius: var(--radius);
    padding: 14px;
}

.empty-state {
    border: 1px dashed var(--border);
    color: var(--muted-foreground);
    background: #fff;
}

.error-banner {
    border: 1px solid #fecaca;
    color: #991b1b;
    background: #fef2f2;
}

.captcha-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    background: rgba(9, 12, 19, 0.52);
}

.captcha-overlay.active {
    display: flex;
}

.captcha-box {
    border-radius: 12px;
    background: #fff;
    padding: 24px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.26);
}

.spin {
    animation: spin 900ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* OBS overlay */
body.obs-overlay {
    width: 100%;
    height: 100vh;
    min-width: 0;
    overflow: hidden;
    padding: 0;
    background: rgb(24, 23, 28);
    color: rgb(227, 229, 235);
}

body.obs-overlay #app,
.obs-vue-root {
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.obs-vue-root {
    --text-secondary: rgba(227, 229, 235, 0.6);
    --link: rgb(102, 143, 217);
}

.obs-shell {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-columns: minmax(280px, 42vw) 1fr;
    gap: 16px;
    padding: 58px 16px 16px;
    pointer-events: none;
}

.obs-topbar {
    position: fixed;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 7;
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 30px;
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(8, 10, 17, 0.72);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(8px);
    pointer-events: none;
}

.obs-chat-panel {
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    pointer-events: auto;
}

.obs-chat-feed {
    overflow-y: hidden;
    word-wrap: break-word;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, black 9%, black 100%);
    mask-image: linear-gradient(to bottom, transparent 0, black 9%, black 100%);
}

.obs-chat-feed > article {
    display: flex;
    align-items: stretch;
    gap: 10px;
    max-width: 100%;
    margin-top: 6px;
    padding: 8px 10px;
    border-left: 2px solid rgba(102, 143, 217, 0.82);
    border-radius: 8px;
    background: rgba(7, 10, 16, 0.68);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.obs-chat-feed > article > span {
    min-width: 0;
}

.obs-chat-avatar {
    width: 3.45em;
    height: 3.45em;
    flex: 0 0 3.45em;
}

.obs-chat-body {
    align-content: center;
}

.obs-chat-body .chat-nickname {
    color: rgb(227, 229, 235);
    font-size: 0.95em;
}

.obs-chat-body .chat-username {
    color: rgba(227, 229, 235, 0.58);
    font-size: 0.72em;
}

.obs-chat-body .chat-message {
    font-size: 1.12em;
    line-height: 1.16;
}

.obs-chat-body .chat-sticker {
    width: 1.7em;
    height: 1.7em;
}

.toast-stack {
    position: fixed;
    right: 16px;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(360px, 34vw);
    pointer-events: none;
}

.gift-toast-stack {
    top: 62px;
}

.like-toast-stack {
    bottom: 16px;
    justify-content: flex-end;
}

.obs-toast {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 9px;
    align-items: center;
    min-height: 50px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    color: rgb(227, 229, 235);
    background: rgba(8, 10, 17, 0.78);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(8px);
    animation: toastIn 180ms ease-out;
    transition: opacity 420ms ease, transform 420ms ease;
}

.obs-toast.is-fading {
    opacity: 0;
    transform: translateX(18px);
}

.obs-toast-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.08);
}

.obs-toast-avatar.obs-chat-avatar,
.obs-gift-toast .obs-toast-avatar,
.obs-like-toast .obs-toast-avatar {
    width: 3.45em;
    height: 3.45em;
    flex: 0 0 3.45em;
}

.obs-toast-body {
    min-width: 0;
}

.obs-toast-title,
.obs-toast-meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.obs-toast-title {
    font-weight: 700;
}

.obs-toast-meta {
    color: var(--text-secondary);
    font-size: 0.82em;
}

.obs-gift-toast {
    grid-template-columns: 3.45em minmax(0, 1fr) 42px;
    border-color: rgba(255, 211, 105, 0.28);
}

.obs-like-toast {
    grid-template-columns: 3.45em minmax(0, 1fr);
    border-color: rgba(255, 62, 108, 0.3);
}

.obs-toast-gift-icon {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.08);
}

.obs-status {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: var(--text-secondary);
    font-family: inherit;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.obs-stats {
    margin-left: auto;
    color: var(--text-secondary);
    font-size: 0.85em;
    white-space: nowrap;
}

.obs-stats b {
    color: rgb(227, 229, 235);
    margin-right: 14px;
}

.obs-overlay .usernamelink {
    color: rgb(102, 143, 217);
}

.obs-overlay .userhandle {
    color: rgba(227, 229, 235, 0.58);
}

.obs-overlay ::-webkit-scrollbar {
    width: 0;
    height: 0;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(16px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Legacy classes kept for old scripts or cached overlays. */
.eventcontainer {
    display: none;
}

.chatcontainer,
.giftcontainer {
    overflow-y: auto;
}

.chatcontainer > div,
.giftcontainer > div {
    padding: 4px 8px 5px 8px;
    border-radius: 6px;
    line-height: 1.5;
    font-size: 0.88rem;
}

.giftcontainer table {
    font-size: 0.85rem;
    color: var(--muted-foreground);
}

@media (max-width: 960px) {
    .app-shell {
        padding: 16px;
    }

    .control-bar {
        grid-template-columns: 1fr;
    }

    .stream-grid,
    .review-grid {
        grid-template-columns: 1fr;
    }

    .stream-grid {
        min-height: 720px;
    }

    .state-row,
    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .session-row {
        grid-template-columns: 1fr;
    }

    .obs-shell {
        grid-template-columns: 1fr;
        padding: 54px 12px 12px;
    }

    .obs-topbar {
        top: 12px;
        left: 12px;
        right: 12px;
        min-height: 30px;
    }

    .toast-stack {
        right: 12px;
        width: min(320px, calc(100vw - 24px));
    }

    .gift-toast-stack {
        top: 58px;
    }

    .like-toast-stack {
        bottom: 12px;
    }
}

@media (max-width: 560px) {
    .app-shell {
        padding: 12px;
    }

    .toolbar,
    .header-actions,
    .stats-strip {
        width: 100%;
    }

    .toolbar > *,
    .header-actions > *,
    .stats-strip > * {
        flex: 1 1 auto;
    }
}
