* {
  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", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: pointer;
}

#hud {
  position: fixed;
  bottom: 45px;
  right: 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 .hud-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#hud .hud-head h3 {
  margin: 0;
}

#hud .hud-head button {
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  pointer-events: auto;
}

#hud #hud-body {
  margin-top: 8px;
}

#hud.min {
  width: auto;
  padding: 8px 12px;
}

#hud.min .hud-head {
  gap: 10px;
}

#hud.min #hud-body {
  display: 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: 150px;
  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;
  left: 14px;
  font-size: 12px;
  color: #94a3b8;
  text-align: left;
  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;
  left: 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 .stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#stats .stats-head h3 {
  margin: 0;
}

#stats .stats-head button {
  width: 22px;
  height: 22px;
  margin: 0;
  padding: 0;
  border-radius: 6px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

#stats.min {
  width: auto;
  padding: 8px 12px;
}

#stats.min .stats-head {
  gap: 10px;
}

#stats.min #stats-body {
  display: none;
}

#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;
}

/* === 미니맵 (AION 스타일, 우상단) === */
#minimap {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 208px;
  background: rgba(8, 6, 4, 0.82);
  border: 1px solid rgba(200, 160, 100, 0.35);
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5);
}

#minimap .mm-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 700;
  color: #ead9b0;
  background: linear-gradient(180deg, rgba(60, 38, 20, 0.9), rgba(30, 18, 10, 0.9));
  border-bottom: 1px solid rgba(200, 160, 100, 0.25);
  letter-spacing: 0.5px;
}

#minimap .mm-coord {
  font-weight: 500;
  font-size: 10.5px;
  color: #c9b288;
}

#minimap canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* === AION 스타일 하단 바 === */
#aionbar {
  position: fixed;
  left: 50%;
  bottom: 42px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

#aionbar .ab-buffs {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(8, 5, 3, 0.65);
  border: 1px solid rgba(200, 160, 100, 0.22);
  font-size: 11px;
  color: #c9b288;
}

#aionbar .ab-buffs b {
  font-size: 12px;
}

#aionbar .ab-buffs.danger {
  border-color: rgba(239, 68, 68, 0.8);
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.45);
}

#aionbar .pips {
  display: flex;
  gap: 5px;
}

#aionbar .pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid #6b4a2e;
  background: rgba(40, 22, 12, 0.8);
}

#aionbar .pip.on {
  background: radial-gradient(circle at 35% 30%, #ffd27a, #ef4444 70%);
  border-color: #fecaca;
  box-shadow: 0 0 7px rgba(239, 68, 68, 0.8);
}

#aionbar .ab-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

#aionbar .ab-side {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 220px;
}

#aionbar .ab-bar {
  height: 16px;
  padding: 2px;
  background: linear-gradient(180deg, rgba(10, 6, 4, 0.9), rgba(25, 14, 8, 0.9));
  border: 1px solid rgba(200, 160, 100, 0.4);
  border-radius: 3px;
}

#aionbar .ab-left .ab-bar {
  transform: skewX(-12deg);
}

#aionbar .ab-right .ab-bar {
  transform: skewX(12deg);
}

#aionbar .segs {
  display: flex;
  gap: 2px;
  height: 100%;
}

#aionbar .hpseg {
  flex: 1;
  border-radius: 1px;
  background: rgba(70, 20, 18, 0.55);
}

#aionbar .hpseg.on {
  background: linear-gradient(180deg, #ff7a6a, #c81e14 60%, #8a0f08);
  box-shadow: 0 0 5px rgba(239, 68, 68, 0.5);
}

#aionbar .hpseg.low {
  background: linear-gradient(180deg, #ffb199, #ef2d1d);
  box-shadow: 0 0 8px rgba(255, 80, 60, 0.9);
  animation: ab-pulse 0.7s infinite alternate;
}

#aionbar .mpseg {
  flex: 1;
  border-radius: 1px;
  background: rgba(18, 32, 60, 0.55);
}

#aionbar .mpseg.on {
  background: linear-gradient(180deg, #7ab8ff, #1d5fc8 60%, #0b3a8a);
  box-shadow: 0 0 5px rgba(80, 140, 255, 0.5);
}

@keyframes ab-pulse {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

#aionbar .ab-bartext {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #d9c6a0;
  padding: 0 4px;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
}

#aionbar .ab-bartext span:last-child {
  font-weight: 800;
  color: #f1e6cc;
}

#aionbar .ab-emblem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: -22px;
}

#aionbar .ab-diamond {
  width: 52px;
  height: 52px;
  transform: rotate(45deg);
  background: linear-gradient(135deg, #2a180c, #0d0705);
  border: 2px solid #c8a064;
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(200, 160, 100, 0.35), inset 0 0 12px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}

#aionbar .ab-diamond span {
  transform: rotate(-45deg);
  font-size: 22px;
  font-weight: 900;
  color: #f3e3bd;
  text-shadow: 0 0 8px rgba(255, 210, 130, 0.8);
}

#aionbar .ab-emblem-lab {
  font-size: 10px;
  color: #c9b288;
  letter-spacing: 1px;
}

#aionbar .ab-slots {
  display: flex;
  gap: 6px;
}

#aionbar .ab-slot {
  position: relative;
  width: 78px;
  padding: 6px 6px 5px;
  background: linear-gradient(180deg, rgba(16, 10, 6, 0.85), rgba(8, 5, 3, 0.85));
  border: 1px solid rgba(200, 160, 100, 0.3);
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

#aionbar .ab-slot .key {
  position: absolute;
  top: -7px;
  left: 4px;
  padding: 0 5px;
  font-size: 9.5px;
  font-weight: 800;
  color: #0d0705;
  background: #c8a064;
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

#aionbar .ab-slot .ico {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

#aionbar .ico-y { background: radial-gradient(circle at 35% 30%, #fff3b0, #eab308 65%, #92600a); }
#aionbar .ico-r { background: radial-gradient(circle at 35% 30%, #ffc9b8, #ef4444 65%, #8a1208); }
#aionbar .ico-d { background: radial-gradient(circle at 35% 30%, #c9f3ff, #22d3ee 65%, #0e6a7a); }
#aionbar .ico-s { background: radial-gradient(circle at 35% 30%, #d6ffc9, #22c55e 65%, #0e6a32); }
#aionbar .ico-rs { background: radial-gradient(circle at 35% 30%, #e2e8f0, #64748b 65%, #2a3648); }

#aionbar .ab-slot .slab {
  font-size: 10px;
  color: #d9c6a0;
  white-space: nowrap;
}

#aionbar .ab-slot .cd {
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

/* 라인 선택기 */
#lane-selector .selector-name {
  margin: 10px 0 2px;
}

#lane-selector .selector-name input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid rgba(200, 160, 100, 0.4);
  background: rgba(10, 6, 4, 0.7);
  color: #f1e6cc;
  font-size: 14px;
  outline: none;
}

#lane-selector .selector-name input:focus {
  border-color: #c8a064;
  box-shadow: 0 0 8px rgba(200, 160, 100, 0.35);
}

#lane-selector .selector-name input::placeholder {
  color: #8a7a5c;
}

/* 캐릭터 색상 선택 */
#color-picker {
  display: flex;
  gap: 7px;
  justify-content: center;
  margin: 8px 0 2px;
}

#color-picker .color-swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}

#color-picker .color-swatch:hover {
  transform: scale(1.15);
}

#color-picker .color-swatch.active {
  border-color: #c8a064;
  box-shadow: 0 0 9px rgba(200, 160, 100, 0.8);
  transform: scale(1.15);
}

#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-server {
  margin-bottom: 12px;
}
.selector-server select {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #e2e8f0;
  font-size: 14px;
  outline: none;
  cursor: pointer;
}
.selector-server select:focus {
  border-color: #22c55e;
}

/* 랭킹 PIN 입력 */
.selector-pin {
  margin-bottom: 12px;
}
.selector-pin input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0b1220;
  color: #e2e8f0;
  font-size: 14px;
  outline: none;
  letter-spacing: 3px;
}
.selector-pin input::placeholder {
  letter-spacing: normal;
  color: #64748b;
}
.selector-pin input:focus {
  border-color: #22c55e;
}

/* 미입력 필드 강조 + 시작 차단 안내 */
.field-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.45);
}
.selector-start-hint.err {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* 시작 안내문 (선택기 하단 — 라인선택기가 배너를 가려서 추가) */
.selector-start-hint {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #86efac;
  font-size: 13.5px;
  font-weight: 700;
}
.selector-start-hint kbd {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  color: #e2e8f0;
}

/* 라인 선택기 헤더: 제목 + 토글 */
.selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* 헤더 우측 컨트롤 묶음 (시계방향 체크 + 오픈북 토글) */
.selector-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.clock-check {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  color: #cbd5e1;
  user-select: none;
}

.clock-check input {
  width: 15px;
  height: 15px;
  accent-color: #22c55e;
  cursor: pointer;
  margin: 0;
}

.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;
}