:root {
  --bg: #0a0d14;
  --panel: #11161f;
  --panel2: #161d29;
  --line: #222c3a;
  --red: #ff4d5e;
  --blue: #4d9bff;
  --txt: #e6ecf5;
  --mut: #8a97aa;
  --gold: #ffce5a;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: "Segoe UI", system-ui, -apple-system, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

/* --- login --- */
body.login {
  display: flex;
  align-items: center;
  justify-content: center;
}
.loginbox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 26px;
  width: 320px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.loginbox .hint {
  color: var(--mut);
  font-size: 13px;
  margin: 0;
}
.loginbox input {
  background: #0c1019;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--txt);
  padding: 11px 12px;
  font-size: 16px;
  text-align: center;
  letter-spacing: 0.2em;
}
.loginbox button {
  background: linear-gradient(90deg, #ff4d5e, #ff8a72);
  color: #1a0a0d;
  font-weight: 800;
  border: 0;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
  cursor: pointer;
}
.err {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

.brand {
  font-weight: 800;
  letter-spacing: 0.14em;
  font-size: 15px;
}
.brand .live {
  color: var(--red);
  margin-left: 6px;
  font-size: 12px;
  border: 1px solid var(--red);
  border-radius: 4px;
  padding: 1px 6px;
}

.app {
  height: 100vh;
  overflow-y: auto; /* 収まらない画面では全体をスクロール可能に (クロップしない) */
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  box-sizing: border-box;
}
.topbar {
  flex: 0 0 54px;
  background: linear-gradient(90deg, #10151e, #0c1119);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
}
.score {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 auto;
  font-weight: 800;
  font-size: 22px;
}
.score .r {
  color: var(--red);
}
.score .b {
  color: var(--blue);
}
.score .dash {
  color: var(--mut);
}
.meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--mut);
}
.phase {
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.08em;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
}

.mid {
  flex: 1 1 auto;
  min-height: 360px; /* 主画面を実用サイズに保つ。これ未満の画面では .app がスクロール */
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 8px;
}
.stage {
  position: relative;
  background: #05070b;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* 16:9 を維持 (黒帯で letterbox。切れ・潰れ無し) */
  background: #05070b;
}
.cam-status {
  position: absolute;
  top: 12px;
  left: 14px;
  color: var(--mut);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: 5px;
}
.live-dot {
  position: absolute;
  right: 14px;
  top: 12px;
  font-size: 12px;
  color: var(--red);
  font-weight: 700;
}
.live-dot::before {
  content: "\25CF";
  margin-right: 5px;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}
.camlabel {
  position: absolute;
  left: 14px;
  bottom: 12px;
}
.camlabel .tag {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-weight: 800;
  font-size: 14px;
  color: var(--gold);
}
.unmute {
  position: absolute;
  right: 14px;
  bottom: 12px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
}
.banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 800;
  padding: 14px 28px;
  border-radius: 10px;
  font-size: 22px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.banner.big {
  font-size: 34px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
}
.card h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--mut);
  font-weight: 700;
  text-transform: uppercase;
}
.feedcard {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.teamhdr {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  font-size: 12px;
  margin: 8px 0 4px;
}
.teamhdr.red {
  color: var(--red);
}
.teamhdr.blue {
  color: var(--blue);
}
.robot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}
.robot .role {
  width: 76px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--mut);
}
.bar {
  flex: 1;
  height: 12px;
  background: #0c1019;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
}
.red .bar > i {
  background: linear-gradient(90deg, #ff4d5e, #ff8a72);
}
.blue .bar > i {
  background: linear-gradient(90deg, #4d9bff, #62e0ff);
}
.hpnum {
  width: 34px;
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: #cfd8e6;
}
.robot.incapacitated {
  opacity: 0.4;
}
.robot.incapacitated .bar > i {
  filter: grayscale(1) brightness(0.6);
}
.cap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}
.cap .name {
  width: 52px;
  font-size: 12px;
  color: var(--mut);
}
.capbar {
  flex: 1;
  height: 14px;
  background: #0c1019;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}
.capbar > i {
  display: block;
  height: 100%;
}
.cap .pct {
  width: 38px;
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.capstate {
  color: var(--mut);
  font-size: 11px;
  margin-top: 4px;
}
.feed {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ev {
  font-size: 12px;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--panel2);
}
.ev.round {
  background: #1a1406;
  color: var(--gold);
}

/* --- thumbnails rail --- */
.rail {
  flex: 0 0 auto;
  height: clamp(90px, 14vh, 150px);
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.thumbs {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto; /* カメラが多い時だけ横スクロール */
}
.thumb {
  position: relative;
  height: 100%;
  width: 168px;
  flex: 0 0 auto;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  color: var(--txt);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}
.thumb:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.thumb.sel {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.thumb .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.thumb .nm {
  font-weight: 700;
}
.thumb .nm.red {
  color: var(--red);
}
.thumb .nm.blue {
  color: var(--blue);
}
.thumb .cam {
  font-size: 11px;
  color: var(--mut);
  white-space: nowrap;
}
.thumb .cam.on::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--red);
  vertical-align: 1px;
}
.thumb .thumb-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; /* 名前が長い時は枠内に省略表示 */
  font-size: 14px;
  font-weight: 600;
}
.thumb .mini-hp {
  width: 100%;
  height: 5px;
  background: #0c1019;
  border-radius: 3px;
  overflow: hidden;
}
.thumb .mini-hp > i {
  display: block;
  height: 100%;
}
.thumb.incapacitated {
  opacity: 0.45;
}
.thumb.nocam {
  cursor: default; /* 映像の届いていないロボットは選べない */
}
.thumb.map {
  flex: 0 0 auto;
  display: block;
  padding: 0;
  width: 200px;
  height: 100%;
  background: #070b12;
  cursor: default;
}
.maplabel {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 11px;
  color: var(--mut);
  z-index: 2;
}
canvas {
  display: block;
  max-width: 100%;
}
