/* ===== ChatRoom App Styles ===== */
.window.chatroom-app {
    --chat-bg:#20242b;
    --chat-border:#ffffff0e;
    --chat-input-bg:#2a3039;
    --chat-text:#cbd3de;
    --chat-text-dim:#a1acba;
    --chat-accent:#b8cbe4;
    --chat-online:#a4bcad;
    --chat-mono:ui-monospace,"Cascadia Code",Consolas,monospace;
    --mica:linear-gradient(140deg,#0d1a13,#0a0d1a);
}
.window.chatroom-app > .content {
    padding:0!important;
    overflow:hidden!important;
    display:flex;
    flex-direction:column;
    background:var(--chat-bg);
    color:#e0e4eb;
    font:14px/1.5 "Segoe UI",Arial,sans-serif;
    container-type:size;
    container-name:chatroom;
    color-scheme:dark;
}
.window.chatroom-app .content button { font:inherit; cursor:pointer; -webkit-tap-highlight-color:transparent; transition:background .15s,color .15s,transform .12s; }
.window.chatroom-app .content button:disabled { cursor:default; }
.window.chatroom-app .content button:not(:disabled):active { transform:scale(.96); }
.window.chatroom-app .content button:focus-visible,#chat-messages:focus-visible { outline:2px solid var(--chat-accent); outline-offset:3px; }

/* ===== Layout and Messages ===== */
#win-chatroom { display:flex; width:100%; height:100%; min-height:0; overflow:hidden; }
#win-chatroom[aria-hidden="true"] { visibility:hidden; }
#chat-main { display:flex; flex-direction:column; flex:1; min-width:0; min-height:0; }
.chat-room-header { flex:none; min-height:59px; margin:0 28px; display:flex; align-items:center; justify-content:space-between; gap:10px; border-bottom:1px solid var(--chat-border); }
.chat-room-header h2 { margin:0; color:#e0e4eb; font-size:13px; font-weight:600; }
#chat-members-btn { display:flex; align-items:center; gap:7px; padding:8px 11px; border:1px solid var(--chat-border); border-radius:8px; background:#ffffff03; color:#bfc7d2; font-size:12px; }
#chat-members-btn:hover { background:#ffffff09; }
#chat-members-btn .bi { margin-left:3px; }
.chat-online-dot { width:6px; height:6px; flex:none; display:inline-block; border-radius:50%; background:#6ddd9b; }
#chat-messages { flex:1; min-height:0; overflow:auto; overflow-x:hidden; padding:23px 28px 12px; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:#536071 transparent; }
.chat-load-more { display:block; width:100%; text-align:center; padding:0 0 19px; margin-bottom:8px; color:var(--chat-text-dim); border:0; border-bottom:1px solid var(--chat-border); background:transparent; font-size:10px; cursor:pointer; }
.chat-load-more:hover { color:var(--chat-accent); }
.chat-msg { display:flex; align-items:flex-start; gap:12px; padding:12px 0; }
.chat-msg-avatar { width:34px; height:34px; flex:none; display:flex; align-items:center; justify-content:center; border:1px solid #c4d0e00d; border-radius:11px; background:#394553; color:#c3cddd; font-size:18px; }
/* Preserve the existing wallet mapping when the bundled icon font lacks a glyph. */
.chat-msg-avatar .bi-alien::before,.chat-online-avatar .bi-alien::before { content:"👽"; font-family:"Segoe UI Emoji","Apple Color Emoji",sans-serif!important; }
.chat-msg-avatar .bi-snowflake::before,.chat-online-avatar .bi-snowflake::before { content:"❄"; font-family:"Segoe UI Symbol","Apple Symbols",sans-serif!important; }
.chat-msg-avatar .bi-anchor::before,.chat-online-avatar .bi-anchor::before { content:"⚓"; font-family:"Segoe UI Symbol","Apple Symbols",sans-serif!important; }
.chat-msg-body { flex:1; min-width:0; }
.chat-msg-meta { display:flex; align-items:center; gap:9px; min-height:16px; margin-bottom:5px; }
.chat-msg-wallet { color:#cdd5df; font:600 11px var(--chat-mono); }
.chat-msg-time { color:#9aa6b6; font-size:10px; flex:none; }
.chat-msg-text { color:var(--chat-text); font-size:13px; line-height:1.75; white-space:pre-wrap; overflow-wrap:anywhere; user-select:text; }
.chat-msg.self-msg { padding:12px; margin:5px -12px; border:1px solid #a9bddb26; border-radius:12px; background:#a9bddb0d; }
.chat-msg.self-msg .chat-msg-wallet { color:#b9cde6; }
.chat-you-chip { display:inline-block; padding:1px 5px; border-radius:4px; background:#b9cde61a; color:#bdcfe6; font:8px/1.6 var(--chat-mono); }
.chat-system-msg { margin:8px 0; padding:10px 13px; border:1px solid #e2b2ba44; border-radius:8px; background:#a747541a; color:#efbdc4; text-align:center; font-size:12px; }

/* ===== Input and Emoji Picker ===== */
.chat-compose-wrap { position:relative; flex:none; padding:15px 28px 17px; }
#chat-input-area { padding:12px 13px 8px; border:1px solid #ffffff15; border-radius:12px; background:var(--chat-input-bg); transition:border-color .15s; }
#chat-input-area:focus-within { border-color:#adbfda66; }
#chat-input { display:block; width:100%; min-height:35px; max-height:80px; padding:0 2px 7px; margin:0; border:0; outline:none; resize:none; background:transparent; color:#e0e4eb; font:13px/1.6 "Segoe UI",Arial,sans-serif; scrollbar-width:thin; }
#chat-input::placeholder { color:var(--chat-text-dim); }
.chat-compose-tools { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.chat-compose-actions { display:flex; align-items:center; gap:9px; min-width:0; }
#chat-emoji-btn,#chat-sound-btn,#chat-close-members { display:flex; align-items:center; justify-content:center; flex:none; width:30px; height:30px; padding:0; border:0; border-radius:8px; background:transparent; color:var(--chat-text-dim); font-size:18px; }
#chat-emoji-btn:hover,#chat-sound-btn:hover,#chat-close-members:hover { background:#ffffff0d; color:#e0e4eb; }
#chat-sound-btn.muted { color:#8f9aaa; }
.chat-writing-as { color:var(--chat-text-dim); font-size:9px; }
.chat-writing-as b { color:#b4c0cf; font:9px var(--chat-mono); }
.chat-writing-as .chat-you-chip { margin-left:6px; }
#chat-send-btn { display:flex; align-items:center; gap:12px; flex:none; min-height:33px; padding:7px 11px; border:0; border-radius:7px; background:var(--chat-accent); color:#253447; font-size:11px; font-weight:650; }
#chat-send-btn:hover:not(:disabled) { background:#ccdaec; }
#chat-send-btn:disabled { background:#3a4656; color:#acb7c7; }
.chat-compose-caption { display:flex; justify-content:space-between; gap:8px; margin-top:9px; color:var(--chat-text-dim); font-size:9px; }
.chat-compose-caption kbd { color:#b7c2d0; font:inherit; }
#chat-emoji-picker { position:absolute; bottom:calc(100% - 5px); left:28px; z-index:10; display:none; grid-template-columns:repeat(6,1fr); gap:3px; width:260px; max-height:min(260px,max(38px,calc(100cqh - 220px))); overflow-y:auto; overscroll-behavior:contain; padding:12px; border:1px solid #ffffff1d; border-radius:12px; background:#303945; box-shadow:0 12px 35px #0005; scrollbar-width:thin; scrollbar-color:#536071 transparent; }
#chat-emoji-picker.open { display:grid; }
#chat-emoji-picker button { display:flex; align-items:center; justify-content:center; width:35px; height:35px; padding:0; border:0; border-radius:7px; background:none; font-size:21px; line-height:1; }
#chat-emoji-picker button:hover { background:#ffffff0d; }

/* ===== Online Members ===== */
#chat-online-panel { display:flex; flex-direction:column; flex:none; width:258px; min-height:0; padding:25px 23px 17px; border-left:1px solid var(--chat-border); background:#1c2027; }
#chat-online-header { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:12px; color:#bfc7d2; font-size:11px; }
#chat-online-count { padding:2px 6px; border-radius:4px; background:#bdcadb14; color:#bdcadb; font:10px var(--chat-mono); }
#chat-online-list { flex:1; min-height:0; overflow:auto; scrollbar-width:thin; scrollbar-color:#536071 transparent; }
.chat-online-user { display:flex; align-items:center; gap:10px; padding:8px 0; }
.chat-online-avatar { position:relative; display:flex; align-items:center; justify-content:center; width:29px; height:29px; flex:none; border-radius:9px; background:#394553; color:#c3cddd; font-size:15px; }
.chat-online-avatar::after { content:""; position:absolute; bottom:-2px; right:-2px; width:7px; height:7px; border:2px solid #1c2027; border-radius:50%; background:var(--chat-online); }
.chat-online-addr { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#bfc7d2; font:10px var(--chat-mono); }
.chat-online-user .chat-you-chip { margin-left:auto; }
.chat-room-note { display:flex; align-items:flex-start; gap:8px; flex:none; margin:24px 0 0; color:var(--chat-text-dim); font-size:10px; line-height:1.7; }
.chat-room-note .bi { margin-top:2px; }
#chat-members-dialog { width:min(390px,calc(100% - 32px)); max-height:calc(100dvh - 40px); margin:auto; overflow:auto; padding:25px; border:1px solid #ffffff20; border-radius:17px; background:#272e38; color:#e0e4eb; box-shadow:0 25px 90px #0006; scrollbar-width:thin; }
#chat-members-dialog::backdrop { background:#0e1219cc; backdrop-filter:blur(5px); }
.chat-members-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:15px; }
.chat-members-heading h2 { margin:0; font-size:20px; font-weight:550; }

/* ===== Wallet Gate ===== */
#chat-login-overlay { display:none; position:absolute; inset:0; z-index:20; overflow:auto; align-items:center; justify-content:safe center; flex-direction:column; padding:24px 24px 65px; background:radial-gradient(ellipse at 50% 23%,#56677e18,transparent 60%),var(--chat-bg); text-align:center; }
#chat-login-overlay.visible { display:flex; }
.chat-gate-art { position:relative; display:flex; align-items:center; justify-content:center; flex:none; width:240px; height:154px; }
.chat-orbit { position:absolute; border:1px solid #aebed119; border-radius:50%; transform:rotate(-24deg); }
.chat-orbit-one { width:236px; height:115px; }
.chat-orbit-two { width:164px; height:150px; border-style:dashed; transform:rotate(32deg); }
.chat-gate-icon { position:relative; width:77px; height:77px; }
.chat-gate-icon img { display:block; width:77px; height:77px; object-fit:contain; }
.chat-art-lock { position:absolute; right:-12px; bottom:-9px; display:flex; align-items:center; justify-content:center; width:34px; height:34px; border:4px solid #232932; border-radius:11px; background:#48576a; color:#e0e6ef; font-size:17px; transform:rotate(9deg); }
.chat-art-dot { position:absolute; right:9px; top:40px; width:7px; height:7px; border-radius:50%; background:#b5c8df; }
.chat-art-star { position:absolute; left:20px; top:13px; color:#b9ab9e; font-size:21px; }
.chat-eyebrow { margin-top:12px; color:#aebfd5; font:9px/1.6 var(--chat-mono); letter-spacing:1.8px; }
#chat-login-overlay h2 { margin:14px 0 18px; color:#e0e4eb; font-size:clamp(28px,4cqw,43px); line-height:1.15; font-weight:550; letter-spacing:-1.2px; }
#chat-login-overlay .chat-gate-description { margin:0 0 25px; color:var(--chat-text-dim); font-size:13px; line-height:1.8; }
#chat-login-btn { display:flex; align-items:center; justify-content:center; flex:none; min-width:144px; min-height:38px; padding:7px 20px; border:1px solid #d4c4ec; border-radius:4px; background:#c3b1df; color:#282331; text-align:center; font-size:12px; font-weight:650; transition:transform .18s ease,box-shadow .18s ease; }
#chat-login-btn:hover { transform:translateY(-2px); box-shadow:0 6px 18px #c3b1df33; }
#chat-login-overlay .chat-gate-footnote { margin:17px 0 0; color:var(--chat-text-dim); font-size:10px; }
.chat-gate-bottom { position:absolute; left:28px; right:28px; bottom:23px; display:flex; justify-content:space-between; gap:12px; color:#98a4b4; font:9px var(--chat-mono); }
.chat-gate-bottom span:first-child { letter-spacing:1.5px; }

/* ===== Adapt to the actual app window, not the desktop viewport ===== */
@container chatroom (max-width:900px) {
    #chat-online-panel { width:225px; padding-left:18px; padding-right:18px; }
    .chat-room-header { margin-left:22px; margin-right:22px; }
    #chat-messages { padding-left:22px; padding-right:22px; }
    .chat-compose-wrap { padding-left:22px; padding-right:22px; }
    #chat-emoji-picker { left:22px; }
}
@container chatroom (max-width:760px) {
    #chat-online-panel { display:none; }
}
@container chatroom (max-width:480px) {
    .chat-room-header { min-height:52px; margin:0 18px; }
    #chat-members-btn { padding:8px; gap:6px; font-size:11px; }
    #chat-members-btn .bi { display:none; }
    #chat-messages { padding:18px 18px 8px; }
    .chat-msg { gap:10px; padding-top:11px; padding-bottom:11px; }
    .chat-msg-text { font-size:14px; }
    .chat-compose-wrap { padding:12px 14px 13px; }
    #chat-input-area { padding:12px 10px 8px; }
    #chat-input { font-size:16px; }
    .chat-writing-as,.chat-writing-as b { font-size:8px; }
    .chat-writing-as .chat-you-chip { margin-left:3px; }
    #chat-emoji-picker { left:14px; }
    .chat-newline-hint { display:none; }
    #chat-login-overlay { padding-left:16px; padding-right:16px; }
    #chat-login-overlay .chat-gate-description { font-size:12px; }
    .chat-gate-bottom { left:20px; right:20px; font-size:8px; }
}
@container chatroom (max-height:560px) {
    #chat-login-overlay { padding-bottom:25px; }
    .chat-gate-art { height:110px; transform:scale(.8); margin-top:-10px; margin-bottom:-8px; }
    .chat-eyebrow { margin-top:0; }
    #chat-login-overlay h2 { margin:10px 0 12px; font-size:31px; }
    #chat-login-overlay .chat-gate-description { margin-bottom:17px; }
    .chat-gate-bottom { display:none; }
}
@container chatroom (max-height:420px) {
    .chat-gate-art { display:none; }
    #chat-login-overlay { padding-top:24px; padding-bottom:24px; }
    #chat-login-overlay h2 { font-size:28px; }
    .chat-compose-wrap { padding-top:8px; padding-bottom:10px; }
}
@media(prefers-reduced-motion:reduce) {
    .window.chatroom-app .content button { transition:none!important; }
    #chat-login-btn:hover { transform:none; }
}
