:root {
  color-scheme: light;
  font: 16px/1.45 "72", "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --shell: #1d2d3e;
  --ink: #1d2d3e;
  --muted: #475e75;
  --line: #d5dce3;
  --surface: #fff;
  --canvas: #f5f7f9;
  --blue: #0070f2;
  --action: #0064d9;
  --hover: #0054b5;
  --selected: #e5f1ff;
  --negative: #aa0808;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; height: 100vh; height: 100dvh; min-width: 280px;
  display: flex; flex-direction: column;
}
h1,h2,h3,p { margin: 0; }
button,input { font: inherit; }
button { cursor: pointer; color: inherit; border: 0; background: none; border-radius: 6px; }
button:disabled { cursor: default; }
button:focus-visible,input:focus-visible,[contenteditable]:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 3px;
}
button:active:not(:disabled) { transform: translateY(1px); }
.mast {
  height: 52px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(16px,3.2vw,48px); background: var(--shell); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 650; letter-spacing: -.035em; white-space: nowrap; }
.mark { position: relative; width: 26px; height: 23px; background: #76c1ff; border-radius: 7px 7px 7px 2px; }
.mark::before,.mark::after {
  content: ""; position: absolute; left: 6px; right: 6px; top: 7px; height: 2px; border-radius: 2px; background: var(--shell);
}
.mark::after { top: 13px; right: 10px; }
#account { display: flex; align-items: center; gap: 16px; min-width: 0; margin-left: 12px; }
#identity { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e1ebf3; font-size: .85rem; }
#sign-out { font-size: .82rem; color: white; border: 1px solid #718497; padding: 4px 12px; min-height: 30px; white-space: nowrap; }
.mast button:focus-visible { outline-color: #a6dafa; }

#welcome { flex: 1; display: grid; place-items: center; padding: 32px 20px; overflow: auto; }
.welcome-card {
  width: 100%; max-width: 850px; display: grid; grid-template-columns: .8fr 1.2fr;
  overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 6px 22px rgba(34,53,72,.09);
}
.cover {
  position: relative; display: grid; place-items: center; min-height: 390px;
  isolation: isolate; overflow: hidden; background: #e4effb; border-inline-end: 1px solid #d9e5f2;
}
.pattern {
  position: absolute; inset: 0; z-index: -1;
  background-image: radial-gradient(#9eb9d4 1px,transparent 1px); background-size: 15px 15px; opacity: .52;
}
.bubbles { position: relative; width: 68%; max-width: 225px; aspect-ratio: 1.27; }
.bubbles span {
  position: absolute; display: grid; align-content: center; gap: 8px; padding-inline: 12%;
  width: 77%; height: 61%; right: 0; bottom: 6%; background: var(--surface);
  border: 1px solid #c5d4e2; border-radius: 12px 12px 2px 12px;
  box-shadow: 0 5px 12px #14345614;
}
.bubbles span:first-child::before,.bubbles span:first-child::after {
  content: ""; height: 5px; border-radius: 9px; width: 85%; margin-inline-start: auto; background: #c9d8e7;
}
.bubbles span:first-child::after { width: 54%; }
.bubbles span+span {
  width: 60%; height: 50%; top: 3%; left: 0; padding: 0; gap: 8%;
  display: flex; align-items: center; justify-content: center;
  background: var(--action); border: 0; border-radius: 12px 12px 12px 2px;
}
.bubbles i { width: 8%; aspect-ratio: 1; border-radius: 50%; background: #fff; }
.entry { padding: 36px clamp(24px,4.5vw,58px) 38px; }
.entry h1 { margin: 0 0 8px; font-size: clamp(28px,3vw,39px); line-height: 1.12; font-weight: 630; letter-spacing: -.045em; }
.entry>p { color: var(--muted); font-size: .94rem; }
form { margin-top: 23px; }
label { display: block; font-size: .86rem; font-weight: 600; }
input:not([type=file]) {
  display: block; width: 100%; min-height: 42px; margin: 5px 0 13px; padding: 8px 11px;
  background: var(--surface); color: var(--ink); border: 1px solid #8293a5; border-radius: 6px;
}
input::placeholder { color: #587086; font-weight: 400; }
.primary { background: var(--action); color: white; font-weight: 650; }
#login-submit { min-height: 42px; width: 100%; margin-top: 3px; }
.error,#compose-status { color: var(--negative); font-size: .84rem; }
.error:not(:empty) { margin-top: 10px; }

#workspace {
  display: grid; grid-template-columns: clamp(230px,26vw,350px) minmax(0,1fr); width: 100%; max-width: 1600px;
  flex: 1; min-height: 0; align-self: center; background: var(--surface); border-inline: 1px solid var(--line);
}
.inbox { overflow: auto; min-width: 0; padding: 20px 10px; background: var(--surface); border-inline-end: 1px solid var(--line); }
.inbox header { display: flex; align-items: center; gap: 9px; margin: 0 10px 16px; }
.inbox h1 { font-size: 1.35rem; letter-spacing: -.035em; font-weight: 650; }
#room-count { font-size: .74rem; font-weight: 650; padding: 2px 8px; border-radius: 16px; background: #edf1f5; color: #384f63; }
.hint { color: var(--muted); font-size: .88rem; padding-inline: 10px; }
.room {
  display: flex; align-items: center; gap: 10px; text-align: left;
  width: 100%; max-width: 100%; min-height: 54px; padding: 8px 10px; margin-bottom: 2px;
}
.room[aria-current=true] { background: var(--selected); box-shadow: inset 3px 0 var(--blue); }
.room-name,.room-meta { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-name { font-size: .92rem; font-weight: 640; line-height: 1.35; }
.room-meta { color: var(--muted); font-size: .78rem; }
.room-desc { min-width: 0; }
.avatar { flex: none; width: 35px; height: 35px; display: grid; place-items: center; border-radius: 9px; background: #e1ebf5; color: #254a6e; font-weight: 650; font-size: .8rem; }
.room[aria-current=true] .avatar { color: #004790; background: #cce3ff; }
#personal-nav { padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.bookmark::before { content: ""; width: 12px; height: 16px; background: #385675; clip-path: polygon(0 0,100% 0,100% 100%,50% 73%,0 100%); }
#thread-avatar.bookmark::before { background: #fff; }
#rooms-error:not(:empty) { margin: 6px 8px; }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head {
  display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 65px;
  padding: 10px clamp(14px,3vw,44px); border-bottom: 1px solid var(--line);
}
.thread-heading { min-width: 0; flex: 1; }
.thread-head h2 { font-size: 1.04rem; letter-spacing: -.02em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#thread-avatar { width: 36px; height: 36px; color: white; background: #27587e; }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .76rem; }
#status-light { width: 7px; height: 7px; border-radius: 50%; background: #a15b00; }
#status-light.ready { background: #18864b; }
#back-rooms { display: none; font-size: .86rem; color: var(--action); padding: 7px 6px; }
#back-rooms span { font-size: 1.25rem; vertical-align: -.06em; line-height: 1; }

.history {
  flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; display: flex; flex-direction: column;
  padding: 20px clamp(15px,3vw,44px); background: var(--canvas);
}
.empty-thread { margin: auto; text-align: center; max-width: 320px; }
.empty-thread h3 { font-size: 1.14rem; letter-spacing: -.02em; }
.empty-thread p { font-size: .89rem; color: var(--muted); margin-top: 5px; }
.mini-bubble {
  display: inline-block; padding: 3px 7px 5px 10px; margin-bottom: 12px; border-radius: 9px 9px 9px 2px;
  background: var(--selected); color: #0057ac; font-size: 1.55rem; line-height: 1; letter-spacing: .1em;
}
.message { display: flex; flex-direction: column; align-items: flex-start; margin-block: 0 14px; min-width: 0; }
.message.own { align-items: flex-end; }
.bubble {
  min-width: 0; max-width: min(88%,640px); overflow: hidden; padding: 9px 13px;
  border: 1px solid var(--line); border-radius: 11px 11px 11px 3px; background: var(--surface);
}
.own .bubble { background: #e5f1ff; border-color: #bed8f3; border-radius: 11px 11px 3px 11px; }
.meta { font-size: .72rem; color: #52677a; margin: 4px 2px 0; }
.rich { overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45; min-width: 0; }
.rich p,.rich h1,.rich h2,.rich h3,.rich h4,.rich h5,.rich h6 { margin: 0 0 .25em; line-height: 1.3; }
.rich p:last-child { margin-bottom: 0; }
.rich a { color: #0054b5; text-decoration: underline; }
.rich ul,.rich ol { padding-inline-start: 1.65em; margin: .2em 0; }
.rich blockquote { border-inline-start: 3px solid #8ea7bf; margin: .3em 0; padding-inline-start: .65em; }
.rich pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.rich table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; white-space: normal; }
.rich td,.rich th { border: 1px solid #99aabd; padding: 3px 7px; }
.image-preview { display: block; max-width: 100%; width: auto; max-height: 270px; object-fit: contain; border-radius: 6px; margin-block: 6px; }
.attachment-download {
  display: block; max-width: 100%; overflow-wrap: anywhere; text-align: left; margin-top: 4px;
  padding: 6px 10px; background: #fff; border: 1px solid #b5cedf; color: #0054a5; font-size: .85rem; font-weight: 550;
}
.compose { background: var(--surface); border-top: 1px solid var(--line); padding: 12px clamp(12px,3vw,44px); }
#composer-box { border: 1px solid #99aaba; border-radius: 8px; padding: 7px 9px 6px; }
#composer-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
#editor { min-height: 42px; max-height: min(24vh,180px); overflow: auto; padding: 3px 4px; outline: none; }
#editor:empty::before { content: attr(data-placeholder); color: #587086; pointer-events: none; }
#pending-file { display: flex; align-items: center; gap: 8px; width: fit-content; max-width: 100%; background: #e9f3ff; border: 1px solid #c8ddf6; border-radius: 5px; padding: 2px 6px; }
#pending-name { font-size: .83rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tools,.editor-tools { display: flex; align-items: center; }
.tools { justify-content: space-between; gap: 8px; margin-top: 4px; }
.editor-tools { gap: 2px; }
.editor-tools button,#remove-file { width: 32px; height: 32px; color: #38536a; border-radius: 5px; }
.editor-tools button[aria-pressed=true] { background: var(--selected); color: #004d9c; }
.clip { position: relative; display: inline-block; width: 12px; height: 20px; border: 1.8px solid currentColor; border-radius: 7px; transform: rotate(36deg); vertical-align: middle; }
.clip::after { content: ""; position: absolute; left: 2px; right: 2px; top: -2px; height: 13px; border: 1.5px solid currentColor; border-top: 0; border-radius: 0 0 4px 4px; background: var(--surface); }
.divider { height: 17px; border-inline-start: 1px solid var(--line); margin: 0 4px; }
#send { min-height: 32px; padding: 5px 13px; white-space: nowrap; font-size: .86rem; }
.primary:disabled { background: #dae2e9; color: #506477; }
#compose-status:not(:empty) { margin: 5px 2px 0; }
dialog { color: var(--ink); background: var(--surface); width: min(370px,90vw); border: 1px solid var(--line); border-radius: 12px; padding: 24px; box-shadow: 0 14px 45px #152c4950; }
dialog::backdrop { background: #14243699; }
dialog h2 { font-size: 1.3rem; }
dialog p { margin: 9px 0 19px; color: var(--muted); font-size: .95rem; }
dialog div { display: flex; justify-content: flex-end; gap: 8px; }
dialog button { padding: 7px 12px; }

@media (hover:hover) {
  button:not(:disabled):hover { background-color: #edf2f7; }
  .primary:not(:disabled):hover { background-color: var(--hover); }
  .mast button:not(:disabled):hover { background-color: #354b61; }
  .room[aria-current=true]:hover { background-color: #d8eaff; }
  .attachment-download:not(:disabled):hover { border-color: var(--blue); background: #f3f8ff; }
}
@media (max-width:680px) {
  .mast { height: 48px; }
  .brand { font-size: 17px; gap: 8px; }
  #identity { display: none; }
  #welcome { padding: 14px; }
  .welcome-card { max-width: 440px; grid-template-columns: 1fr; }
  .cover { min-height: 98px; height: 14vh; max-height: 128px; border: 0; border-bottom: 1px solid #d9e5f2; }
  .bubbles { width: 126px; }
  .entry { padding: 22px; }

  #workspace { display: flex; border: 0; }
  .inbox,.thread { width: 100%; }
  #workspace[data-pane=thread] .inbox,#workspace[data-pane=rooms] .thread { display: none; }
  #back-rooms { display: block; }
  .thread-head { min-height: 58px; padding-block: 8px; }
  .history { padding-block: 14px; }
  .compose { padding-bottom: max(10px,env(safe-area-inset-bottom)); }
  .bubble { max-width: 92%; }
  .room { min-height: 54px; }
}
@media (max-height:500px) {
  .mast { height: 44px; }
  #welcome { display: block; }
  .welcome-card { margin: 0 auto; }
  .cover { min-height: 0; }
  .entry { padding-block: 14px; }
  .entry form { margin-top: 12px; }
}

#refresh-rooms { margin-inline-start: auto; padding: 2px; width: 32px; height: 32px; font-size: 1.2rem; color: var(--action); }
.room-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 5px 14px; }
.room-actions button,#invite-person { color: var(--action); border: 1px solid #b7cce1; font-size: .82rem; font-weight: 600; padding: 6px 9px; }
#invite-person { flex: none; }
#channel-dialog form { margin: 0; }
#channel-dialog label { margin-top: 14px; }
#channel-dialog .error:not(:empty) { margin-block: 6px 14px; }
#channel-notice:not(:empty) { margin: 0; padding: 7px 16px; background: #e9f6ee; color: #215b36; font-size: .85rem; }
#rooms-error:not(:empty) { padding: 4px; }
#channel-error:empty,#channel-notice:empty { display: none; }

#storage-panel { margin: 24px 7px 0; padding: 14px 4px; border-top: 1px solid var(--line); }
#storage-title { margin-bottom: 4px; font-size: .88rem; }
#storage-usage,#storage-feedback { font-size: .8rem; color: var(--muted); }
#storage-feedback:not(:empty) { margin-top: 6px; }
#storage-meter { display: block; width: 100%; height: 7px; margin: 8px 0; accent-color: var(--action); }
#clear-storage,#cancel-upload { color: var(--action); padding: 5px 4px; font-size: .8rem; font-weight: 600; }
.storage-banner { flex: none; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 7px 14px; background: #fff3d6; color: #624000; border-bottom: 1px solid #e1bc65; font-size: .85rem; }
#go-storage { flex: none; color: #674000; text-decoration: underline; font-weight: 600; }
#storage-dialog { width: min(440px,92vw); }
#storage-dialog .danger { background: #aa0808; color: white; font-weight: 600; }
#storage-dialog .danger:not(:disabled):hover { background: #870606; }
#clear-error:not(:empty) { color: var(--negative); }
#clear-error:empty { display: none; }
