:root {
  --bg: #0f0f1a;
  --panel: #1b1b2e;
  --panel-2: #26263f;
  --text: #f2f2f7;
  --muted: #9a9ab5;
  --accent: #ff4f8b;
  --accent-2: #ffb347;
  --danger: #ff5c5c;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

button {
  border: 0;
  border-radius: 999px;
  background: var(--panel-2);
  padding: 0.5em 1em;
  cursor: pointer;
}
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: #fff; font-weight: 700; }
button.icon { width: 2.4em; height: 2.4em; padding: 0; display: inline-grid; place-items: center; }
button:disabled { opacity: 0.4; cursor: default; }

input[type="text"], input[type="search"] {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.7em 0.9em;
  outline: none;
}
input:focus { border-color: var(--accent); }

.muted { color: var(--muted); }
.badge {
  display: inline-block;
  font-size: 0.72em;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.badge.youtube { background: #3a1616; color: #ff8080; }
.badge.niconico { background: #2a2a2a; color: #e0e0e0; }
.badge.key { background: #3a3016; color: var(--accent-2); font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6em 1.2em;
  border-radius: 999px;
  font-weight: 600;
  z-index: 100;
  max-width: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast button { background: var(--accent); color: #fff; font-weight: 700; padding: 0.3em 0.9em; white-space: nowrap; }

/* ---------- トップ ---------- */
.home {
  max-width: 420px;
  margin: 0 auto;
  padding: 12vh 16px 32px;
  display: grid;
  gap: 20px;
  text-align: center;
}
.home h1 { font-size: 2.2em; margin: 0; }
.home h1 span { color: var(--accent); }
.home .card { background: var(--panel); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.home .card h2 { margin: 0; font-size: 1.05em; }
.home input[type="text"] { text-align: center; font-size: 1.6em; letter-spacing: 0.2em; text-transform: uppercase; }
.home input[type="text"]::placeholder { letter-spacing: normal; font-size: 0.6em; }
.check { display: flex; gap: 8px; align-items: flex-start; text-align: left; font-size: 0.9em; cursor: pointer; }
.check input { margin-top: 0.25em; accent-color: var(--accent); }

/* ---------- 歌唱UI ---------- */
.stage { height: 100vh; display: grid; grid-template-rows: 1fr auto; overflow: hidden; }
.stage-screen { position: relative; background: #000; min-height: 0; }
.stage-player, .stage-player iframe { width: 100%; height: 100%; border: 0; display: block; }
.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  text-align: center;
  background: radial-gradient(circle at 50% 30%, #2b1b3d, var(--bg));
  padding: 16px;
}
.stage-overlay h1 { margin: 0; font-size: clamp(1.6em, 4vw, 3em); }
.stage-overlay .code { font-size: clamp(3em, 10vw, 7em); font-weight: 800; letter-spacing: 0.15em; color: var(--accent-2); line-height: 1; }
.stage-overlay img.qr { width: min(36vh, 60vw); background: #fff; border-radius: var(--radius); padding: 8px; }
.stage-overlay button.primary { font-size: 1.5em; padding: 0.6em 1.6em; }
.stage-message {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  padding: 0.6em 1.2em;
  border-radius: 999px;
}
.stage-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  font-size: clamp(0.9em, 1.6vw, 1.3em);
}
.stage-bar .now { flex: 1; min-width: 0; }
.stage-bar .next { flex: 1; min-width: 0; color: var(--muted); }
.stage-bar .label { font-size: 0.7em; color: var(--muted); display: block; }
.stage-bar .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.stage-bar .singer { color: var(--accent-2); font-weight: 700; }
.stage-bar .join { display: flex; align-items: center; gap: 10px; }
.stage-bar .join button { font-size: 0.8em; white-space: nowrap; }
.stage-bar .badge { margin-left: 6px; vertical-align: middle; }
.overlay-sub { margin: 0; font-size: clamp(1em, 2vw, 1.5em); }
.overlay-sub .singer { color: var(--accent-2); font-weight: 700; }
body.idle, body.idle * { cursor: none !important; }

/* 配信者モード：ルームコード・QRコード・予約URLを出さない */
.stream-mode .secret { display: none !important; }
body:not(.stream-mode) .stream-only { display: none !important; }
#stream-toggle.on { background: #1f3a2a; color: #7fe0a8; }

.stage-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 92vw);
  background: rgba(15, 15, 26, 0.94);
  backdrop-filter: blur(6px);
  border-left: 1px solid var(--panel-2);
  padding: 12px 16px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  z-index: 5;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h2 { margin: 0; font-size: 1.1em; }
.panel-help { font-size: 0.75em; text-align: center; margin: 4px 0 0; }
.stage-bar .join img { width: 64px; height: 64px; background: #fff; border-radius: 6px; padding: 3px; }
.stage-bar .join b { font-size: 1.5em; letter-spacing: 0.1em; color: var(--accent-2); }

/* ---------- 予約UI ---------- */
.remote { max-width: 640px; margin: 0 auto; padding: 0 16px 80px; }
.remote header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.remote header .room { font-weight: 800; color: var(--accent-2); letter-spacing: 0.1em; }
.remote header .name { margin-left: auto; width: 9em; padding: 0.4em 0.7em; }
.status { font-size: 0.8em; color: var(--danger); }

.now-card {
  background: linear-gradient(135deg, #3a1f4a, var(--panel));
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
}
.now-card .controls { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.break-card { text-align: center; display: grid; gap: 6px; justify-items: center; padding: 8px; }
.break-card .break-title { font-size: 1.3em; font-weight: 800; }
.break-card p { margin: 0; font-size: 0.85em; }

.key-picker {
  background: var(--panel);
  border: 1px solid var(--accent-2);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 8px;
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.picker-head { display: flex; align-items: center; gap: 8px; }
.picker-head .icon { margin-left: auto; }
.picker-note { margin: 0; font-size: 0.78em; }
.key-picker .item { background: var(--panel-2); }

.tabs { display: flex; gap: 6px; margin: 14px 0 10px; }
.tabs button { flex: 1; }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); font-weight: 700; }

.search-form { display: flex; gap: 8px; margin-bottom: 8px; }
.search-form input { flex: 1; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px;
}
.item img { width: 96px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; background: #000; display: block; }
.item .body { min-width: 0; }
.item .title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 0.92em; }
.item .meta { font-size: 0.78em; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item .actions { display: flex; gap: 4px; }
.item.mine { outline: 1px solid var(--accent); }
.item .num { font-weight: 800; color: var(--accent-2); margin-right: 4px; }
.empty { text-align: center; color: var(--muted); padding: 32px 0; }

@media (max-width: 420px) {
  .item img { width: 72px; }
  .item { grid-template-columns: auto 1fr; }
  .item .actions { grid-column: 1 / -1; justify-content: flex-end; }
}
