.arcanechat {
    --arcanechat-accent: #9a68c7;
    margin: 0 0 20px;
    border: 1px solid color-mix(in srgb, var(--arcanechat-accent) 55%, #34313d);
    border-radius: 8px;
    overflow: hidden;
    color: #e8e3ef;
    background: #0c1019;
    box-shadow:
        0 0 28px color-mix(in srgb, var(--arcanechat-accent) 18%, transparent),
        inset 0 1px color-mix(in srgb, var(--arcanechat-accent) 12%, transparent);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.arcanechat-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--arcanechat-accent) 36%, #302f39);
    background:
        radial-gradient(circle at 78% 0%, color-mix(in srgb, var(--arcanechat-accent) 16%, transparent), transparent 35%),
        linear-gradient(90deg, color-mix(in srgb, var(--arcanechat-accent) 13%, #14131c), color-mix(in srgb, var(--arcanechat-accent) 22%, #171522) 55%, #111521);
}

.arcanechat-heading h2 {
    margin: 0;
    color: color-mix(in srgb, var(--arcanechat-accent) 62%, #ffffff);
    font-size: 18px;
}

.arcanechat-heading span {
    color: #aaa0b7;
    font-size: 12px;
}

.arcanechat-heading-actions {
    display: flex;
    align-items: center;
    gap: 9px;
}

.arcanechat.is-collapsed .arcanechat-heading {
    border-bottom: 0;
}

.arcanechat.is-collapsed .arcanechat-body {
    display: none;
}

.arcanechat.is-collapsed .arcanechat-clear {
    display: none;
}

.arcanechat-room-tabs {
    display: flex;
    align-items: center;
    gap: 7px;
    overflow-x: auto;
    padding: 9px 14px;
    border-bottom: 1px solid color-mix(in srgb, var(--arcanechat-accent) 25%, #34303e);
    background: linear-gradient(90deg, color-mix(in srgb, var(--arcanechat-accent) 6%, #11141d), #11141d 65%);
    scrollbar-width: thin;
}

.arcanechat-room-tab {
    flex: 0 0 auto;
    border: 1px solid color-mix(in srgb, var(--arcanechat-room-color, #9a68c7) 62%, #393240);
    border-radius: 999px;
    padding: 5px 12px;
    color: #bcb3c7;
    background: #161923;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.arcanechat-room-tab:hover {
    border-color: var(--arcanechat-room-color, #9a68c7);
    color: #f0e6f7;
}

.arcanechat-room-tab.is-active {
    border-color: var(--arcanechat-room-color, #9a68c7);
    color: #ffffff;
    background: color-mix(in srgb, var(--arcanechat-room-color, #9a68c7) 25%, #161923);
    box-shadow: 0 0 10px color-mix(in srgb, var(--arcanechat-room-color, #9a68c7) 24%, transparent);
    font-weight: 700;
}

.arcanechat-clear,
.arcanechat-collapse,
.arcanechat-action,
.arcanechat-cancel-edit {
    border: 0;
    padding: 3px 5px;
    color: #b9afc5;
    background: transparent;
    cursor: pointer;
    font: inherit;
}

.arcanechat-clear,
.arcanechat-collapse {
    padding: 5px 9px;
    border: 1px solid #58455f;
    border-radius: 5px;
    color: #d9bedf;
    font-size: 11px;
}

.arcanechat-clear:hover,
.arcanechat-collapse:hover,
.arcanechat-action:hover,
.arcanechat-cancel-edit:hover {
    color: #f2d9ff;
    text-decoration: underline;
}

.arcanechat-clear:hover,
.arcanechat-collapse:hover {
    border-color: var(--arcanechat-accent);
    text-decoration: none;
    background: color-mix(in srgb, var(--arcanechat-accent) 18%, transparent);
}

.arcanechat-notice,
.arcanechat-error {
    margin: 12px;
    padding: 10px 12px;
    border: 1px solid #76536b;
    border-radius: 5px;
    color: #ffd7ec;
    background: #251521;
}

.arcanechat-messages {
    min-height: 210px;
    max-height: 390px;
    overflow-y: auto;
    padding: 10px 14px;
    background:
        radial-gradient(circle at 85% 10%, color-mix(in srgb, var(--arcanechat-accent) 13%, transparent), transparent 36%),
        radial-gradient(circle at 10% 85%, color-mix(in srgb, var(--arcanechat-accent) 6%, transparent), transparent 28%),
        #0d111a;
}

.arcanechat-load-earlier-wrap {
    display: flex;
    justify-content: center;
    padding: 3px 0 8px;
}

.arcanechat-load-earlier {
    border: 1px solid #50425f;
    border-radius: 999px;
    padding: 5px 12px;
    color: #cbb8db;
    background: #171522;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
}

.arcanechat-load-earlier:hover {
    border-color: var(--arcanechat-accent);
    color: #f2ddff;
    background: color-mix(in srgb, var(--arcanechat-accent) 18%, #171522);
}

.arcanechat-load-earlier:disabled {
    cursor: wait;
    opacity: 0.65;
}

.arcanechat-message {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 11px;
    padding: 11px 4px;
    border-bottom: 1px solid #292d39;
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

.arcanechat-message.has-grouped-followup {
    padding-bottom: 4px;
    border-bottom-color: transparent;
}

.arcanechat-message.is-grouped {
    padding-top: 4px;
    padding-bottom: 7px;
}

.arcanechat-message.is-grouped .arcanechat-message-content {
    grid-column: 2;
}

.arcanechat-message.is-grouped .arcanechat-message-meta {
    margin-bottom: 1px;
}

.arcanechat-message.is-grouped .arcanechat-time {
    font-size: 10px;
}

.arcanechat-message.is-reply-highlighted {
    background: color-mix(in srgb, var(--arcanechat-accent) 18%, transparent);
    box-shadow: inset 3px 0 var(--arcanechat-accent);
}

.arcanechat-message:last-child {
    border-bottom: 0;
}

.arcanechat-avatar {
    width: 44px;
    height: 44px;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--arcanechat-accent) 58%, #4f5360);
    border-radius: 7px;
    background: #171b25;
}

a.arcanechat-avatar {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

a.arcanechat-avatar:hover,
a.arcanechat-avatar:focus {
    border-color: color-mix(in srgb, var(--arcanechat-accent) 68%, #ffffff);
    outline: 0;
    box-shadow: 0 0 9px color-mix(in srgb, var(--arcanechat-accent) 38%, transparent);
}

.arcanechat-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.arcanechat-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e2c4ff;
    background: #30223e;
    font-size: 20px;
    font-weight: 700;
}

.arcanechat-message-content {
    min-width: 0;
}

.arcanechat-message-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 7px;
    margin-bottom: 3px;
}

.arcanechat-message-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.arcanechat-message:hover .arcanechat-message-actions,
.arcanechat-message:focus-within .arcanechat-message-actions {
    opacity: 1;
}

.arcanechat-action {
    color: #91869d;
    font-size: 11px;
}

.arcanechat-delete:hover {
    color: #ff9eb7;
}

.arcanechat .arcanechat-character-name {
    color: color-mix(in srgb, var(--arcanechat-accent) 62%, #ffffff);
    font-size: 14px;
}

a.arcanechat-character-name {
    text-decoration: none;
}

.arcanechat a.arcanechat-character-name:hover,
.arcanechat a.arcanechat-character-name:focus {
    color: color-mix(in srgb, var(--arcanechat-accent) 35%, #ffffff);
    text-decoration: underline;
}

.arcanechat-universe {
    padding: 1px 6px;
    border-radius: 999px;
    color: #bdc8d6;
    background: #222936;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.arcanechat-time {
    margin-left: auto;
    color: #777f8d;
    font-size: 11px;
}

.arcanechat-message-body {
    color: #d8dce5;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.arcanechat-action-text {
    display: block;
    color: #cbbbd8;
    font-style: italic;
}

.arcanechat-reply-reference {
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin: 3px 0 6px;
    overflow: hidden;
    border: 0;
    border-left: 3px solid color-mix(in srgb, var(--arcanechat-accent) 70%, #4b4354);
    border-radius: 0 5px 5px 0;
    padding: 5px 8px;
    color: #a9a0b5;
    background: color-mix(in srgb, var(--arcanechat-accent) 12%, transparent);
    cursor: pointer;
    text-align: left;
    font: inherit;
}

.arcanechat-reply-reference:hover,
.arcanechat-reply-reference:focus {
    border-left-color: color-mix(in srgb, var(--arcanechat-accent) 65%, #ffffff);
    outline: 0;
    background: color-mix(in srgb, var(--arcanechat-accent) 20%, transparent);
}

.arcanechat-reply-reference strong,
.arcanechat-reply-reference span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.arcanechat-reply-reference strong {
    color: color-mix(in srgb, var(--arcanechat-accent) 58%, #ffffff);
    font-size: 11px;
}

.arcanechat-reply-reference span {
    margin-top: 1px;
    font-size: 11px;
}

.arcanechat-inline-editor {
    box-sizing: border-box;
    width: 100%;
    min-height: 68px;
    border: 1px solid color-mix(in srgb, var(--arcanechat-accent) 68%, #4b4d58);
    border-radius: 5px;
    padding: 8px 9px;
    color: #ece7f2;
    background: #090d14;
    resize: vertical;
}

.arcanechat-inline-editor:focus {
    outline: 1px solid color-mix(in srgb, var(--arcanechat-accent) 42%, transparent);
}

.arcanechat-edit-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.arcanechat-save-edit {
    padding: 4px 12px;
}

.arcanechat-cancel-edit {
    font-size: 11px;
}

.arcanechat-loading,
.arcanechat-empty {
    display: flex;
    min-height: 190px;
    align-items: center;
    justify-content: center;
    color: #81798c;
    font-style: italic;
}

.arcanechat-composer {
    display: grid;
    grid-template-columns: minmax(145px, 220px) minmax(0, 1fr) auto;
    grid-template-areas:
        "character-label message-label message-label"
        "character message send"
        "status status status";
    gap: 5px 10px;
    padding: 12px 14px;
    border-top: 1px solid color-mix(in srgb, var(--arcanechat-accent) 27%, #35303e);
    background: #121620;
}

.arcanechat-composer label {
    color: #a9a0b3;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.arcanechat-composer label[for="arcanechat-character"] {
    grid-area: character-label;
}

.arcanechat-message-label {
    grid-area: message-label;
}

#arcanechat-character {
    grid-area: character;
}

#arcanechat-message {
    display: block;
    resize: vertical;
}

.arcanechat-message-wrap {
    grid-area: message;
    min-width: 0;
}

.arcanechat-formatting {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 5px;
}

.arcanechat-format {
    min-width: 29px;
    border: 1px solid #494153;
    border-radius: 4px;
    padding: 3px 7px;
    color: #cbb7d8;
    background: #171521;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
}

.arcanechat-format:hover,
.arcanechat-format:focus {
    border-color: var(--arcanechat-accent);
    outline: 0;
    color: #f0d9ff;
    background: color-mix(in srgb, var(--arcanechat-accent) 18%, #171521);
}

.arcanechat-format-action {
    min-width: 52px;
    font-style: italic;
}

.arcanechat-reply-composer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
    border-left: 3px solid var(--arcanechat-accent);
    border-radius: 0 5px 5px 0;
    padding: 6px 8px;
    color: #aaa1b6;
    background: color-mix(in srgb, var(--arcanechat-accent) 14%, transparent);
    font-size: 11px;
}

.arcanechat-reply-composer[hidden] {
    display: none;
}

.arcanechat-reply-composer > div {
    min-width: 0;
}

.arcanechat-reply-composer strong,
.arcanechat-reply-composer span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.arcanechat-reply-composer strong {
    color: color-mix(in srgb, var(--arcanechat-accent) 58%, #ffffff);
}

#arcanechat-cancel-reply {
    flex: 0 0 auto;
    border: 0;
    padding: 2px 5px;
    color: #bcaac7;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

#arcanechat-cancel-reply:hover,
#arcanechat-cancel-reply:focus {
    outline: 0;
    color: #ffffff;
}

.arcanechat-composer select,
.arcanechat-composer textarea {
    box-sizing: border-box;
    width: 100%;
    border: 1px solid #444a59;
    border-radius: 5px;
    padding: 8px 9px;
    color: #ece7f2;
    background: #0b0f17;
}

.arcanechat-smilie-control {
    position: relative;
    display: flex;
    justify-content: flex-start;
    margin-top: 5px;
}

.arcanechat-smilie-toggle {
    border: 1px solid #494153;
    border-radius: 5px;
    padding: 4px 9px;
    color: #cbb7d8;
    background: #171521;
    cursor: pointer;
    font: inherit;
    font-size: 11px;
}

.arcanechat-smilie-toggle:hover,
.arcanechat-smilie-toggle[aria-expanded="true"] {
    border-color: var(--arcanechat-accent);
    color: #f0d9ff;
    background: color-mix(in srgb, var(--arcanechat-accent) 18%, #171521);
}

.arcanechat-smilie-picker {
    position: absolute;
    z-index: 50;
    bottom: calc(100% + 6px);
    left: 0;
    display: grid;
    grid-template-columns: repeat(6, minmax(34px, 1fr));
    gap: 4px;
    width: max-content;
    max-width: min(320px, 75vw);
    max-height: 210px;
    overflow-y: auto;
    border: 1px solid color-mix(in srgb, var(--arcanechat-accent) 58%, #47434f);
    border-radius: 7px;
    padding: 8px;
    background: #11131c;
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.48);
}

.arcanechat-smilie-picker[hidden] {
    display: none;
}

.arcanechat-smilie {
    display: flex;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 5px;
    padding: 3px;
    background: transparent;
    cursor: pointer;
}

.arcanechat-smilie:hover,
.arcanechat-smilie:focus {
    border-color: var(--arcanechat-accent);
    outline: 0;
    background: color-mix(in srgb, var(--arcanechat-accent) 20%, #1b1b24);
}

.arcanechat-smilie img {
    max-width: 28px;
    max-height: 28px;
}

.arcanechat-message-body img.smilie {
    max-width: 32px;
    max-height: 32px;
    vertical-align: middle;
}

.arcanechat-composer select:focus,
.arcanechat-composer textarea:focus {
    border-color: var(--arcanechat-accent);
    outline: 1px solid color-mix(in srgb, var(--arcanechat-accent) 38%, transparent);
}

.arcanechat-send {
    grid-area: send;
    align-self: stretch;
    min-width: 78px;
    border-color: color-mix(in srgb, var(--arcanechat-accent) 55%, #4a4352);
    background: linear-gradient(180deg, color-mix(in srgb, var(--arcanechat-accent) 17%, #241d2b), #1a1720);
}

.arcanechat-send:hover,
.arcanechat-send:focus {
    border-color: var(--arcanechat-accent);
    outline: 0;
    background: linear-gradient(180deg, color-mix(in srgb, var(--arcanechat-accent) 28%, #241d2b), #211925);
}

.arcanechat-status {
    grid-area: status;
    min-height: 16px;
    color: #9ab6a4;
    font-size: 11px;
}

.arcanechat-status.is-error {
    color: #ff9eb7;
}

@media (max-width: 700px) {
    .arcanechat-composer {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "character-label character-label"
            "character character"
            "message-label message-label"
            "message send"
            "status status";
    }

    .arcanechat-heading span {
        display: none;
    }

    .arcanechat-heading {
        align-items: flex-start;
    }

    .arcanechat-message-actions {
        opacity: 1;
    }

    .arcanechat-time {
        width: 100%;
        margin-left: 0;
    }
}


/* Guest read-only mode */
.arcanechat[data-read-only="1"] .arcanechat-composer {
    display: none;
}


/* OOC Lounge: member identity replaces the character selector. */
.arcanechat-member-identity {
    grid-area: character;
    display: flex;
    align-items: center;
    align-self: start;
    height: 39px;
    box-sizing: border-box;
    border: 1px solid color-mix(in srgb, var(--arcanechat-accent) 50%, #444a59);
    border-radius: 5px;
    padding: 8px 11px;
    color: #ece7f2;
    background: #0b0f17;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.arcanechat-member-identity[hidden],
#arcanechat-character[hidden],
.arcanechat-notice[hidden] {
    display: none !important;
}


/* v0.8.3 — small, non-intrusive unread counts for each room and the header. */
.arcanechat-room-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.arcanechat-unread-count {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    color: #101723;
    background: #93d5ed;
    font-size: 10px;
    line-height: 1;
    font-weight: 700;
}

.arcanechat-total-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: 23px;
    padding: 3px 8px;
    border-radius: 999px;
    color: #0e1a25;
    background: #93d5ed;
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    white-space: nowrap;
}

.arcanechat-unread-count[hidden],
.arcanechat-total-unread[hidden] {
    display: none !important;
}

/* Keep the unread indicator visible on phones even when the subtitle is hidden. */
@media (max-width: 700px) {
    .arcanechat-heading .arcanechat-total-unread:not([hidden]) {
        display: inline-flex;
    }
}
