:root {
  --bg: #0f0f13;
  --panel: #1a1a22;
  --panel-2: #22222c;
  --border: #2a2a36;
  --text: #e8e8ee;
  --muted: #8a8a9a;
  --accent: #6c5ce7;
  --live: #e53e3e;
  --danger: #c0392b;
  --cheer: #ff6b81;
  --ok: #2ecc71;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
a { color: inherit; text-decoration: none; }

/* header */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  min-height: 50px;
  flex: none;
}
header h1 { font-size: 18px; margin: 0; white-space: nowrap; }
header h1 a:hover { color: var(--accent); }
#header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.hdr-user { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 999px; border: 1px solid var(--border); }
.hdr-user:hover { border-color: var(--accent); }
.hdr-user .uname { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex: none; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }
.avatar.xl { width: 96px; height: 96px; font-size: 36px; }

.badge {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--border); color: var(--muted); letter-spacing: .05em; white-space: nowrap;
}
.badge.live { background: var(--live); color: #fff; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* buttons / inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.cheer { background: var(--cheer); font-weight: 700; }
.btn.cheer:active { transform: scale(.95); }
.btn.follow { font-weight: 700; }
input[type=text], input[type=password], textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 14px; min-width: 0; width: 100%;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus { outline: 1px solid var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.check input { width: 16px; height: 16px; }
.check .muted { display: block; margin-left: 24px; }
code { background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* layout */
main { padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card h2 .muted { font-weight: 400; margin-left: 8px; }
.section-title { font-size: 15px; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-title:first-child { margin-top: 0; }

/* top page */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { font-size: 13px; padding: 5px 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); cursor: pointer; color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.ch-card { display: block; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.ch-card:hover { border-color: var(--accent); }
.ch-thumb {
  aspect-ratio: 16/9; background: #000; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px; position: relative; overflow: hidden;
}
.ch-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ch-card.offline .ch-thumb img { opacity: .45; }
.ch-thumb .badge { position: absolute; top: 8px; left: 8px; }
.ch-thumb .ph { position: absolute; }
.ch-thumb .meta { position: absolute; bottom: 8px; right: 8px; display: flex; gap: 6px; }
.ch-thumb .meta span { font-size: 12px; color: #fff; background: rgba(0,0,0,.65); padding: 2px 8px; border-radius: 4px; }
.ch-body { display: flex; gap: 10px; padding: 10px 12px; align-items: center; }
.ch-body .title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-body .sub { display: flex; gap: 6px; align-items: center; margin-top: 3px; overflow: hidden; }
.ch-body .sub .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* watch page */
.watch { display: grid; grid-template-columns: 1fr 340px; gap: 16px; height: calc(100vh - 51px); }
.watch-main { min-width: 0; overflow-y: auto; }
#player-wrap { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; max-height: 75vh; }
video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
#offline {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--muted); background: #000; text-align: center; padding: 16px;
}
#offline.hidden { display: none; }
#offline strong { color: var(--text); font-size: 18px; }
#offline img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .3; z-index: -1; }
#offline.hidden img { display: none; }
#hearts { position: absolute; right: 16px; bottom: 60px; width: 60px; height: 240px; pointer-events: none; overflow: visible; }
.heart {
  position: absolute; bottom: 0; left: 50%; font-size: 26px; pointer-events: none;
  animation: floatUp 1.6s ease-out forwards;
}
@keyframes floatUp {
  0%   { transform: translate(-50%, 0) scale(.6); opacity: 0; }
  15%  { opacity: 1; transform: translate(-50%, -20px) scale(1.1); }
  100% { transform: translate(calc(-50% + var(--dx, 0px)), -220px) scale(1); opacity: 0; }
}
.ch-info { display: flex; align-items: flex-start; gap: 12px; margin-top: 12px; }
.ch-info h2 { font-size: 16px; margin: 0 0 4px; }
.ch-info .desc { margin: 8px 0 0; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.ch-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex: none; flex-wrap: wrap; justify-content: flex-end; }

#chat { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; min-height: 0; }
#chat h3 { font-size: 14px; margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--muted); }
#messages { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; gap: 8px; font-size: 14px; line-height: 1.4; word-break: break-word; align-items: flex-start; }
.msg > div { flex: 1; min-width: 0; }
.msg .name { color: var(--accent); font-weight: 700; margin-right: 6px; }
.msg .name.guest { color: var(--muted); }
.msg .time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.msg .mod { display: none; gap: 2px; flex: none; }
.msg .mod button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0 4px; }
.msg .mod button:hover { color: var(--text); }
#chat.owner .msg .mod { display: inline-flex; }
.msg .rep { display: none; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0 4px; flex: none; }
.msg:hover .rep { display: inline; }
.msg .rep:hover { color: #f5a5a5; }
.sysmsg { font-size: 12px; color: var(--muted); text-align: center; padding: 2px 0; }
.site-footer { display: flex; gap: 16px; justify-content: center; padding: 24px 0 8px; font-size: 12px; color: var(--muted); }
.site-footer a:hover { color: var(--accent); }
#chat form { display: grid; grid-template-columns: 90px 1fr auto; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); }
#chat form.logged-in { grid-template-columns: 1fr auto; }
#chat form.logged-in #name { display: none; }
#chat-error { font-size: 12px; color: #f5a5a5; padding: 0 14px 6px; }

/* profile page */
.profile { max-width: 860px; margin: 0 auto; }
.profile-head { display: flex; gap: 20px; align-items: flex-start; }
.profile-head h2 { margin: 0 0 4px; font-size: 20px; }
.profile-head .bio { white-space: pre-wrap; font-size: 14px; margin: 10px 0 0; color: var(--text); }
.profile-head .stats { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.profile-head .stats b { color: var(--text); }
.profile-actions { margin-left: auto; display: flex; gap: 8px; flex: none; }
.ch-hero { display: grid; grid-template-columns: 320px 1fr; gap: 16px; margin-top: 20px; }
.ch-hero .ch-thumb { border-radius: 8px; }
.ch-hero h3 { margin: 0 0 6px; font-size: 16px; }

/* dashboard / settings */
.dash { max-width: 760px; margin: 0 auto; display: grid; gap: 16px; }
.key-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.key-row input { font-family: ui-monospace, monospace; flex: 1; min-width: 200px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 15px; font-weight: 700; margin-top: 2px; }
.notice { font-size: 13px; padding: 8px 12px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); margin-top: 10px; }
.notice.error { border-color: var(--danger); color: #f5a5a5; }
.notice.ok { border-color: var(--ok); color: #a5f5c5; }
.login-panel { display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 8px 12px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; }
.tabpane.active { display: block; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.7; }
.steps li { margin-bottom: 4px; }
.thumb-edit { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.thumb-edit .ch-thumb { width: 240px; border-radius: 6px; }
.avatar-edit { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.list-item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.provider-icon { width: 26px; height: 26px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; flex: none; }
.provider-icon.google { background: #4285f4; }
.provider-icon.discord { background: #5865f2; }
.provider-icon.x { background: #000; border: 1px solid var(--border); }
.provider-icon.dev { background: var(--muted); }

/* game tag / picker */
.game-tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 3px; }
.game-tag img { width: 18px; height: 18px; border-radius: 4px; }
.game-tag.lg { font-size: 13px; padding: 4px 10px 4px 4px; }
.game-tag.lg img { width: 24px; height: 24px; }
.chip img { width: 18px; height: 18px; border-radius: 4px; vertical-align: -4px; margin-right: 4px; }
.game-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 320px; overflow-y: auto; padding: 4px; }
.game-opt { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 4px; border-radius: 8px; border: 2px solid transparent; background: var(--panel-2); cursor: pointer; color: var(--text); font-size: 12px; text-align: center; }
.game-opt img { width: 56px; height: 56px; border-radius: 12px; }
.game-opt .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.game-opt:hover { border-color: var(--border); }
.game-opt.selected { border-color: var(--accent); background: rgba(108,92,231,.15); }
.game-opt.none img { display: none; }
.game-opt.none .ph { width: 56px; height: 56px; border-radius: 12px; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 24px; }
.game-selected { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

/* search / schedule / ranking / history */
.search { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; max-width: 420px; }
.search input { flex: 1; }
.next-stream { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 8px; border-radius: 4px; background: rgba(108,92,231,.15); border: 1px solid rgba(108,92,231,.5); color: var(--text); white-space: nowrap; }
.ch-thumb .next-stream { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.7); border-color: rgba(255,255,255,.2); }
.rank-list { display: flex; flex-direction: column; gap: 6px; }
.rank-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.rank-item:hover { border-color: var(--accent); }
.rank-item .no { width: 32px; font-weight: 700; font-size: 18px; color: var(--muted); text-align: center; flex: none; }
.rank-item.top1 .no { color: #f1c40f; }
.rank-item.top2 .no { color: #bdc3c7; }
.rank-item.top3 .no { color: #cd7f32; }
.rank-item .info { flex: 1; min-width: 0; }
.rank-item .info .t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-item .val { font-weight: 700; font-size: 16px; white-space: nowrap; }
.rank-item .val small { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 400; font-size: 12px; }
.table td.t { white-space: normal; }
.table-wrap { overflow-x: auto; }
.viewer-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.viewer-list .v { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: 13px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; }
.switch .muted { display: block; margin-top: 2px; }

/* toast */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: 340px; }
.toast {
  display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.4); opacity: 0; transform: translateY(10px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast.live { border-color: var(--live); }
a.toast:hover { border-color: var(--accent); }

/* スマホ: 縦一列。プレイヤー上、コメントが残りを占め、入力欄は最下部に固定 */
@media (max-width: 900px) {
  header { flex-wrap: nowrap; gap: 8px; overflow: hidden; }
  header h1 { font-size: 16px; }
  #header-right { flex-wrap: nowrap; min-width: 0; }
  .hdr-user .uname { display: none; }
  .hdr-link { display: none; }
  #header-right .btn { padding: 5px 8px; font-size: 12px; }
  .page-watch header .muted { font-size: 12px; white-space: nowrap; }
  body.page-watch { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
  .watch { flex: 1; min-height: 0; height: auto; display: flex; flex-direction: column; gap: 0; padding: 0; }
  .watch-main { flex: none; overflow: visible; }
  #player-wrap { border-radius: 0; max-height: 56vh; }
  #player-wrap.portrait { aspect-ratio: auto; height: 56vh; }
  .ch-info { padding: 10px 12px; margin: 0; }
  .ch-info .desc { display: none; }
  #chat { flex: 1; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; }
  #chat h3 { display: none; }
  main.dash { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .ch-hero { grid-template-columns: 1fr; }
  .profile-head { flex-wrap: wrap; }
  .profile-actions { margin-left: 0; width: 100%; }
  #toasts { left: 12px; right: 12px; max-width: none; }
}
