:root {
  --bg: #0e1013;
  --panel: #171a1f;
  --panel-2: #1f232a;
  --line: #2a2f38;
  --text: #e8eaed;
  --muted: #9aa0a8;
  --accent: #4f8cff;
  --live: #ff3b3b;
  --question: #f5b445;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
}
button:hover { border-color: #3a404b; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: #ff8a8a; }
input, textarea, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------------- login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
.login-card button { width: 100%; margin-top: 22px; padding: 11px; }
.error { color: #ff8a8a; font-size: 13px; min-height: 1.5em; margin-top: 10px; }

/* ---------------- watch */
body.watch { overflow: hidden; }
#app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); font-size: 14px; flex: none;
}
.topbar .spacer { flex: 1; }
.topbar button, .topbar a.btn { padding: 4px 10px; font-size: 13px; }
.topbar a.btn { text-decoration: none; color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
.live-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live-pill.live .live-dot { background: var(--live); box-shadow: 0 0 0 3px rgba(255,59,59,.25); }
.live-pill.live { color: #fff; }
.viewer-count { color: var(--muted); }
.source-name { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.topbar select.source-select { width: auto; max-width: 180px; padding: 4px 8px; font-size: 13px; }
.source-list { display: flex; flex-direction: column; gap: 8px; }
.source-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.source-item.active { border-color: var(--live); }
.source-item input { width: auto; }
.source-item .path { color: var(--muted); font-size: 12px; margin-left: auto; }

.stage-wrap { flex: 1; display: flex; min-height: 0; }
.stage { position: relative; flex: 1; background: #000; min-width: 0; display: grid; place-items: center; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted);
  pointer-events: none; text-align: center; padding: 16px;
}
.fab { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.fab button {
  width: 52px; height: 52px; border-radius: 50%; padding: 0; font-size: 22px; position: relative;
  background: rgba(20, 22, 26, .72); border: 1px solid rgba(255,255,255,.15); backdrop-filter: blur(6px);
}
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--live); color: #fff; font-size: 11px; line-height: 18px; padding: 0 4px;
}
.toasts {
  position: absolute; left: 12px; bottom: 14px; right: 80px; display: flex; flex-direction: column;
  gap: 6px; pointer-events: none; z-index: 4;
}
.toast {
  align-self: flex-start; max-width: 100%; background: rgba(0,0,0,.6); padding: 6px 10px; border-radius: 8px;
  font-size: 13px; animation: toast-in .2s ease-out; overflow-wrap: anywhere;
}
.toast b { color: var(--question); margin-right: 6px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

.chat {
  width: 340px; flex: none; display: flex; flex-direction: column; background: var(--panel);
  border-left: 1px solid var(--line); min-height: 0;
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px;
}
.chat-head button { padding: 2px 10px; }
.messages { list-style: none; margin: 0; padding: 10px 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.msg { font-size: 14px; overflow-wrap: anywhere; }
.msg .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; }
.msg .name { color: var(--text); font-weight: 600; }
.msg.admin .name { color: var(--accent); }
.msg.question { background: rgba(245,180,69,.08); border: 1px solid rgba(245,180,69,.3); border-radius: 8px; padding: 8px; }
.msg .tag { font-size: 11px; color: #1b1300; background: var(--question); border-radius: 4px; padding: 0 5px; font-weight: 700; }
.msg img { display: block; margin-top: 6px; max-width: 100%; max-height: 180px; border-radius: 6px; cursor: zoom-in; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form button { flex: none; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.65); }
dialog h2 { margin: 0 0 12px; font-size: 17px; }
dialog img { width: 100%; max-height: 45dvh; object-fit: contain; background: #000; border-radius: 8px; }
dialog textarea { margin-top: 12px; min-height: 90px; resize: vertical; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
#imgDialog { width: auto; max-width: calc(100vw - 32px); padding: 8px; }
#imgDialog img { max-height: calc(100dvh - 60px); }

/* 音声ボタン（OFF のとき斜線） */
.fab button.off { opacity: .6; }
#voiceBtn.off::after {
  content: ''; position: absolute; left: 12px; right: 12px; top: 50%; height: 2px;
  background: #ff6b6b; transform: rotate(-45deg);
}

/* 遠隔操作 */
.fab button.active { background: var(--live); border-color: var(--live); }
.stage.controlling { touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.stage.controlling video { outline: 2px solid var(--live); outline-offset: -2px; }
.stage.controlling .toasts { bottom: 80px; }
.ctrl-badge {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: rgba(255,59,59,.85); color: #fff; font-size: 13px; font-weight: 600;
  padding: 4px 12px; border-radius: 14px; pointer-events: none; white-space: nowrap;
}
.ctrl-bar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 5;
  display: flex; gap: 8px; padding: 6px; border-radius: 30px;
  background: rgba(20,22,26,.78); border: 1px solid rgba(255,255,255,.15); backdrop-filter: blur(6px);
}
.ctrl-bar button { width: 46px; height: 46px; border-radius: 50%; padding: 0; font-size: 18px; background: transparent; border: 0; }
.ctrl-bar button:active { background: rgba(255,255,255,.15); }
.tap-ripple {
  position: fixed; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(255,59,59,.35); pointer-events: none; z-index: 50;
  animation: ripple .45s ease-out forwards;
}
@keyframes ripple { to { transform: scale(1.8); opacity: 0; } }

.mobile-only { display: none; }

/* 全画面（Fullscreen API / iPhone向け疑似全画面 共通） */
#app:fullscreen .topbar, body.pseudo-fs .topbar { display: none; }
#app:fullscreen .chat:not(.open), body.pseudo-fs .chat:not(.open) { display: none; }
body.pseudo-fs .stage { position: fixed; inset: 0; z-index: 10; }

/* ---------------- スマホ */
@media (max-width: 820px) {
  .mobile-only { display: inline-block; }
  .topbar {
    position: absolute; top: 0; left: 0; right: 0; z-index: 6; border: 0;
    background: linear-gradient(rgba(0,0,0,.7), transparent); padding: 8px 12px 18px;
  }
  .topbar { gap: 8px; }
  .topbar button, .topbar a.btn { white-space: nowrap; flex: none; }
  .topbar .source-name { display: none; }
  .topbar select.source-select { max-width: 120px; flex: 0 1 auto; }
  .stage-wrap { position: relative; }
  .ctrl-bar { left: 12px; transform: none; }
  .ctrl-badge { top: 52px; }
  .chat {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 62dvh; z-index: 20;
    border: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0;
    transform: translateY(100%); transition: transform .2s ease-out;
  }
  .chat.open { transform: none; }
  #app:fullscreen .chat:not(.open), body.pseudo-fs .chat:not(.open) { display: flex; }
  body.pseudo-fs .chat { position: fixed; z-index: 30; }
}

/* ---------------- admin */
.admin { max-width: 1200px; margin: 0 auto; padding: 16px; }
.admin header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.admin header h1 { font-size: 20px; margin: 0; flex: 1; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.wrap { white-space: normal; min-width: 200px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--panel-2); }
.pill.ok { background: rgba(70,200,120,.15); color: #6fdc9b; }
.pill.ng { background: rgba(255,80,80,.15); color: #ff8a8a; }
.pill.out { background: var(--panel-2); color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.form-row label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.row-actions { display: flex; gap: 6px; }
.row-actions button, .row-actions select { padding: 3px 8px; font-size: 12px; width: auto; }
.q-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.q-item { background: var(--panel-2); border-radius: 8px; padding: 10px; font-size: 13px; }
.q-item img { width: 100%; border-radius: 6px; background: #000; cursor: zoom-in; }
.q-item .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.q-item p { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.muted { color: var(--muted); }

/* ---------------- 通話 */
.voice-bar {
  position: absolute; left: 10px; top: 44px; right: 76px; z-index: 4;
  display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none;
}
.voice-chip {
  background: rgba(0,0,0,.6); color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px; font-size: 12px; white-space: nowrap; transition: border-color .15s, box-shadow .15s;
}
.voice-chip.muted { color: var(--muted); }
.voice-chip.speaking { border-color: #3ddc84; box-shadow: 0 0 0 2px rgba(61,220,132,.35); }
.fab button.on { background: #1f8f4e; border-color: #3ddc84; }
@media (max-width: 820px) { .voice-bar { top: 84px; } }

/* ホーム画面から開いたとき（PWA）：ステータスバーやホームバーに重ならないようにする */
@media (display-mode: standalone) {
  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  #app { height: 100%; }
}

.brand-icon{display:block;margin:0 auto 12px;border-radius:22%;box-shadow:0 6px 24px #0005}
