:root {
  color-scheme: dark;
  --bg: #0f0d14;
  --card: #1b1823;
  --line: #312b3d;
  --text: #eeeaf4;
  --muted: #9f97b0;
  --accent: #e0409a;
  --ok: #2fbf7f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
}
h1 { font-size: 22px; margin: 0; letter-spacing: 0.08em; }
h1 .sub { color: var(--muted); font-size: 13px; font-weight: normal; letter-spacing: 0.02em; margin-left: 10px; }
h2 { font-size: 13px; margin: 0 0 10px; letter-spacing: 0.08em; color: var(--accent); }

.conn { display: flex; align-items: center; gap: 10px; }
.badge { font-size: 12px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.badge.on { color: var(--ok); border-color: var(--ok); }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 18px;
  padding: 18px 24px;
  max-width: 1500px;
  margin: 0 auto;
}
@media (max-width: 1000px) { main { grid-template-columns: minmax(0, 1fr); } }

.stageCol, .sideCol { display: grid; gap: 12px; align-content: start; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
}

button, select, input[type="number"], input[type="text"], .fileBtn {
  font: inherit;
  color: var(--text);
  background: #28233a;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
}
button, .fileBtn { cursor: pointer; }
button:hover:not(:disabled), .fileBtn:hover { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: #9c2c44; color: #ff8fa3; }
button.small { padding: 2px 8px; font-size: 12px; }
button.wide { min-width: 96px; }
input[type="number"], input[type="text"], select { padding: 4px 8px; width: 100%; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* ---- 動画ソース ---- */
.sourceBar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; }
.tab { padding: 4px 14px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; color: var(--muted); }
.tab input { accent-color: var(--accent); }
.tab:has(input:checked) { border-color: var(--accent); color: var(--text); }
.srcPanel { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.srcPanel[hidden] { display: none; }
.srcPanel input[type="text"] { flex: 1; min-width: 120px; }
/* 再生ボタンは動画の上に置き、スクロールせずに押せるようにする */
.playButtons { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.srcInfo { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- ステージ ---- */
.stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.stage.dragover { outline: 3px dashed var(--accent); outline-offset: -8px; }
.stage video, .ytHost { display: none; position: absolute; inset: 0; width: 100%; height: 100%; }
.stage video { object-fit: contain; }
.ytHost iframe { width: 100%; height: 100%; border: 0; display: block; }
.stage[data-tab="file"][data-file="loaded"] video { display: block; }
.stage[data-tab="youtube"][data-yt="loaded"] .ytHost { display: block; }

.hint {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); text-align: center;
}
.hint p { margin: 4px 0; }
.hint .small { font-size: 12px; }
.stage[data-tab="file"] .hintYt, .stage[data-tab="youtube"] .hintFile { display: none; }
.stage[data-tab="file"][data-file="loaded"] .hint,
.stage[data-tab="youtube"][data-yt="loaded"] .hint { display: none; }
.fileBtn { display: inline-block; white-space: nowrap; }

/* フリの表示は動画の外に置く。YouTube のプレーヤーには要素を重ねないため */
.hud { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; }
.cueBox {
  height: 120px;
  background: #0a0910;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.bigArrow {
  font-size: 72px; font-weight: bold; line-height: 1; height: 76px;
  opacity: 0.12;
  text-shadow: 0 0 18px currentColor;
  transition: opacity 0.1s;
}
.bigArrow.on { opacity: 1; }
.nextCue { font-size: 12px; color: var(--muted); height: 18px; }
.judge { font-size: 13px; font-weight: bold; height: 18px; letter-spacing: 0.06em; }
.judge.perfect { color: #ffd23f; text-shadow: 0 0 12px currentColor; }
.judge.great { color: #00ff78; }
.judge.good { color: #00b4ff; }
.judge.wrong { color: #ff9f40; }
.judge.miss { color: #ff6b8a; }

/* 採点モード: フリの矢印と判定を動画の中央に重ねる。動画の操作を邪魔しないようクリックは通す */
.stageCue {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.stageCue[hidden] { display: none; }
.stageCue .bigArrow {
  font-size: clamp(90px, 16vw, 180px); height: auto;
  opacity: 0;
  text-shadow: 0 0 24px currentColor, 0 0 4px #000;
}
.stageCue .bigArrow.on { opacity: 1; }
.stageCue .judge {
  font-size: clamp(22px, 3.2vw, 40px); height: auto; min-height: 1.2em;
  text-shadow: 0 0 14px currentColor, 0 2px 4px #000;
}

/* ---- ゲーム風の矢印と判定（SVG） ---- */
.arrowArt { display: block; width: 1em; height: 1em; overflow: visible; }
.bigArrow.on .arrowArt, .swingSeen.fresh .arrowArt { filter: drop-shadow(0 0 10px currentColor); }
/* 動画の上の矢印は、出るときに少し大きくしてから収める */
.stageCue .bigArrow.on .arrowArt {
  filter: drop-shadow(0 0 22px currentColor) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
  animation: arrowIn 0.22s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
@keyframes arrowIn { from { transform: scale(1.35); } to { transform: scale(1); } }

.stageCue .judge.art { width: min(78%, 560px); min-height: 0; }
.judgeArt {
  display: block; width: 100%; height: auto; overflow: visible;
  filter: drop-shadow(0 0 16px var(--glow)) drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
  animation: judgePop 0.85s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes judgePop {
  0%   { transform: scale(2.1); opacity: 0; }
  18%  { transform: scale(0.94); opacity: 1; }
  30%  { transform: scale(1.04); }
  42%, 78% { transform: scale(1); opacity: 1; }
  100% { transform: translateY(-10%) scale(1); opacity: 0; }
}
/* MISS と方向ちがいは、弾ませずに上から落ちてくる */
.judgeArt.miss, .judgeArt.wrong { animation-name: judgeDrop; animation-timing-function: ease-out; }
@keyframes judgeDrop {
  0%   { transform: translateY(-35%); opacity: 0; }
  22%  { transform: translateY(0); opacity: 1; }
  30%  { transform: translateY(-4%); }
  40%, 78% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(12%); opacity: 0; }
}
/* ---- 対戦 ---- */
:root { --p1: #ff4d6d; --p2: #3da5ff; }

/* 動画の上: 1P を左、2P を右に。真ん中はフリの矢印 */
.vsJudges {
  position: absolute; inset: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 2%;
}
/* 勝敗を出している間は、点数を下に寄せて勝敗の絵と重ならないようにする */
.vsJudges.final { align-items: flex-end; padding-bottom: 5%; }
.vsSide { width: 34%; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.vsSide .vsTag {
  font: 900 clamp(22px, 3.4vw, 42px) / 1 "Arial Black", "Segoe UI Black", Impact, sans-serif;
  font-style: italic; letter-spacing: 0.02em;
  -webkit-text-stroke: 1.5px #140c1c;
  text-shadow: 0 0 12px currentColor, 0 3px 4px rgba(0, 0, 0, 0.7);
}
.vsSide.p1 .vsTag { color: var(--p1); }
.vsSide.p2 .vsTag { color: var(--p2); }
.vsSide .vsTag span { color: #fff; margin-left: 0.2em; }
.vsName { font-size: 11px; color: #fff; opacity: 0.8; text-shadow: 0 1px 3px #000; height: 1.3em; }
.vsJudge { width: 100%; min-height: 4em; }
.vsJudge .judgeArt { width: 100%; }

/* 勝敗は画面いっぱいに大きく出し、消さずに残す */
.vsResult {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(10, 8, 16, 0.55), rgba(10, 8, 16, 0) 70%);
}
.vsResult .judgeArt { width: min(82%, 720px); animation: resultPop 0.9s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
@keyframes resultPop {
  0%   { transform: scale(2.6); opacity: 0; }
  30%  { transform: scale(0.92); opacity: 1; }
  45%  { transform: scale(1.04); }
  60%, 100% { transform: scale(1); opacity: 1; }
}
.vsResult .judgeArt .star { animation-iteration-count: infinite; animation-duration: 1.6s; }

/* 左の枠: 2人ぶん並べるので広げる */
.hud.versus { grid-template-columns: 200px minmax(0, 1fr); }
.vsSeen { display: flex; gap: 6px; width: 100%; padding: 0 6px; }
.vsPanel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center;
  border-top: 3px solid; border-radius: 4px; padding-top: 2px;
}
.vsPanel.p1 { border-color: var(--p1); }
.vsPanel.p2 { border-color: var(--p2); }
.vsPanel .vsTag { font-weight: 900; font-size: 12px; line-height: 14px; }
.vsPanel.p1 .vsTag { color: var(--p1); }
.vsPanel.p2 .vsTag { color: var(--p2); }
.vsArrow { font-size: 44px; height: 48px; display: flex; align-items: center; opacity: 0.4; transition: opacity 0.4s; }
.vsArrow.fresh { opacity: 1; transition: none; }
.vsArrow.fresh .arrowArt { filter: drop-shadow(0 0 8px currentColor); }
.vsText { font-size: 12px; font-weight: bold; height: 16px; color: var(--muted); white-space: nowrap; }
.hud.versus .nextCue { margin-top: 4px; }

/* 採点の欄 */
.versusTargets .slot, .player .slot { font-weight: 900; }
.versusTargets .p1 .slot { color: var(--p1); }
.versusTargets .p2 .slot { color: var(--p2); }
.player .slot { color: var(--slot); }
.player.lead .rank { border-color: var(--slot); }
.vsResultText { font-size: 18px; font-weight: 900; margin: 6px 0; }

/* PERFECT のきらめき */
.judgeArt .star { transform-box: fill-box; transform-origin: center; animation: twinkle 0.85s ease-out both; }
.judgeArt .s1 { animation-delay: 0.06s; }
.judgeArt .s2 { animation-delay: 0.12s; }
.judgeArt .s3 { animation-delay: 0.18s; }
@keyframes twinkle {
  0% { opacity: 0; scale: 0.2; rotate: 0deg; }
  35% { opacity: 1; scale: 1.2; }
  100% { opacity: 0; scale: 0.6; rotate: 90deg; }
}
/* YouTube の採点では、左の枠に「自分が振った向き・判定・次のフリ」を詰めて出す */
.cueBox.compact .swingSeen { font-size: 58px; height: 62px; }
.cueBox.compact .judge { font-size: 14px; }

/* 採点モードの左の枠: 自分が振った向き */
.swingSeen {
  font-size: 72px; font-weight: bold; line-height: 1; height: 76px;
  color: var(--muted); opacity: 0.35;
  transition: opacity 0.4s, text-shadow 0.4s;
}
.swingSeen.fresh { opacity: 1; text-shadow: 0 0 18px currentColor; transition: none; }
.swingWho { font-size: 12px; height: 18px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }

/* display を指定した要素にも hidden を効かせる */
[hidden] { display: none !important; }

.scoreTarget { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.scoreTarget select { flex: 1; min-width: 0; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player { display: grid; grid-template-columns: 34px 1fr; gap: 8px; align-items: center; }
.player .meta.result { color: var(--text); }
.player .rank {
  font-size: 20px; font-weight: bold; text-align: center; line-height: 30px;
  border: 1px solid var(--line); border-radius: 6px; color: var(--muted);
}
.player.done .rank { border-color: currentColor; }
.player .rankS { color: #ffd23f; }
.player .rankA { color: #00ff78; }
.player .rankB { color: #00b4ff; }
.player .rankC { color: #c0b7d0; }
.player .rankD, .player .rankE { color: #ff9f40; }
.player .name { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.player .meta { color: var(--muted); font-size: 11px; display: block; font-family: inherit; }
.player .bar { grid-column: 2; height: 4px; background: #0b0a10; border-radius: 2px; overflow: hidden; }
.player .bar span { display: block; height: 100%; border-radius: 2px; }

.lane {
  width: 100%;
  height: 120px;
  background: #0a0910;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.transport { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.transport label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.transport select { width: auto; }
.time { font-family: ui-monospace, Consolas, monospace; min-width: 170px; }
.modes { display: flex; gap: 4px; margin-left: auto; }
.mode { padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.mode input { accent-color: var(--accent); }
.mode:has(input:checked) { border-color: var(--accent); color: var(--text); }
.keys { margin: 0; color: var(--muted); font-size: 12px; }
kbd {
  font-family: ui-monospace, Consolas, monospace; font-size: 11px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 5px; margin: 0 1px; color: var(--text);
}

/* ---- サイド ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
.grid2 label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline output { min-width: 28px; color: var(--text); font-family: ui-monospace, Consolas, monospace; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; }

.devices { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.devices .empty { color: var(--muted); font-size: 13px; }
.dev {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.dev .dot { width: 10px; height: 10px; border-radius: 50%; }
.dev .name { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.dev .meta { color: var(--muted); font-size: 11px; display: block; }
.dev .via {
  font-family: system-ui, sans-serif; font-size: 10px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px;
}

.bridge { margin-bottom: 12px; }
.bridgeHead { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.bridgeHead .badge { margin-right: auto; }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.note code {
  display: block; margin-top: 4px; padding: 4px 8px; border-radius: 4px;
  background: #0b0a10; color: var(--text); font-family: ui-monospace, Consolas, monospace; font-size: 11px;
  overflow-x: auto; white-space: nowrap;
}
.scanResult { margin-top: 8px; padding: 8px; border: 1px dashed var(--line); border-radius: 6px; }
.found { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 2px; }
.found label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.found label:hover { background: #231f2e; }
.found input { accent-color: var(--accent); }
.found .name { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.found .meta { color: var(--muted); font-size: 11px; margin-left: auto; }

.cueHead, .cue {
  display: grid;
  grid-template-columns: 76px 1fr 66px 52px 24px;
  gap: 6px;
  align-items: center;
}
.cueHead { color: var(--muted); font-size: 11px; padding: 0 4px; }
.cues { list-style: none; margin: 4px 0 0; padding: 0; max-height: 360px; overflow: auto; }
.cue { padding: 3px 4px; border-radius: 4px; }
.cue:hover { background: #231f2e; }
.cue.sel { background: #3a2140; }
.cue .t { font-family: ui-monospace, Consolas, monospace; font-size: 12px; cursor: pointer; text-decoration: underline dotted var(--muted); }
.cue input, .cue select { padding: 2px 4px; font-size: 12px; }
.cue button { padding: 0 6px; font-size: 12px; }
.cuesEmpty { color: var(--muted); font-size: 12px; padding: 8px 4px; }

pre#log {
  background: #0b0a10;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
  height: 140px;
  overflow: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  white-space: pre-wrap;
}
