:root {
  --blue: #38b6ff; --indigo: #5271ff; --gray: #ebebeb;
  /* 文字の大きさ(Discordと同じくらい)。全体を大きく/小さくしたいときはここを変える */
  --fs-msg: 18px;   /* メッセージ・入力欄 */
  --fs-ui: 16px;    /* 一覧・ボタン・ヘッダー */
  --fs-sm: 13px;    /* 時刻・補足 */
  --icon-msg: 40px; /* メッセージのアイコン */
  --icon-list: 32px;/* 一覧のアイコン */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; background: #fff; color: #333; font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif; font-size: var(--fs-ui); }
button, input, textarea, select { font: inherit; color: inherit; }
button, select { cursor: pointer; background: #fff; border: 1px solid #ccc; border-radius: 8px; padding: 4px 10px; }
input:not([type=file]):not([type=color]):not([type=checkbox]) { border: 2px solid var(--blue); border-radius: 8px; padding: 8px 10px; width: 100%; }
.outline { border: 2px solid var(--blue); color: var(--blue); }
.danger { border: 2px solid #ff3333; color: #ff3333; }
.error { color: #ff3333; min-height: 1.4em; font-size: 14px; }

#login { height: 100%; display: grid; place-items: center; }
#loginForm { width: min(90vw, 340px); display: grid; gap: 12px; text-align: center; }
#loginForm h1 { color: var(--blue); font-weight: 400; }
#modeBtn { border: 0; color: var(--indigo); text-decoration: underline; }

#app { display: flex; height: 100vh; height: 100dvh; }
#sidebar { width: 280px; flex: none; border-right: 2px solid var(--blue); display: flex; flex-direction: column; }
#addFriendBtn, #addGroupBtn { margin: 8px 8px 0; font-size: var(--fs-ui); padding: 3px 8px; }
#addGroupBtn { margin-top: 6px; margin-bottom: 8px; }
#list { flex: 1; overflow-y: auto; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; border-radius: 0; padding: 6px 12px; text-align: left; margin-bottom: 2px; }
.item.active { background: var(--gray); }
.name { font-weight: 700; font-size: var(--fs-ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.badge { margin-left: auto; background: #ff3333; color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 7px; }
.incall { margin-left: auto; color: var(--indigo); font-size: 12px; white-space: nowrap; }
#meBtn { display: flex; align-items: center; gap: 10px; border: 0; border-top: 1px solid var(--gray); border-radius: 0; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); text-align: left; min-width: 0; }

.icon { width: var(--icon-list); height: var(--icon-list); aspect-ratio: 1; object-fit: cover; flex: none; background: #c9d1da; display: grid; place-items: center; font-size: 8px; white-space: nowrap; overflow: hidden; color: #000; }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#header { display: flex; align-items: center; gap: 10px; padding: 4px 12px; border-bottom: 2px solid var(--blue); min-height: 48px; }
#title { color: var(--blue); font-size: var(--fs-ui); white-space: nowrap; flex: none; }
#callBtn { margin-left: auto; color: var(--indigo); font-size: var(--fs-ui); flex: none; padding: 3px 12px; white-space: nowrap; }
#partner { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 45%; }
#partner .icon { width: 28px; height: 28px; }
#partner button { white-space: nowrap; }
#partner .unfriend { font-size: 13px; padding: 2px 8px; flex: none; }
#backBtn { display: none; border: 0; font-size: 30px; color: var(--blue); padding: 0 6px; }

/* ---- メッセージ(連続した同じ人の発言は、アイコンと名前をまとめる) ---- */
#messages { flex: 1; overflow-y: auto; padding: 8px 0 12px; min-height: 0; }
.msg { display: flex; align-items: flex-start; gap: 14px; padding: 2px 16px; margin-top: 14px; position: relative; }
.msg.cont { margin-top: 0; }
.msg:hover { background: #f7f7f8; }
.msg .icon { width: var(--icon-msg); height: var(--icon-msg); font-size: 10px; margin-top: 2px; }
.msg.cont .icon { visibility: hidden; height: 0; margin: 0; }
.msg .main { flex: 1; min-width: 0; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .head .name { font-size: var(--fs-msg); }
.msg .time { color: #a6a6a6; font-size: var(--fs-sm); white-space: nowrap; }
.msg.cont .head { display: none; }
.msg .gtime { display: none; position: absolute; left: 16px; width: var(--icon-msg); top: 6px; text-align: center; color: #a6a6a6; font-size: 11px; }
.msg.cont:hover .gtime { display: block; }
.msg .body { font-size: var(--fs-msg); line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.edited { color: #a6a6a6; font-size: 12px; margin-left: 6px; }
.msg.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #cfeeff; } to { background: transparent; } }

.quote { display: flex; gap: 8px; align-items: baseline; font-size: var(--fs-sm); color: #6b6b6b; cursor: pointer; margin-bottom: 2px; border-left: 3px solid var(--blue); padding-left: 8px; white-space: nowrap; overflow: hidden; }
.quote .qname { font-weight: 700; flex: none; }
.quote .qtext { overflow: hidden; text-overflow: ellipsis; }
.quote.gone { cursor: default; font-style: italic; border-left-color: #ccc; }

.actions { display: none; position: absolute; right: 16px; top: -14px; gap: 2px; background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 2px; box-shadow: 0 1px 4px #0002; z-index: 2; }
.msg:hover .actions, .msg.show-actions .actions { display: flex; }
.actions button { border: 0; padding: 2px 8px; font-size: 13px; border-radius: 6px; }
.actions button:hover { background: var(--gray); }
.actions .del { color: #ff3333; }

.edit-box { display: block; width: 100%; font-size: var(--fs-msg); line-height: 1.4; border: 2px solid var(--blue); border-radius: 8px; padding: 6px 8px; resize: none; outline: 0; max-height: 220px; }
.edit-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 12px; color: #888; white-space: normal; }
.edit-actions button { font-size: 13px; padding: 2px 10px; }

.attach { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin: 4px 0; font-size: 14px; white-space: normal; }
.attach img, .attach video { max-width: min(100%, 480px); max-height: 360px; border-radius: 6px; }
.attach audio { max-width: 100%; }
.attach .note { color: #888; font-size: 12px; }
.attach .pending { white-space: pre-line; display: grid; place-items: center; width: min(100%, 320px); aspect-ratio: 16 / 9; background: #f0f0f0; border-radius: 6px; color: #888; font-size: 13px; text-align: center; padding: 8px; }
.download { border: 2px solid var(--blue); color: var(--blue); border-radius: 8px; padding: 2px 10px; text-decoration: none; font-size: 13px; }
.sticker { display: block; width: auto; height: auto; max-width: 160px; max-height: 160px; margin: 4px 0; }
.empty { color: #aaa; text-align: center; margin-top: 30px; }
#progress { padding: 0 16px; color: var(--indigo); font-size: 13px; }

/* ---- 入力欄 ---- */
#composerArea { position: relative; margin: 6px 14px calc(10px + env(safe-area-inset-bottom)); }
#composer { display: flex; align-items: center; gap: 8px; border: 2px solid var(--blue); border-radius: 10px; padding: 4px 10px; background: #fff; }
#composer button { border: 0; padding: 2px; display: flex; }
#composer svg { width: 26px; height: 26px; fill: none; stroke-width: 2.4; }
#plusBtn svg { stroke: var(--blue); stroke-width: 3.4 !important; }
#stickerBtn svg { stroke: var(--blue); }
#sendBtn svg { stroke: var(--indigo); overflow: visible; }
#text { flex: 1; border: 0; outline: 0; resize: none; font-size: var(--fs-msg); line-height: 1.4; max-height: 160px; min-width: 0; padding: 3px 0; }
#text::placeholder { color: #d9d9d9; font-weight: 700; }
#main.drag { outline: 4px dashed var(--blue); outline-offset: -8px; }

#attachTray { border: 2px solid var(--blue); border-bottom: 0; border-radius: 10px 10px 0 0; background: #fff; padding: 8px 10px 4px; }
#attachTray:not([hidden]) + #composer { border-top-left-radius: 0; border-top-right-radius: 0; }
#attachItems { display: flex; gap: 10px; overflow-x: auto; padding: 6px 6px 4px 0; }
.att { position: relative; width: 68px; flex: none; }
.att .thumb { width: 68px; height: 68px; border-radius: 8px; object-fit: cover; background: #e3edf5; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #5b7a96; overflow: hidden; }
.att img.thumb { cursor: zoom-in; }
.att-x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 1px solid #ff3333; color: #ff3333; background: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center; }
#attachTray.busy .att-x { display: none; }
#attachTray.busy .att { opacity: .75; }
.att-name { margin-top: 2px; font-size: 11px; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#attachInfo { font-size: 12px; color: #888; padding: 2px 0; }
#attachInfo.error { color: #ff3333; }
.attach img { cursor: zoom-in; }

#lightbox { position: fixed; inset: 0; z-index: 30; background: #000d; display: flex; overflow: auto; cursor: zoom-out; }
#lightbox img { margin: auto; flex: none; max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
#lightbox img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
#lightboxClose { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 14px; z-index: 31; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: #0009; color: #fff; font-size: 26px; line-height: 1; display: grid; place-items: center; }
#replyBar { display: flex; align-items: center; gap: 8px; background: var(--gray); border-radius: 8px 8px 0 0; padding: 4px 8px 4px 12px; font-size: var(--fs-sm); color: #555; }
#replyBar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#replyBar button { border: 0; background: none; font-size: 18px; line-height: 1; padding: 0 6px; }

#stickerPanel { position: absolute; right: 0; bottom: 100%; margin-bottom: 6px; width: min(380px, 100%); max-height: 340px; display: flex; flex-direction: column; background: #fff; border: 2px solid var(--blue); border-radius: 10px; box-shadow: 0 4px 20px #0003; z-index: 15; }
.sp-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; border-bottom: 1px solid var(--gray); }
.sp-head span { flex: 1; }
.sp-head button { font-size: 13px; padding: 2px 10px; }
#stickerGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; padding: 8px; overflow-y: auto; }
.sticker-cell { position: relative; }
.sticker-tile { width: 100%; aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px; background: none; padding: 4px; display: grid; place-items: center; }
.sticker-tile:hover { background: var(--gray); }
.sticker-tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sticker-del { position: absolute; top: 0; right: 0; width: 20px; height: 20px; border-radius: 50%; border: 1px solid #ff3333; color: #ff3333; background: #fff; padding: 0; font-size: 14px; line-height: 1; display: grid; place-items: center; }
.sp-empty { grid-column: 1 / -1; color: #aaa; text-align: center; padding: 16px 0; font-size: 14px; }

#callPanel { display: flex; flex-direction: column; background: #f4fbff; border-bottom: 2px solid var(--blue); height: 62%; min-height: 0; }
#callPanel.small { height: 190px; flex: none; }
#callBar { display: flex; gap: 10px; align-items: center; padding: 4px 10px; font-size: 13px; }
#callTitle { font-weight: 700; color: var(--indigo); }
#callStats { color: #888; margin-right: auto; }
#tiles { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); grid-auto-rows: minmax(0, 1fr); gap: 6px; padding: 0 8px; }
.tile { display: flex; flex-direction: column; min-height: 0; background: #fff; border: 2px solid var(--blue); border-radius: 8px; overflow: hidden; }
.tile .screen { flex: 1; min-height: 0; position: relative; background: #111; }
.tile video, .tile .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.tile video.mirror { transform: scaleX(-1); }
.tile .off { position: absolute; inset: 0; display: grid; place-items: center; background: #222; color: #fff; }
.tile .spec { width: 100%; height: 56px; flex: none; background: #000; display: block; }
.tile .label { font-weight: 700; font-size: 13px; padding: 1px 6px; white-space: nowrap; overflow: hidden; }
#callPanel.small .screen { display: none; }
#callPanel.small .spec { flex: 1; min-height: 0; }
#controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 6px; font-size: 14px; }
#controls button.muted { background: #ff3333; border-color: #ff3333; color: #fff; }

#ring { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 20; background: #fff; border: 3px solid var(--blue); border-radius: 12px; padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; width: max-content; max-width: 94vw; box-shadow: 0 4px 20px #0003; }
dialog { margin: auto; border: 3px solid var(--blue); border-radius: 14px; padding: 20px; width: min(92vw, 440px); }
dialog::backdrop { background: #0005; }
dialog form { display: grid; gap: 10px; }
dialog h2 { color: var(--blue); font-weight: 400; }
dialog label { display: grid; gap: 4px; font-size: 14px; }
.row { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#groupMembers { max-height: 40vh; overflow-y: auto; display: grid; gap: 6px; }
#groupMembers label { display: flex; align-items: center; gap: 10px; }
#preview { border: 1px solid #ddd; border-radius: 8px; padding: 8px; }

/* ---- グループ管理 ---- */
dialog .sub { color: #888; font-size: 13px; }
#currentMembers { display: grid; gap: 6px; max-height: 30vh; overflow-y: auto; }
.member-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.member-row .name { flex: 1; }
.member-row .me { color: #888; font-size: 12px; flex: none; }
.member-row button { font-size: 13px; padding: 2px 10px; flex: none; }
#groupDelete { margin-right: auto; }

/* ---- スライドして確定する確認 ---- */
#slideDialog { width: min(92vw, 380px); border-color: #ff3333; display: none; }
#slideDialog[open] { display: grid; gap: 12px; }
#slideDialog h2 { color: #ff3333; font-size: 18px; font-weight: 700; }
#slideMsg { font-size: 14px; color: #555; white-space: pre-line; }
#slideMsg:empty { display: none; }
#slideTrack { position: relative; height: 52px; border-radius: 26px; background: #ffeaea; border: 2px solid #ff3333; overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; }
#slideFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: #ff9c9c; border-radius: 26px; }
#slideLabel { position: absolute; inset: 0; display: grid; place-items: center; padding-left: 40px; color: #c62828; font-weight: 700; font-size: 15px; pointer-events: none; white-space: nowrap; }
#slideKnob { position: absolute; left: 3px; top: 3px; width: 42px; height: 42px; border-radius: 50%; background: #ff3333; color: #fff; display: grid; place-items: center; font-size: 20px; letter-spacing: -2px; cursor: grab; touch-action: none; outline: 0; box-shadow: 0 1px 4px #0004; }
#slideKnob:active { cursor: grabbing; }
#slideKnob:focus-visible { box-shadow: 0 0 0 3px #fff, 0 0 0 5px #ff3333; }
#slideHint { font-size: 12px; color: #999; text-align: center; }
#slideHint:empty { display: none; }

@media (hover: none) {
  .msg:hover { background: none; }
}
@media (max-width: 760px) {
  #sidebar { width: 100%; max-width: none; border: 0; }
  #app:not(.open) #main { display: none; }
  #app.open #sidebar { display: none; }
  #backBtn { display: block; }
  #header { gap: 8px; padding: 4px 8px; }
  #title { display: none; }
  #callBtn { order: 3; flex: none; }
  #partner { max-width: none; flex: 1; gap: 8px; }
  .msg { gap: 10px; padding: 2px 10px; }
  .msg .gtime { left: 10px; }
  .actions { right: 10px; }
  #composerArea { margin-left: 8px; margin-right: 8px; }
  #callPanel { height: 70%; }
  #callPanel.small { height: 170px; }
}
