:root {
  --bg: #1b1d23;
  --panel: #23262e;
  --panel-2: #2b2f39;
  --line: #353a46;
  --text: #e6e8ee;
  --muted: #9097a6;
  --accent: #6f9bff;
  --accent-2: #4f7ef0;
  --green: #4fc47a;
  --red: #e8555f;
  --live: #e8555f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ic { display: block; }

/* ボタン */
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.wide { width: 100%; }
.btn.big { padding: 12px 36px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 6px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.icon-btn.sm { padding: 3px; }

.input { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ログイン */
.login-wrap, .loading { height: 100%; display: grid; place-items: center; padding: 16px; }
.loading { color: var(--muted); }
.login { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; text-align: center; }
.login h1 { margin: 8px 0 0; font-size: 22px; }
.login p { margin: 0 0 12px; }
.login .field { text-align: left; }
.login-logo { color: var(--accent); display: flex; justify-content: center; }
.login-error { color: var(--red); min-height: 21px; margin: 4px 0 8px; font-size: 13px; }

/* 全体 */
.shell { display: grid; grid-template-columns: 250px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; position: relative; }
.team { padding: 14px 16px; font-weight: 700; font-size: 15px; border-bottom: 1px solid var(--line); }
.side-scroll { flex: 1; overflow-y: auto; padding: 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 600; padding: 10px 8px 4px; }
.rooms, .room-people, .members { list-style: none; margin: 0; padding: 0; }
.room-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.room-row:hover { background: rgba(255,255,255,.05); color: var(--text); }
.room.active > .room-row { background: rgba(255,255,255,.09); color: var(--text); }
.room.here > .room-row .room-ic { color: var(--green); }
.room-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-tools { display: none; }
.room-row:hover .room-tools { display: flex; }
.room-people { padding: 2px 0 6px 26px; }
.person { display: flex; align-items: center; gap: 8px; padding: 3px 6px; font-size: 13px; }
.person-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-ic { color: var(--red); display: inline-flex; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); white-space: nowrap; }
.badge.live { background: var(--live); color: #fff; font-weight: 700; }
.member { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-size: 13px; }
.member span:nth-child(2) { flex: 1; }
.member.off { opacity: .45; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); }

.call-status { border-top: 1px solid var(--line); padding: 10px 14px; }
.call-line { display: flex; align-items: center; gap: 6px; color: var(--green); font-weight: 600; font-size: 13px; }
.call-room { color: var(--muted); font-size: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--line); background: #1f2229; }
.me-name { flex: 1; min-width: 0; font-weight: 600; font-size: 13px; line-height: 1.25; }
.me-name small { display: block; color: var(--muted); font-weight: 400; }
.offline-banner { position: absolute; left: 8px; right: 8px; bottom: 64px; background: #5a3a12; color: #ffd9a0; padding: 8px 10px; border-radius: 8px; font-size: 12px; }

.avatar { border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; transition: box-shadow .12s; }
.speaking .avatar.ring { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--green); }

/* メイン */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main-head { display: flex; align-items: center; gap: 10px; padding: 0 18px; height: 52px; border-bottom: 1px solid var(--line); flex: none; }
.main-head h1 { font-size: 16px; margin: 0; }
.main-head .count { color: var(--muted); font-size: 12px; }
.room-ic { color: var(--muted); display: inline-flex; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }

.lobby { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px; text-align: center; }
.lobby-people { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
.lobby-person { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.screens { flex: 1; min-height: 0; display: grid; gap: 10px; }
.screens.n1 { grid-template-columns: 1fr; }
.screens.n2 { grid-template-columns: 1fr 1fr; }
.screens.n3, .screens.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.screens.focused { grid-template-columns: 1fr 220px; }
.thumbs { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; }
.thumbs .screen-tile { aspect-ratio: 16 / 9; flex: none; }
.screen-tile { position: relative; background: #000; border-radius: 10px; overflow: hidden; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.screen-tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.screen-tile:fullscreen { border-radius: 0; }
.pan { position: absolute; inset: 0; overflow: auto; cursor: grab; display: flex; }
.pan.dragging { cursor: grabbing; }
.pan video { max-width: none; max-height: none; object-fit: fill; flex: none; margin: auto; }
.pan::-webkit-scrollbar { width: 10px; height: 10px; }
.pan::-webkit-scrollbar-thumb { background: rgba(255,255,255,.25); border-radius: 5px; }
.tile-tools .icon-btn.active { background: var(--accent-2); }
.connecting { color: var(--muted); }
.tile-label { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.65); padding: 3px 8px; border-radius: 6px; font-size: 12px; display: flex; gap: 6px; align-items: center; }
.chip { background: rgba(111,155,255,.25); color: #cfe0ff; padding: 0 6px; border-radius: 4px; font-size: 11px; }
.tile-stats { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; font-size: 11px; color: #cfd5e2; white-space: pre; font-variant-numeric: tabular-nums; }
.tile-stats:empty { display: none; }
.tile-tools { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.screen-tile:hover .tile-tools { opacity: 1; }
.tile-tools .icon-btn { background: rgba(0,0,0,.6); color: #fff; }

.people { flex: 1; display: flex; flex-wrap: wrap; gap: 12px; align-content: center; justify-content: center; }
.people.strip { flex: none; align-content: flex-start; }
.person-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 180px; }
.strip .person-card { flex-direction: row; width: auto; padding: 6px 12px; gap: 8px; }
.card-name { font-weight: 600; font-size: 13px; }
.card-name small { color: var(--muted); font-weight: 400; margin-left: 2px; }
.card-icons { display: flex; gap: 6px; align-items: center; min-height: 16px; }
.link-state { font-size: 11px; color: #ffcf7a; }
.volume { width: 100%; accent-color: var(--accent); }
.strip .volume { width: 70px; }
.person-card.speaking { border-color: var(--green); }

/* 下の操作ボタン */
.controls { flex: none; display: flex; justify-content: center; gap: 10px; padding: 10px 12px 14px; border-top: 1px solid var(--line); }
.ctl { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel-2); padding: 9px 16px; border-radius: 10px; cursor: pointer; }
.ctl:hover { filter: brightness(1.15); }
.ctl.off { background: #4a2a2e; border-color: #6b3540; color: #ffb3ba; }
.ctl.on { background: #24406e; border-color: var(--accent-2); color: #dbe6ff; }
.ctl.leave { background: var(--red); border-color: var(--red); color: #fff; }
.ctl:disabled { opacity: .5; cursor: default; }
.ctl-label { font-size: 13px; }
.caret { opacity: .7; }
.share-wrap { position: relative; }
.share-menu { position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%); width: 330px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.5); z-index: 10; }
.menu-title { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.preset { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.preset:hover { background: rgba(255,255,255,.04); }
.preset.sel { border-color: var(--accent-2); background: rgba(79,126,240,.12); }
.preset input { margin-top: 4px; accent-color: var(--accent); }
.preset-name { font-weight: 600; }
.preset-name small { color: var(--muted); font-weight: 400; margin-left: 8px; font-size: 11px; }
.preset-note { color: var(--muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; padding: 10px 4px; font-size: 13px; }
.check input { accent-color: var(--accent); }
.share-menu .btn { margin-top: 6px; }

/* 小窓 */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 100%; max-width: 380px; }
.modal h2 { margin: 0 0 8px; font-size: 17px; }
.modal-text { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toasts { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: #111318; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: opacity .4s; }
.toast.out { opacity: 0; }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 40vh; }
  .ctl-label { display: none; }
  .screens.focused { grid-template-columns: 1fr; }
}
