/* ===== モバイル: 横は100%幅で動かない・バウンス禁止（全フロント案件の必須規約） ===== */
html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
  overscroll-behavior: none;
}
img, video, iframe { max-width: 100%; height: auto; }
table { max-width: 100%; }
input, textarea, select { max-width: 100%; box-sizing: border-box; }
pre, code { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }

/* ===== 色 ===== */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #18212f;
  --muted: #5f6b7a;
  --line: #e3e8ef;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #d1242f;
  --yt: #e8333a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #18202b;
    --ink: #eef2f7;
    --muted: #9aa6b5;
    --line: #2a3442;
    --accent: #4c8dff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word; /* 長い URL・英数字で画面を広げない（全幅の安全網） */
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ===== ヘッダー ===== */
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
#topbar h1 {
  flex: 1 1 auto; min-width: 0; margin: 0;
  font-size: 18px; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#topbar .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }

main { padding: 14px 12px 120px; max-width: 760px; margin: 0 auto; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn.icon { min-width: 42px; padding: 0; }
.btn:disabled { opacity: .45; cursor: default; }

/* ===== ホーム（ボード一覧） ===== */
.lead { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.boards { display: grid; gap: 12px; }
.board-card {
  display: block; width: 100%; text-align: left;
  padding: 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
}
.board-card .title { font-weight: 700; font-size: 17px; }
.board-card .meta { color: var(--muted); font-size: 13px; }
.thumbs { display: flex; gap: 6px; margin-top: 10px; }
.thumbs > div {
  width: 64px; height: 48px; border-radius: 8px; background: var(--line) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 20px; flex: none;
}
.empty {
  text-align: center; color: var(--muted); padding: 40px 12px;
  border: 1px dashed var(--line); border-radius: 14px;
}
.privacy-note { margin-top: 18px; font-size: 12px; color: var(--muted); text-align: center; }

/* ===== ボード画面 ===== */
.board-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.board-actions .btn.primary { flex: 1 1 100%; min-height: 50px; font-size: 17px; }
.items { display: grid; gap: 10px; }
.item {
  display: flex; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.item .thumb {
  width: 96px; height: 72px; flex: none; border-radius: 8px;
  background: var(--line) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.item .body { flex: 1 1 auto; min-width: 0; }
.item .ititle { font-weight: 700; overflow-wrap: anywhere; }
.item .badge {
  display: inline-block; font-size: 12px; padding: 0 6px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-right: 4px;
}
.item .badge.yt { color: var(--yt); border-color: var(--yt); }
.item .caption { font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.item .memo { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.item .ops { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* ===== 追加バー（画面下に固定。FABは使わない） ===== */
#addbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
/* display:grid が hidden 属性より強いため、隠す指定を明示する */
#addbar[hidden] { display: none; }
#addbar .btn { min-height: 48px; padding: 0 4px; font-size: 13px; flex-direction: column; gap: 0; line-height: 1.2; }
#addbar .btn span { font-size: 20px; }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 20, .55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; } }
.modal {
  width: min(520px, 100%);
  max-height: calc(100% - 12px);
  overflow-y: auto;
  background: var(--surface); border-radius: 16px; padding: 16px;
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.field textarea { min-height: 72px; resize: vertical; }
.row2 { display: flex; flex-wrap: wrap; gap: 10px; }
.row2 > .field { flex: 1 1 140px; min-width: 0; }
.hint { font-size: 12px; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.preview {
  width: 100%; aspect-ratio: 16 / 9; border-radius: 10px; margin-bottom: 12px;
  background: var(--line) center / cover no-repeat;
}

/* ===== 見せるモード（全画面） ===== */
.show {
  position: fixed; inset: 0; z-index: 100;
  background: #000; color: #fff;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  user-select: none; -webkit-user-select: none;
}
.show[hidden] { display: none; }
.show .bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px;
}
.show .count { font-size: 14px; color: #c9d1dc; white-space: nowrap; }
.show .exit {
  position: relative; overflow: hidden;
  min-height: 36px; padding: 0 12px; border-radius: 18px;
  border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #fff;
  font-size: 13px; cursor: pointer;
}
.show .exit .fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: rgba(255,255,255,.3); pointer-events: none;
}
.show .exit.holding .fill { width: 100%; transition: width .8s linear; }
.show .exit .label { position: relative; }
.show .stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0 8px;
}
.show .stage img, .show .stage video {
  max-width: 100%; max-height: 100%; object-fit: contain; height: auto;
}
.show .ytwrap { width: 100%; max-width: 1100px; aspect-ratio: 16 / 9; }
.show .ytwrap.short { max-width: 420px; aspect-ratio: 9 / 16; max-height: 100%; }
.show .ytwrap iframe { width: 100%; height: 100%; border: 0; }
.show .card {
  max-width: 640px; width: 100%; padding: 22px; border-radius: 16px;
  background: #1b2330; text-align: center; overflow-wrap: anywhere;
}
.show .card .big { font-size: clamp(20px, 5vw, 34px); font-weight: 700; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.show .caption {
  text-align: center; padding: 10px 16px; font-size: clamp(15px, 3.6vw, 22px);
  min-height: 1.5em; overflow-wrap: anywhere;
}
.show .nav { display: flex; gap: 10px; padding: 8px 10px 12px; }
.show .nav button {
  flex: 1 1 0; min-height: 52px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff;
  font-size: 18px; cursor: pointer;
}
.show .nav button:disabled { opacity: .3; }
.show .tv-link { color: #9cc2ff; font-size: 13px; white-space: nowrap; }

/* ===== トースト ===== */
#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 200;
  max-width: calc(100% - 24px);
  translate: -50% 0;
  padding: 10px 14px; border-radius: 10px;
  background: #18212f; color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.on { opacity: 1; }

/* ===== ホームのタブ（テーマ／人） ===== */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tab {
  min-height: 42px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--muted); font-weight: 700; cursor: pointer;
}
.tab.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ===== 見せたい人の選択（チップ） ===== */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip {
  min-height: 34px; padding: 0 12px; border-radius: 17px;
  border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  max-width: 100%; overflow-wrap: anywhere;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pp-filter { margin-bottom: 4px; }
.pp-add { display: flex; flex-wrap: wrap; gap: 6px; }
.pp-add input {
  flex: 1 1 160px; min-width: 0; padding: 8px 10px; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.field .pp-filter {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}

/* ===== この部屋に映す（room.js） ===== */
.room-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.room-btn {
  min-height: 96px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 16px; font-weight: 700;
}
.room-btn span { font-size: 30px; }
.row-search { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.row-search input {
  flex: 1 1 200px; min-width: 0; padding: 10px 12px; font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
.yt-result {
  display: flex; gap: 10px; width: 100%; text-align: left; padding: 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  margin-bottom: 8px; cursor: pointer;
}
.yt-result .thumb {
  width: 120px; height: 68px; flex: none; border-radius: 8px; background: var(--line) center / cover no-repeat;
}
.yt-result .body { min-width: 0; }
.yt-result .ititle { font-weight: 700; overflow-wrap: anywhere; font-size: 14px; }
.room-paste { margin-top: 10px; }
.room-yt-easy {
  padding: 12px; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.room-steps { margin: 0 0 10px; padding-left: 22px; line-height: 2; }
.room-steps .btn { display: inline-block; text-decoration: none; }
.room-big { width: 100%; min-height: 52px; font-size: 17px; }
.intro { max-height: calc(100vh - 220px); overflow-y: auto; }
.confirm-preview {
  display: flex; justify-content: center; align-items: center; background: #000; border-radius: 12px;
  overflow: hidden; margin: 8px 0 12px;
}
.confirm-preview img, .confirm-preview video { max-width: 100%; max-height: 45vh; object-fit: contain; display: block; }
.confirm-warn { margin: 0 0 10px; line-height: 1.7; }
.confirm-skip { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.intro-head { font-weight: 700; margin: 10px 0 4px; }
.intro-list { margin: 0; padding-left: 0; list-style: none; }
.intro-list li { padding: 6px 0; line-height: 1.6; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.intro-list li:last-child { border-bottom: 0; }
.room-paste summary { cursor: pointer; color: var(--accent); }
.room-deck { padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.room-deck-head { font-weight: 700; margin-bottom: 8px; }
.room-thumbs { flex-wrap: wrap; }
.room-thumb {
  width: 64px; height: 48px; border-radius: 8px; border: 2px solid transparent;
  background: var(--line) center / cover no-repeat; cursor: pointer; font-size: 20px;
}
.room-thumb.on { border-color: var(--accent); }
.room-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.room-remote {
  padding: 12px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow);
}
.room-remote-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  font-weight: 700; margin-bottom: 10px;
}
.room-remote-tabs { display: flex; gap: 6px; }
.rc-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.rc-pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.rc-btn {
  min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  color: inherit; font: inherit; font-size: 18px; font-weight: 700; cursor: pointer;
  touch-action: manipulation;
}
.rc-btn small { font-size: 11px; margin-left: 2px; }
.rc-btn.rc-main { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rc-btn:active { transform: scale(.96); }
