* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #030712;
  color: #e2e8f0;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", sans-serif;
}

#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: pointer;
}

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 260px;
  padding: 14px 14px 12px;
  background: rgba(8, 13, 26, 0.74);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.35;
  backdrop-filter: blur(4px);
  pointer-events: none;
}

#hud h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #86EFAC;
  letter-spacing: 0.5px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.12);
}

.row .k {
  color: #94a3b8;
}

.row .v {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip {
  display: inline-block;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
}

.stack {
  display: flex;
  gap: 5px;
}

.stack .chip {
  width: 16px;
  height: 16px;
}

.stack .chip.active {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

#log {
  position: fixed;
  bottom: 45px;
  left: 14px;
  width: 340px;
  font-size: 11px;
  color: #cbd5e1;
  pointer-events: none;
}

#log div {
  padding: 2px 0;
  opacity: 0.9;
}

#log div:first-child {
  color: #fde68a;
}

#hint {
  position: fixed;
  bottom: 45px;
  right: 14px;
  font-size: 12px;
  color: #94a3b8;
  text-align: right;
  pointer-events: none;
  line-height: 1.6;
}

#hint kbd {
  background: #1e293b;
  border: 1px solid #334155;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: 700;
  color: #e2e8f0;
}

#banner {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
  padding: 14px 30px;
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.82);
  border: 1px solid rgba(226, 232, 240, 0.25);
  font-weight: 800;
  font-size: 18px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

#banner.hidden {
  display: none;
}

#title {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #94a3b8;
  pointer-events: none;
}

/* 畫面正下方：擊中層數 + 黃水 */
#statusbar {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  align-items: flex-end;
  pointer-events: none;
}

#statusbar .box {
  background: rgba(2, 6, 23, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 12px;
  padding: 8px 18px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#statusbar .box.danger {
  border-color: rgba(239, 68, 68, 0.8);
  box-shadow: 0 0 18px rgba(239, 68, 68, 0.45);
}

#statusbar .lab {
  font-size: 11px;
  color: #94a3b8;
}

#statusbar .big {
  font-size: 22px;
  font-weight: 800;
  margin-top: 3px;
}

#statusbar .pips {
  display: flex;
  gap: 7px;
  justify-content: center;
  margin-top: 5px;
}

#statusbar .pip {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #64748b;
}

#statusbar .pip.on {
  background: #ef4444;
  border-color: #fecaca;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.7);
}

#statusbar .hpbar {
  display: flex;
  gap: 3px;
  justify-content: center;
  margin-top: 5px;
}

#statusbar .hpseg {
  width: 13px;
  height: 11px;
  border-radius: 2px;
  background: #334155;
}

#statusbar .hpseg.on {
  background: #22c55e;
  box-shadow: 0 0 5px rgba(34, 197, 94, 0.5);
}

#statusbar .hpseg.low {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

/* 打到別人的球：跳出視窗 */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  cursor: pointer;
}

#modal.hidden {
  display: none;
}

#modal .modal-box {
  background: #1a0c12;
  border: 2px solid #ef4444;
  border-radius: 16px;
  padding: 30px 44px;
  text-align: center;
  box-shadow: 0 0 44px rgba(239, 68, 68, 0.55);
  max-width: 80vw;
}

#modal .modal-title {
  font-size: 30px;
  font-weight: 900;
  color: #fca5a5;
  letter-spacing: 1px;
}

#modal .modal-sub {
  margin-top: 14px;
  font-size: 14px;
  color: #cbd5e1;
  line-height: 1.7;
}

/* 成績統計面板 */
#stats {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 216px;
  padding: 12px 14px;
  background: rgba(8, 13, 26, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  font-size: 12px;
  backdrop-filter: blur(4px);
}

#stats h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #86EFAC;
  letter-spacing: 0.5px;
}

#stats .srow {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  color: #94a3b8;
}

#stats .srow b {
  color: #e2e8f0;
}

#stats #fail-row {
  cursor: pointer;
}

#stats #fail-break {
  margin: 2px 0 4px 6px;
  padding-left: 8px;
  border-left: 2px solid rgba(239, 68, 68, 0.4);
}

#stats .brow {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  color: #fca5a5;
  font-size: 11px;
}

#stats .gone {
  display: none;
}

#stats button {
  margin-top: 9px;
  width: 100%;
  padding: 7px;
  border-radius: 8px;
  border: 1px solid #21B858;
  background: #86EFAC;
  color: #06281A;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
}

#stats button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  border-color: #475569;
  background: #1e293b;
  color: #94a3b8;
}

/* 成绩单 */
#cert {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  z-index: 80;
}

#cert.hidden {
  display: none;
}

#cert canvas {
  max-width: 92vw;
  max-height: 70vh;
  border-radius: 14px;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.6);
}

#cert .cert-btns {
  display: flex;
  gap: 12px;
}

#cert .cert-btns button {
  padding: 10px 24px;
  border-radius: 10px;
  border: none;
  font-weight: 800;
  cursor: pointer;
  font-size: 14px;
}

#cert #cert-dl {
  background: #22c55e;
  color: #06281a;
}

#cert #cert-close {
  background: #334155;
  color: #e2e8f0;
}

/* 底部浮动栏 */
.sticky-bottom {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  position: sticky;
  bottom: 0;
  gap: 20px;
  z-index: 100;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 10px 0;
  font-size: 12px;
  color: #fff;
  width: 100%;
}

.sticky-bottom a {
  color: inherit;
  text-decoration: none;
  font-weight: inherit;
  background-color: transparent;
  transition: none;
}

.sticky-bottom a:hover {
  color: #86EFAC;
  text-decoration: underline;
}

/* 路线选择器 */
#lane-selector {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid #334155;
  border-radius: 12px;
  padding: 20px;
  z-index: 1000;
  min-width: 320px;
  text-align: center;
}

#lane-selector.hidden {
  display: none;
}

.selector-title {
  color: #e2e8f0;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 16px;
}

.selector-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.lane-btn {
  width: 50px;
  height: 50px;
  border: 2px solid #475569;
  background: #1e293b;
  color: #cbd5e1;
  font-size: 16px;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lane-btn:hover {
  background: #334155;
  border-color: #64748b;
  color: #f1f5f9;
}

.lane-btn.active {
  background: #86EFAC;
  border-color: #21B858;
  color: #0f172a;
  box-shadow: 0 0 12px rgba(134, 239, 172, 0.5);
}

.selector-info {
  color: #94a3b8;
  font-size: 12px;
  line-height: 1.4;
}

.selector-info span {
  color: #eab308;
  font-weight: bold;
}

/* 路线选择器头部：标题 + 开关 */
.selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.selector-title {
  color: #e2e8f0;
  font-size: 18px;
  font-weight: bold;
  margin: 0;
  /* 覆盖之前的 margin */
  text-align: left;
  /* 已经是左对齐，但确保 */
}

/* 自定义切换开关 */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 70px;
  height: 28px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #475569;
  transition: .3s;
  border-radius: 14px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

.toggle-switch input:checked+.slider {
  background-color: #22C55E;
}

.toggle-switch input:checked+.slider:before {
  transform: translateX(42px);
}

.labels {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: bold;
  color: white;
  pointer-events: none;
  white-space: nowrap;
  text-align: center;
}

.labels::before {
  content: attr(data-off);
  position: absolute;
  left: -5px;
  top: 50%;
  transform: translateY(-50%);
}

.toggle-switch input:checked+.slider+.labels::before {
  content: attr(data-on);
  left: auto;
  right: 6px;
}