/* ===== 共通トークン ===== */
:root {
  --bg: #0f1220;
  --surface: #1a1f35;
  --surface-2: #232a45;
  --border: #2e3656;
  --text: #e8ebf5;
  --text-dim: #9aa3c4;
  --accent: #5b8cff;
  --accent-2: #7c5bff;
  --danger: #ff5b7a;
  --ok: #46d39a;
  --own: #2b6cff;
  --radius: 14px;
  --radius-sm: 9px;
  --gap: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

/* ライトテーマ（html[data-theme="light"] で全画面共通に切替）*/
:root[data-theme="light"] {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #d8dcea;
  --text: #14172a;
  --text-dim: #5b6588;
  --own: #2b6cff;
  --shadow: 0 6px 24px rgba(20, 30, 60, 0.12);
}

* { box-sizing: border-box; }

/* テーマ切替ボタン */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.theme-toggle:hover { border-color: var(--accent); }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ===== 参加者画面 ===== */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .back {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  padding: 4px 6px;
  border-radius: 8px;
}
.topbar .back:hover { background: var(--surface-2); color: var(--text); }
.topbar .title {
  font-weight: 700;
  font-size: 16px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .me {
  font-size: 13px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}
.topbar .me:hover { color: var(--text); }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.badge.open { background: rgba(70, 211, 154, 0.16); color: var(--ok); }
.badge.closed { background: rgba(154, 163, 196, 0.16); color: var(--text-dim); }

/* 名前入力 */
.center-card {
  margin: auto;
  width: min(92%, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.center-card h1 { font-size: 22px; margin: 0 0 6px; }
.center-card p { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; line-height: 1.6; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 13px; color: var(--text-dim); }
input[type="text"], textarea, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  width: 100%;
}
input[type="text"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.full { width: 100%; margin-top: 16px; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* 部屋一覧 */
.rooms {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.rooms .empty { color: var(--text-dim); text-align: center; margin-top: 40px; }
.room-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.12s ease;
}
.room-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.room-card .rc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.room-card .rc-title { font-weight: 700; font-size: 16px; flex: 1; }
.room-card .rc-desc { color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* チャット */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg.own { align-self: flex-end; align-items: flex-end; }
.msg .meta { font-size: 12px; color: var(--text-dim); margin: 0 6px 3px; display: flex; gap: 6px; align-items: baseline; }
.msg .name { font-weight: 700; color: var(--text); }
.msg.own .name { color: var(--accent); }
.bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 9px 13px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.own .bubble { background: var(--own); border-color: var(--own); color: #fff; }
.msg .edited { font-size: 11px; color: var(--text-dim); }
.msg .row2 { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 5px 6px 0; }
.msg .reacts { display: flex; flex-wrap: wrap; gap: 6px; }
.react-btn .cnt { font-variant-numeric: tabular-nums; }
.react-btn, .act-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.react-btn.active { background: rgba(91, 140, 255, 0.18); color: var(--accent); border-color: var(--accent); }
.act-btn:hover, .react-btn:hover { color: var(--text); }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  font-size: 16px;
  border-radius: 20px;
  padding: 10px 14px;
}
.composer .send { border-radius: 999px; padding: 0 20px; }
/* 拍手（👏888…）ボタン：送信の隣に置く丸ボタン */
.composer .clap {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 0 16px;
  font-size: 18px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.composer .clap:hover { border-color: var(--accent); }
.composer .clap:active { transform: scale(0.94); }
.composer.disabled { opacity: 0.6; }

.jump-latest {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 84px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 6;
}

/* トースト */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  z-index: 30;
  box-shadow: var(--shadow);
}

/* ===== モニター表示画面 ===== */
.display-root {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.display-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.display-head .dt { font-weight: 800; font-size: clamp(20px, 3vw, 34px); flex: 1; }
.gear {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 18px;
}
.display-feed {
  flex: 1;
  overflow-y: auto;
  padding: 24px 40px 40px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--d-gap, 18px);
  scroll-behavior: smooth;
}
.d-msg { display: flex; align-items: baseline; gap: 16px; animation: slidein 0.25s ease; }
@keyframes slidein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.d-name {
  font-weight: 800;
  color: var(--accent);
  font-size: var(--d-font, 40px);
  white-space: nowrap;
  flex-shrink: 0;
}
.d-body { font-size: var(--d-font, 40px); line-height: 1.35; word-break: break-word; white-space: pre-wrap; }
.d-reacts { display: inline-flex; gap: 14px; flex-shrink: 0; align-items: baseline; }
.d-react { font-size: calc(var(--d-font, 40px) * 0.6); color: var(--ok); flex-shrink: 0; }

.panel {
  position: fixed;
  top: 64px;
  right: 24px;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  z-index: 20;
}
.panel h3 { margin: 0 0 14px; font-size: 15px; }
.panel .pf { margin-bottom: 14px; }
.panel .pf label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.panel input[type="range"] { width: 100%; }
.panel .val { float: right; color: var(--text); }

/* ===== 管理画面 ===== */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 24px 16px 60px; }
.admin-wrap h1 { font-size: 22px; }
.admin-wrap h2 { font-size: 17px; margin-top: 32px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1; min-width: 160px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-dim); font-weight: 600; }
.muted { color: var(--text-dim); font-size: 13px; }
.linkish { color: var(--accent); cursor: pointer; word-break: break-all; }
.tag { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px; margin: 0 6px 6px 0; }
.tag button { background: transparent; border: none; color: var(--text-dim); font-size: 15px; }
.tag button:hover { color: var(--danger); }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.pill.visible { background: rgba(70,211,154,0.16); color: var(--ok); }
.pill.hidden { background: rgba(255,91,122,0.16); color: var(--danger); }

/* ===== 投稿者向け注意事項 ===== */
.notice {
  background: rgba(255, 91, 122, 0.10);
  border: 1px solid rgba(255, 91, 122, 0.35);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;       /* admin が入力した改行を保持 */
  word-break: break-word;
}
.center-card .notice { text-align: left; margin-bottom: 4px; }
.notice-bar { margin: 12px 16px 0; }   /* 部屋一覧上部のバナー配置 */

/* ===== レスポンシブ（スマートフォン）===== */
@media (max-width: 600px) {
  .center-card { width: min(94%, 460px); padding: 22px 18px; }
  .center-card h1 { font-size: 20px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar .title { font-size: 15px; }
  .rooms { padding: 12px; gap: 10px; }
  .room-card { padding: 14px; }
  .feed { padding: 12px 10px 6px; }
  .msg { max-width: 92%; }
  .notice-bar { margin: 10px 12px 0; }

  .display-head { padding: 10px 14px; gap: 8px; }
  .display-feed { padding: 16px 16px 28px; }
  /* 表示調整パネルは画面下部のシートとして全幅表示（右上固定だと小画面でははみ出すため）*/
  .panel { top: auto; right: 0; bottom: 0; left: 0; width: auto; border-radius: var(--radius) var(--radius) 0 0; }

  .admin-wrap { padding: 16px 12px 48px; }
  .admin-wrap h1 { font-size: 19px; }
  .admin-wrap h2 { font-size: 16px; margin-top: 24px; }
  .card { padding: 14px; }
  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
}
