/* オンライン早押しクイズ 共通スタイル */
:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --panel-2: #f7f8fb;
  --text: #1c2230;
  --muted: #6b7486;
  --line: #dde2ea;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --ok: #18a058;
  --ng: #e5484d;
  --warn: #e8a317;
  --rest: #8e7cc3;
  --buzz: #ff3b5c;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 4px 16px rgba(20, 30, 50, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --panel: #1b2029;
    --panel-2: #222834;
    --text: #e8ecf3;
    --muted: #97a1b3;
    --line: #2e3542;
    --accent: #5b8cff;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.wrap { max-width: 1280px; margin: 0 auto; padding: 12px 16px 120px; }

/* フォーム */
input[type=text], input[type=password], input[type=number], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
input[type=number] { width: 90px; }
textarea { width: 100%; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  transition: transform .05s, background .15s;
  white-space: nowrap;
}
button:hover:not(:disabled) { filter: brightness(1.05); border-color: var(--accent); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
button.ok { background: var(--ok); color: #fff; border-color: transparent; }
button.ng { background: var(--ng); color: #fff; border-color: transparent; }
button.ghost { background: transparent; }
button.tiny { padding: 2px 7px; font-size: 12px; border-radius: 6px; }
kbd {
  font-size: 10px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
  color: var(--muted); margin-left: 4px; background: var(--panel);
}
button.primary kbd, button.ok kbd, button.ng kbd { color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.4); background: transparent; }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 1280px; margin: 0 auto; padding: 8px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 800; letter-spacing: .02em; }
.brand small { font-weight: 500; color: var(--muted); margin-left: 6px; }
.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.live { color: #fff; background: var(--ok); border-color: transparent; }
.badge.warn { color: #000; background: var(--warn); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.on { background: var(--ok); }

/* タブ */
.tabs { display: flex; gap: 4px; margin: 12px 0; overflow-x: auto; }
.tabs button { border-radius: 999px; padding: 6px 14px; }
.tabs button.active { background: var(--accent); color: #fff; border-color: transparent; }

/* ゲーム画面のレイアウト */
.game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; align-items: start; }
@media (max-width: 960px) { .game-grid { grid-template-columns: minmax(0, 1fr); } }

.stage { text-align: center; padding: 18px 14px; }
.stage .phase { font-size: 13px; color: var(--muted); }
.stage .headline { font-size: 26px; font-weight: 800; margin: 6px 0; min-height: 36px; }
.stage .headline .name { padding: 0 6px; border-radius: 6px; }
.queue { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.queue .q { padding: 3px 10px; border-radius: 999px; border: 2px solid var(--line); font-size: 13px; background: var(--panel-2); }
.queue .q.now { border-color: var(--buzz); font-weight: 700; }
.queue .q.out { text-decoration: line-through; opacity: .6; }
.lyric {
  margin: 12px auto 0; max-width: 680px; text-align: left; white-space: pre-wrap;
  font-size: 19px; line-height: 1.8; background: var(--panel-2); border-radius: 10px; padding: 12px 16px; min-height: 60px;
}
.lyric .caret { display: inline-block; width: 2px; height: 1em; background: var(--accent); vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.answer-card { display: flex; gap: 14px; align-items: center; text-align: left; margin: 12px auto 0; max-width: 680px; background: var(--panel-2); border-radius: 10px; padding: 10px; }
.answer-card img { width: 128px; height: 72px; object-fit: cover; border-radius: 6px; background: #000; flex: none; }
.answer-card .t { font-weight: 800; font-size: 18px; word-break: break-all; }

.buzz-wrap { display: flex; justify-content: center; margin: 16px 0 4px; }
.buzz {
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7a8f, var(--buzz) 60%, #b5112c);
  color: #fff; font-size: 30px; font-weight: 900; letter-spacing: .1em;
  border: 6px solid rgba(255,255,255,.6);
  box-shadow: 0 8px 0 #8f0c22, 0 12px 24px rgba(255, 59, 92, .35);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.buzz:active:not(:disabled), .buzz.pressed { transform: translateY(6px); box-shadow: 0 2px 0 #8f0c22, 0 4px 10px rgba(255, 59, 92, .3); }
.buzz:disabled { background: #9aa3b2; box-shadow: 0 8px 0 #6c7380; opacity: 1; filter: grayscale(.3); }
.buzz small { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0; opacity: .9; }
.buzz-note { text-align: center; font-size: 12px; color: var(--muted); }

/* 司会パネル */
.host-panel { border: 2px solid var(--accent); }
.host-answer { background: var(--panel-2); border-radius: 10px; padding: 10px; display: flex; gap: 12px; align-items: flex-start; }
.host-answer img { width: 112px; height: 63px; object-fit: cover; border-radius: 6px; flex: none; background: #000; }
.host-answer .t { font-weight: 800; font-size: 17px; word-break: break-all; }
.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin-top: 10px; }
.controls button { padding: 10px 8px; font-weight: 700; }
.judge { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.judge button { padding: 14px; font-size: 18px; font-weight: 800; }

/* 得点表 */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pcard {
  position: relative; border-radius: 12px; padding: 10px 10px 8px; background: var(--panel);
  border: 3px solid var(--pc, var(--line)); box-shadow: var(--shadow); text-align: center;
}
.pcard.offline { opacity: .5; }
.pcard.answering { box-shadow: 0 0 0 4px var(--buzz), var(--shadow); }
.pcard.win { background: linear-gradient(180deg, rgba(232,163,23,.18), var(--panel)); }
.pcard.lose { background: linear-gradient(180deg, rgba(229,72,77,.14), var(--panel)); }
.pcard.resting { background: linear-gradient(180deg, rgba(142,124,195,.16), var(--panel)); }
.pcard .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .pts { font-size: 34px; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pcard .ox { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pcard .ox .o { color: var(--ok); font-weight: 700; }
.pcard .ox .x { color: var(--ng); font-weight: 700; }
.pcard .tag { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-size: 11px; padding: 0 8px; border-radius: 999px; color: #fff; white-space: nowrap; }
.pcard .tag.win { background: var(--warn); color: #000; }
.pcard .tag.lose { background: var(--ng); }
.pcard .tag.rest { background: var(--rest); }
.pcard .tag.rank { background: var(--buzz); }
.pcard .icon { position: absolute; top: 4px; right: 6px; font-size: 13px; }
.pcard .on { position: absolute; top: 8px; left: 8px; }
.pcard .adj { margin-top: 6px; display: grid; grid-template-columns: auto 1fr auto; gap: 2px 4px; align-items: center; font-size: 12px; }
.pcard .adj span { color: var(--muted); }
.pcard .adj button { padding: 0 6px; font-size: 12px; }

/* チャット */
.chat { display: flex; flex-direction: column; height: min(70vh, 640px); }
.chat .log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
.chat .m { font-size: 14px; word-break: break-word; }
.chat .m .who { font-weight: 700; margin-right: 6px; }
.chat .m.system { color: var(--muted); font-size: 12px; text-align: center; }
.chat .m.answer { background: rgba(255, 59, 92, .12); border-left: 3px solid var(--buzz); padding: 2px 6px; border-radius: 4px; }
.chat .m.host .who::after { content: "司会"; font-size: 10px; margin-left: 4px; padding: 0 4px; border-radius: 4px; background: var(--accent); color: #fff; font-weight: 600; }
.chat form { display: flex; gap: 6px; margin-top: 8px; }
.chat form input { flex: 1; }

/* 着差・観戦・ミュート */
.pcard .diff { font-size: 12px; font-weight: 700; color: var(--buzz); font-variant-numeric: tabular-nums; min-height: 16px; }
.pcard .mute { padding: 0 4px; font-size: 12px; border-radius: 6px; margin-top: 2px; }
.queue .q .d { font-size: 11px; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.spectators { margin-top: 10px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.spectators .sp { padding: 2px 8px; border-radius: 999px; border: 2px solid var(--pc, var(--line)); background: var(--panel-2); color: var(--text); display: inline-flex; gap: 4px; align-items: center; }
.spectators .sp.offline { opacity: .5; }
.spectators .sp button { padding: 0 4px; font-size: 11px; }
button.on { background: var(--accent); color: #fff; border-color: transparent; }

/* チーム戦 */
.teams { display: flex; flex-direction: column; gap: 12px; }
.team { border: 3px solid var(--tc, var(--line)); border-radius: 14px; padding: 10px; background: linear-gradient(180deg, color-mix(in srgb, var(--tc) 10%, transparent), transparent 70%); }
.team.win { box-shadow: 0 0 0 3px var(--warn); }
.team.lose { opacity: .7; }
.team-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.team-head .tn { font-weight: 900; font-size: 17px; color: var(--tc); }
.team-head .tp { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; }
.team-head .tox { font-size: 13px; color: var(--muted); }
.team .board { min-height: 40px; }
.team-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.team-row input[type=text] { flex: 1; min-width: 120px; }
.pcard select { font-size: 11px; padding: 2px; margin-top: 4px; width: 100%; }
.pcard.locked { filter: grayscale(.6); }
.pcard .hosttag { font-size: 10px; background: var(--accent); color: #fff; border-radius: 4px; padding: 0 4px; margin-left: 4px; }

/* スタンプ */
.stamp-bar { display: flex; gap: 4px; margin-top: 8px; }
.stamp-bar button { flex: 1; font-size: 20px; padding: 4px 0; line-height: 1.2; }
.stamp-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.stamp-fly { position: absolute; bottom: 8%; display: flex; flex-direction: column; align-items: center; animation: stamp-up 2.6s ease-out forwards; }
.stamp-fly .e { font-size: 56px; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.stamp-fly .n { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; color: #fff; margin-top: 2px; white-space: nowrap; }
@keyframes stamp-up {
  0% { transform: translateY(30px) scale(.4); opacity: 0; }
  12% { transform: translateY(0) scale(1.15); opacity: 1; }
  22% { transform: translateY(-10px) scale(1); }
  80% { opacity: 1; }
  100% { transform: translateY(-46vh) scale(.9); opacity: 0; }
}

/* 設定画面 */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.years { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.years label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); }
.years input { width: 100%; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.presets button.active { background: var(--accent); color: #fff; border-color: transparent; }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatches button { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.swatches button.sel { border-color: var(--text); }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }

/* 履歴 */
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history td, .history th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.history th { color: var(--muted); font-weight: 600; font-size: 12px; }

/* 入室・トースト・モーダル */
.center-card { max-width: 440px; margin: 8vh auto; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: #222b3a; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.error { background: var(--ng); }
.banner { background: var(--warn); color: #000; padding: 8px 14px; border-radius: 10px; margin-top: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner.info { background: var(--panel); color: var(--text); border: 1px solid var(--accent); }

/* ロビー */
.room-list { display: grid; gap: 10px; }
.room-item { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.room-item:hover { border-color: var(--accent); }
.room-item .nm { font-weight: 800; font-size: 17px; }

.badge { white-space: nowrap; }
#room-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

/* スマホ: 早押しボタンを画面下いっぱいの横長ボタンにして固定 */
@media (max-width: 700px) {
  .wrap { padding: 8px 10px 130px; }
  .topbar .inner { padding: 6px 10px; gap: 6px; }
  #room-name { max-width: 60vw; }
  .topbar .inner > .grow { flex: 1 1 calc(100% - 90px); }
  #host-buttons { width: 100%; justify-content: space-between; }
  .buzz-wrap.sticky-mobile { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; z-index: 30; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
  .buzz-wrap.sticky-mobile .buzz { width: 100%; height: 88px; border-radius: 18px; font-size: 28px; box-shadow: 0 6px 0 #8f0c22; }
  .buzz-wrap.sticky-mobile .buzz:disabled { box-shadow: 0 6px 0 #6c7380; }
  .buzz-wrap.sticky-mobile .buzz small { display: none; }
  /* ゲーム画面をコンパクトに(大人数でもスクロールを減らす) */
  .tabs { margin: 8px 0; }
  .tabs button { padding: 4px 10px; font-size: 13px; }
  .panel { padding: 10px; border-radius: 10px; }
  .game-grid, #tab-game .col { gap: 8px !important; }
  .stage { padding: 8px 10px; }
  .stage .phase { font-size: 11px; }
  .stage .headline { font-size: 18px; margin: 2px 0; min-height: 0; }
  .lyric { font-size: 16px; line-height: 1.6; padding: 8px 10px; margin-top: 6px; }
  .answer-card { margin-top: 6px; padding: 6px; gap: 8px; }
  .answer-card img { width: 80px; height: 45px; }
  .answer-card .t { font-size: 15px; }
  .buzz-note { font-size: 11px; }
  .section-title { margin-bottom: 6px; }
  .section-title h2 { font-size: 14px; }
  .board { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
  .pcard { padding: 6px 4px 4px; border-width: 2px; border-radius: 10px; }
  .pcard .nm { font-size: 12px; }
  .pcard .pts { font-size: 22px; }
  .pcard .ox { font-size: 11px; }
  .pcard .diff { font-size: 10px; min-height: 0; }
  .pcard .diff:empty, .pcard .mute { display: none; }
  .pcard .icon { font-size: 10px; top: 2px; right: 3px; }
  .pcard .tag { font-size: 10px; top: -8px; }
  .team { padding: 6px; border-width: 2px; }
  .team-head { margin-bottom: 4px; gap: 6px; }
  .team-head .tp { font-size: 20px; }
  .chat { height: 38vh; }
  .stamp-bar button { font-size: 16px; padding: 2px 0; }
  /* チャット入力を画面下(早押しボタンの上)に固定して、スクロールせずにチャット回答できるようにする */
  #chat-form { position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom)); z-index: 31; margin: 0;
    padding: 6px 10px; background: var(--bg); border-top: 1px solid var(--line); }
  body.has-buzz #chat-form { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .buzz-wrap.sticky-mobile { padding-top: 6px; }
  .buzz-wrap.sticky-mobile .buzz { height: 66px; font-size: 24px; }
  .wrap { padding-bottom: 170px; }
}

/* コピー用ダイアログ(httpのページで自動コピーできないとき) */
.copy-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.copy-dialog { width: min(560px, 100%); }

/* リーチ(次に正解したら勝ち抜け) */
.pcard.reach { box-shadow: 0 0 0 3px #ff8a3d, 0 0 14px rgba(255, 138, 61, .55); animation: reach-glow 1.4s ease-in-out infinite; }
.pcard.reach.answering { box-shadow: 0 0 0 4px var(--buzz), 0 0 14px rgba(255, 138, 61, .55); }
.pcard .tag.reach, .badge.reach { background: #ff8a3d; color: #fff; border-color: transparent; font-weight: 800; }
@keyframes reach-glow { 50% { box-shadow: 0 0 0 3px #ff8a3d, 0 0 22px rgba(255, 138, 61, .9); } }

/* ボード回答 */
.ab-list { display: flex; flex-direction: column; gap: 6px; }
.ab-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--line); border-left: 5px solid var(--pc, var(--line)); border-radius: 8px; }
.ab-row.ok { background: rgba(24, 160, 88, .10); }
.ab-row.ng { background: rgba(255, 92, 122, .10); }
.ab-row .abn { font-weight: 700; min-width: 5em; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ab-row .abt { flex: 1; font-size: 1.1em; word-break: break-all; }
.ab-row .abm { font-weight: 900; font-size: 1.2em; }
.ab-row .abm.ok { color: var(--ok); }
.ab-row .abm.ng { color: var(--ng); }
.pcard .streak { color: #ff8a3d; font-weight: 800; }

/* スマホの司会パネル: 小さく・簡潔に(答え・○×・主要ボタンだけを詰めて表示) */
@media (max-width: 700px) {
  .host-panel { padding: 8px; border-width: 2px; }
  .host-panel .section-title { margin-bottom: 4px; }
  .host-panel .section-title h2 { display: none; }
  #host-status { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .host-answer { padding: 6px; gap: 8px; }
  .host-answer img { width: 64px; height: 36px; }
  .host-answer .t { font-size: 14px; }
  .host-answer .cap, .host-answer .meta { display: none; }
  .host-answer .small { font-size: 11px; }
  .host-answer .mylist-from { font-size: 10px; }
  .judge { gap: 6px; margin-top: 6px; }
  .judge button { padding: 8px; font-size: 15px; }
  .controls { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-top: 6px; }
  .controls button { padding: 6px 2px; font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .host-panel kbd { display: none; }
  .stamp-bar { gap: 2px; }
  .stamp-bar button { font-size: 15px; padding: 2px 0; }
}
