:root {
    --bg: #0c0c0c;
    --panel: #161616;
    --pink: #ff0080;
    --text: #f3f3f3;
    --muted: #999;
    --safe: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: #ff8ac4; }
.join-page { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 1rem; }
.join-card { width: 100%; max-width: 420px; background: var(--panel); padding: 1.25rem; border-radius: 12px; }
.join-card input, .staff-box input {
    width: 100%; padding: 0.75rem; margin: 0.4rem 0; font-size: 1rem;
    border-radius: 8px; border: 1px solid #333; background: #111; color: #fff;
}
.btn, .btn-call, .btn-call-sm {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0.6rem 1rem; border: 0; border-radius: 8px;
    background: var(--pink); color: #fff; font-size: 1rem; cursor: pointer; text-decoration: none;
}
.btn { width: 100%; margin-top: 0.5rem; }
.muted, .tiny { color: var(--muted); font-size: 0.9rem; }
.tiny { font-size: 0.8rem; }
.err { color: #f88; }
.check { display: flex; align-items: center; gap: 0.5rem; min-height: 44px; }
.staff-box { margin-top: 1.5rem; }
.room-page { display: flex; flex-direction: column; height: 100%; position: relative; overflow: hidden; }
.topbar {
    display: flex; gap: 0.5rem; padding: 0.5rem;
    background: #111; border-bottom: 1px solid #333; align-items: center;
}
.tabs { display: flex; flex: 1; gap: 0.35rem; }
.tab {
    flex: 1; min-height: 44px; border: 0; border-radius: 8px;
    background: #222; color: #fff; font-size: 1rem; cursor: pointer;
}
.tab.active { background: var(--pink); }
.btn-call-sm { flex: 0 0 auto; padding: 0 0.9rem; }
.layout { display: flex; flex: 1; min-height: 0; }
.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.welcome { margin: 0.5rem 1rem; color: var(--muted); font-size: 0.9rem; }
.msg .ip, .side .ip {
    display: inline-block; font-size: 0.75rem; color: #7d7; font-weight: 400;
    font-family: ui-monospace, monospace; margin-left: 0.25rem;
}
.msg .ip { display: inline; margin-right: 0.35rem; }
.msg .ip.ip-warn, .side .ip.ip-warn { color: #f44; font-weight: 700; }
/* Staff pref: hide IPs in the message thread only (Online list unchanged). */
.room-page.hide-chat-ips .msg .ip { display: none !important; }
.sound-btn.ips-off { background: #333; color: #aaa; }
.btn-grant, .btn-kick, .btn-mute, .btn-limit, .btn-unlimit {
    display: inline-block; width: auto; margin: 0 0 0 0.25rem; min-height: 28px;
    padding: 0 0.45rem; border: 0; border-radius: 6px; color: #fff;
    cursor: pointer; font-size: 0.7rem; vertical-align: middle;
}
.btn-grant { background: #064; }
.btn-mute { background: #553; }
.btn-kick { background: #622; }
.btn-limit { background: #1a3a5c; }
.btn-unlimit { background: #1a4a3a; }
.btn-grant:disabled { opacity: 0.6; cursor: default; }
.btn-pm {
    display: inline-block; margin: 0 0.15rem 0 0; min-height: 28px; padding: 0 0.45rem;
    border: 0; border-radius: 6px; background: #334; color: #fff; cursor: pointer; font-size: 0.7rem;
}
#pm-open { flex-shrink: 0; }
#pm-badge {
    display: inline-block; background: #fff; color: #c06; border-radius: 10px;
    padding: 0 0.4rem; margin-left: 0.25rem; font-size: 0.75rem; min-width: 1.2em;
    text-align: center; font-weight: 700;
}
#pm-badge[hidden] { display: none !important; }
.msg-time {
    font-size: 0.7rem; color: #777; font-weight: 400; margin-left: 0.25rem; white-space: nowrap;
}
.msg-body a.msg-link { color: #8cf; text-decoration: underline; word-break: break-all; }
.sound-btn {
    min-height: 44px; padding: 0 0.7rem; border: 0; border-radius: 8px;
    background: #223; color: #cde; cursor: pointer; font-size: 0.8rem; width: auto; flex: 0 0 auto;
}
.sound-btn.is-muted { background: #432; color: #fcc; }
.sound-btn.alerts-off { background: #333; color: #aaa; }
.pm-panel {
    position: fixed;
    top: 56px;
    left: 8px;
    right: auto;
    bottom: auto;
    width: min(380px, calc(100% - 16px));
    height: min(70vh, 560px);
    z-index: 80;
    max-height: calc(100vh - 64px);
    background: #121212;
    display: flex;
    flex-direction: column;
    border: 1px solid #333;
    border-radius: 10px;
    box-shadow: 6px 8px 28px rgba(0,0,0,.55);
}
/* Desktop only: drag already works; allow corner-resize without touching mobile sheet. */
@media (min-width: 721px) {
    .pm-panel {
        resize: both;
        overflow: auto;
        min-width: 300px;
        min-height: 280px;
        max-width: calc(100vw - 16px);
        max-height: calc(100vh - 24px);
    }
    .pm-panel::after {
        content: '';
        position: absolute;
        right: 2px;
        bottom: 2px;
        width: 14px;
        height: 14px;
        pointer-events: none;
        background:
            linear-gradient(135deg, transparent 50%, #555 50%, #555 60%, transparent 60%),
            linear-gradient(135deg, transparent 68%, #555 68%, #555 78%, transparent 78%);
        opacity: 0.7;
    }
}
.pm-panel[hidden] { display: none !important; }
.pm-panel.is-dragging { opacity: 0.92; user-select: none; }
.pm-head {
    display: flex; gap: 0.35rem; align-items: center; padding: 0.35rem 0.4rem;
    background: #1a1a1a; cursor: move; touch-action: none; flex-shrink: 0;
}
.pm-nav {
    min-height: 40px; padding: 0 0.7rem; border: 0; border-radius: 8px;
    background: #333; color: #fff; cursor: pointer;
}
.pm-head strong, .pm-title { flex: 1; font-size: 0.9rem; cursor: move; }
.pm-drag-hint { color: #666; font-size: 0.85rem; padding: 0 0.2rem; cursor: move; }
.pm-hint { margin: 0 0.75rem 0.5rem; }
.pm-inbox { list-style: none; margin: 0; padding: 0.5rem; overflow-y: auto; flex: 1; }
.pm-inbox li { padding: 0.6rem; border-bottom: 1px solid #333; cursor: pointer; min-height: 44px; }
.pm-inbox .pm-ignore-btn {
    float: right; min-height: 28px; padding: 0 0.45rem; border: 0; border-radius: 6px;
    background: #333; color: #ccc; font-size: 0.7rem; cursor: pointer;
}
.pm-thread-bar {
    display: flex; gap: 0.35rem; flex-wrap: wrap; padding: 0.35rem 0.5rem;
    border-bottom: 1px solid #333; background: #161616;
}
.pm-thread-bar[hidden] { display: none !important; }
.pm-thread-bar button {
    min-height: 32px; padding: 0 0.55rem; border: 0; border-radius: 6px;
    background: #333; color: #ddd; font-size: 0.75rem; cursor: pointer;
}
.pm-msgs { flex: 1; min-height: 120px; }
.pm-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#pm-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#pm-chat[hidden] { display: none !important; }
.msg.mine .nick { color: #8c8; }
.staff-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    background: #e33; margin-left: 0.3rem; vertical-align: middle;
    box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}
.btn-dot {
    display: inline-block; margin: 0 0.15rem 0 0; min-height: 28px; min-width: 28px;
    padding: 0 0.4rem; border: 0; border-radius: 6px; background: #2a2a2a;
    color: #888; cursor: pointer; font-size: 0.85rem; line-height: 1; vertical-align: middle;
}
.btn-dot.on { color: #e33; }
.side li { margin: 0 0 0.3rem; padding-bottom: 0.25rem; border-bottom: 1px solid #222; }
.vip-gate { margin: 1rem; padding: 1rem; background: #2a1a00; border-radius: 8px; line-height: 1.45; }
.messages { flex: 1; overflow-y: auto; padding: 0.75rem; }
.msg { margin: 0 0 0.65rem; line-height: 1.35; }
.msg .nick { font-weight: 700; color: var(--pink); cursor: pointer; }
.msg .nick.operator { color: #6cf; }
.msg .nick.mod, .msg .nick.admin { color: #fc6; }
.msg .nick.vip { color: #ffd166; }
.vip-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #ffd166;
    vertical-align: middle;
}
.msg img { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; margin-top: 0.3rem; cursor: pointer; }
.msg .del { margin-left: 0.4rem; font-size: 0.75rem; color: #f88; background: none; border: 0; cursor: pointer; }
.composer {
    display: flex; gap: 0.4rem; padding: 0.5rem;
    padding-bottom: calc(0.5rem + var(--safe));
    background: #111; border-top: 1px solid #333;
}
.spy-btn {
    background: #1a2a1a; border: 1px solid #3a5a3a; color: #cfc; font-size: 0.78rem;
    cursor: pointer; padding: 0 0.65rem; min-height: 36px; border-radius: 8px;
    font-weight: 600; white-space: nowrap;
}
.spy-btn.on {
    background: #4a2a00; border-color: #a60; color: #ffd;
    box-shadow: 0 0 0 1px rgba(255, 160, 0, 0.35);
}
.spy-banner {
    background: #4a2a00; color: #ffd; font-size: 0.85rem; font-weight: 600;
    padding: 0.45rem 0.75rem; border-bottom: 1px solid #a60; text-align: center;
}
.spy-banner[hidden] { display: none !important; }
.fmt-bar {
    display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center;
    padding: 0.35rem 0.5rem 0; background: #111;
}
.fmt-btn, .fmt-lbl select, .fmt-lbl input[type=color] {
    min-height: 40px; border-radius: 8px; border: 1px solid #333; background: #222; color: #fff;
}
.fmt-btn { min-width: 44px; cursor: pointer; font-size: 1.2rem; }
.fmt-lbl { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: #aaa; }
.fmt-lbl input[type=color] { width: 44px; padding: 0; border: 0; }
.emoji-pop {
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 220px;
    overflow: hidden;
    padding: 0.4rem;
    background: #1a1a1a;
    border-top: 1px solid #333;
}
.emoji-pop.open {
    display: flex;
    position: fixed;
    left: 8px;
    right: auto;
    bottom: 72px;
    z-index: 86;
    width: min(420px, calc(100% - 16px));
    border: 1px solid #333;
    border-radius: 8px;
}
.emoji-pop[hidden] { display: none !important; }
.emoji-pop-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0 0.15rem 0.25rem;
    border-bottom: 1px solid #333;
    flex: 0 0 auto;
}
.emoji-pop-head span { font-size: 0.8rem; color: #aaa; }
.emoji-close {
    min-width: 40px; min-height: 40px; border: 0; background: #2a2a2a;
    color: #fff; font-size: 1.4rem; line-height: 1; border-radius: 8px; cursor: pointer;
}
.emoji-pop-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem;
    overflow-y: auto;
    max-height: 168px;
    -webkit-overflow-scrolling: touch;
}
.emoji-pop button.em {
    min-width: 40px; min-height: 40px; border: 0; background: transparent;
    font-size: 1.25rem; cursor: pointer;
}
.msg-body.size-sm { font-size: 0.85rem; }
.msg-body.size-md { font-size: 1rem; }
.msg-body.size-lg { font-size: 1.3rem; }
.op img.av { width: 36px; height: 36px; object-fit: cover; border-radius: 8px; display: block; margin: 0; flex-shrink: 0; cursor: pointer; }
.composer input[type=text] {
    flex: 1; min-height: 44px; border-radius: 8px; border: 1px solid #333;
    background: #1a1a1a; color: #fff; padding: 0 0.75rem; font-size: 16px;
}
.composer .btn { width: auto; margin: 0; min-width: 72px; }
.composer .fmt-btn { width: auto; margin: 0; flex: 0 0 auto; }
.pic-btn {
    min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
    background: #222; border-radius: 8px; cursor: pointer;
}
.pic-btn.no-perm { opacity: 0.7; }
.upload-info {
    position: absolute; inset: 0; z-index: 88; background: rgba(0,0,0,.65);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.upload-info[hidden] { display: none !important; }
.upload-info-card {
    max-width: 420px; background: #1a1408; border: 1px solid #664; border-radius: 12px;
    padding: 1.1rem 1.2rem; line-height: 1.45;
}
.upload-info-card p { margin: 0 0 0.75rem; }
.upload-info-card .btn { width: auto; min-width: 88px; margin: 0.25rem 0 0; }
.side {
    width: 250px; border-left: 1px solid #333; padding: 0.5rem 0.55rem;
    overflow: hidden; background: #101010;
    display: flex; flex-direction: column; min-height: 0;
}
.side-lists { flex: 1; overflow-y: auto; min-height: 0; }
.side-foot { flex-shrink: 0; border-top: 1px solid #333; padding-top: 0.4rem; margin-top: 0.35rem; }
.busy-btn {
    min-height: 44px; padding: 0 0.7rem; border: 0; border-radius: 8px;
    background: #164; color: #cfc; cursor: pointer; font-size: 0.8rem; width: auto; flex: 0 0 auto;
}
.side h2 { font-size: 0.75rem; margin: 0.35rem 0 0.25rem; color: var(--muted); text-transform: uppercase; }
.side ul { list-style: none; padding: 0; margin: 0 0 0.4rem; }
.op { display: flex; gap: 0.4rem; align-items: flex-start; margin: 0 0 0.4rem; font-size: 0.85rem; }
.op-meta { flex: 1; min-width: 0; }
.op-meta strong { display: block; line-height: 1.2; }
.op-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem; margin-top: 0.15rem; }
.op-links a {
    display: inline-flex; align-items: center; min-height: 28px; padding: 0 0.4rem;
    font-size: 0.7rem; text-decoration: none;
}
.img-lightbox {
    position: absolute; inset: 0; z-index: 90; background: rgba(0,0,0,.8);
    display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1rem;
}
.img-lightbox[hidden] { display: none !important; }
.img-lightbox .pm-nav { margin-bottom: 0.6rem; width: auto; align-self: flex-end; }
.img-lightbox img { max-width: 96%; max-height: 82vh; object-fit: contain; border-radius: 8px; }
.busy-btn.is-busy { background: #642; color: #fcc; }
.op.is-busy { opacity: 0.7; }
.busy-pill { font-size: 0.65rem; color: #fa8; font-weight: 700; margin-left: 0.25rem; }
.muted-pill { font-size: 0.65rem; color: #c88; margin-left: 0.25rem; }
@media (max-width: 720px) {
    .layout { flex-direction: column; }
    .side { width: 100%; border-left: 0; border-top: 1px solid #333; max-height: 32vh; }
    .pm-panel {
        top: auto !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 52% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        max-width: none !important;
        max-height: none !important;
        resize: none !important;
        overflow: hidden;
        border-radius: 10px 10px 0 0;
    }
    .pm-panel::after { display: none !important; }
    .pm-head { cursor: default; }
    .pm-drag-hint { display: none; }
}

/* Quota / daily-limit UI */
.limited-pill {
    display: inline-block;
    background: #c00;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0 0.35rem;
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 0.2rem;
}
.btn-limit {
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    background: #555;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 0.2rem;
}
.btn-unlimit {
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    background: #c00;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 0.2rem;
}
