* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0d1117;
  color: #e6edf3;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #1b2735 0%, #090a0f 100%);
  position: relative;
  overflow: hidden;
}

.login-bg-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}
.login-bg-wrap img,
.login-bg-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.login-bg-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: linear-gradient(to bottom, rgba(5,7,10,0.75), rgba(5,7,10,0.92));
  transition: opacity 0.25s ease;
}
/* On character-select the video stays visible behind the 3D model;
   dim the dark overlay so the character isn't covered. */
body.select-mode .login-bg-overlay {
  opacity: 0.35;
}

/* Full-viewport WebGL canvas used by both character-select (index) and game.
   index.html starts it hidden via inline style; game.html must stay visible.
   Do NOT set display:none here — that was hiding the entire game world. */
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
}
/* On the auth/select page the canvas sits under UI and shouldn't capture clicks */
body.auth-body #scene {
  z-index: 2;
  pointer-events: none;
}

.music-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #30363d;
  background: rgba(22, 27, 34, 0.85);
  color: #e6edf3;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.music-toggle:hover {
  background: rgba(48, 54, 61, 0.95);
  transform: scale(1.05);
}

.auth-layout {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  padding: 20px;
}

.patch-notes-panel {
  display: none; /* hidden by default (mobile) — see desktop media query below */
  width: 100%;
  max-width: 400px;
  padding: 20px;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid #30363d;
  border-radius: 12px;
}
.patch-notes-panel h3 {
  margin: 0 0 16px;
  font-size: 27px;
  color: #58a6ff;
}
.patch-note {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid #21262d;
}
.patch-note:last-child { border-bottom: none; margin-bottom: 0; }
.patch-note .version {
  font-size: 12px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.patch-note .title { font-weight: 600; font-size: 16px; margin: 4px 0 6px; }
.patch-note .body { font-size: 13px; color: #b6bcc4; line-height: 1.5; }

/* Small "Patch Notes" link shown only on mobile, only once notes exist
   (`.has-notes` gets added by JS after a successful fetch). Opens the
   popup modal below instead of a full side panel, which was too large
   and pushed/overlapped the login card on small screens. */
.patch-notes-mobile-link {
  display: none;
  background: none;
  border: none;
  color: #8b949e;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 4px;
  padding: 4px;
}
.patch-notes-mobile-link:hover { color: #58a6ff; }
.patch-notes-mobile-link.has-notes { display: inline-block; }

.modal.patch-notes-modal {
  width: 100%;
  max-width: 420px;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
}
.patch-notes-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.patch-notes-modal-header h3 {
  margin: 0;
  font-size: 22px;
  color: #58a6ff;
}
.modal-close-btn {
  background: none;
  border: none;
  color: #8b949e;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close-btn:hover { color: #e6edf3; }
#patchNotesModalList {
  overflow-y: auto;
  flex: 1;
}

/* Desktop: the mobile link disappears and the full patch-notes panel
   becomes a fixed panel pinned to the left, well clear of the centered
   login card, sized to a consistent 80% of viewport height. */
@media (min-width: 901px) {
  .auth-layout {
    flex-direction: row;
    justify-content: center;
  }
  .patch-notes-mobile-link {
    display: none !important;
  }
  .patch-notes-panel.has-notes {
    display: block;
    position: fixed;
    left: 80px;
    top: 50%;
    transform: translateY(-50%);
    width: 440px;
    max-width: none;
    height: 80vh;
    max-height: 80vh;
    overflow-y: auto;
  }
}

.auth-card {
  width: 100%;
  max-width: 340px;
  padding: 32px;
  background: rgba(22, 27, 34, 0.9);
  border: 1px solid #30363d;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.logo {
  text-align: center;
  font-size: 28px;
  margin: 0 0 20px;
  letter-spacing: 1px;
}
.logo span { color: #58a6ff; }

.motd {
  text-align: center;
  font-size: 12px;
  color: #8b949e;
  margin: -10px 0 20px;
}
.motd.maintenance {
  color: #f0883e;
  font-weight: 600;
}

.tabs {
  display: flex;
  margin-bottom: 20px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #30363d;
}
.tab {
  flex: 1;
  padding: 10px;
  background: #161b22;
  color: #8b949e;
  border: none;
  cursor: pointer;
  font-size: 14px;
}
.tab.active { background: #1f6feb; color: white; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form.hidden { display: none; }

.auth-form input {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
  font-size: 14px;
}

.auth-form button {
  padding: 10px;
  border-radius: 6px;
  border: none;
  background: #238636;
  color: white;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.auth-form button:hover { background: #2ea043; }

.auth-message {
  min-height: 20px;
  text-align: center;
  color: #f85149;
  font-size: 13px;
  margin-top: 14px;
}

/* Character select & game HUD shared bits */
.overlay-ui {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e6edf3;
}
.overlay-ui * { pointer-events: auto; }

.top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.top-bar .title { font-size: 20px; font-weight: 700; }
.top-bar .title span { color: #58a6ff; }
.top-bar-actions { display: flex; align-items: center; gap: 10px; }
.viewer-control-wrap { position: relative; display: flex; align-items: center; gap: 6px; }
.info-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid #30363d;
  background: #21262d;
  color: #9fb0c3;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.info-btn:hover, .info-btn.active { background: #30363d; color: #e6edf3; }
.viewer-legend {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 260px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #d3dbe4;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 30;
}
.viewer-legend strong { display: block; margin-bottom: 4px; color: #e6edf3; font-size: 13px; }
.viewer-legend kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: #0d1117;
  border: 1px solid #30363d;
  font-size: 11.5px;
  font-family: inherit;
}
.viewer-legend-note { margin-top: 6px; color: #9fb0c3; }
.logout-btn {
  background: #21262d;
  border: 1px solid #30363d;
  color: #e6edf3;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.logout-btn:hover { background: #30363d; }
.logout-btn.active {
  background: #1f6f3f;
  border-color: #2ea043;
  color: #d9fbe0;
}
.logout-btn.active:hover { background: #26824a; }

.char-nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid #30363d;
  background: rgba(22, 27, 34, 0.85);
  color: #e6edf3;
  font-size: 22px;
  cursor: pointer;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.char-nav-btn:hover { background: rgba(48, 54, 61, 0.95); transform: translateY(-50%) scale(1.05); }
.char-nav-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.char-nav-btn:disabled:hover { transform: translateY(-50%); }
.char-nav-left { left: 20px; }
.char-nav-right { right: 20px; }

.char-indicator {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: #e6edf3;
  background: rgba(22, 27, 34, 0.7);
  padding: 10px 24px;
  border-radius: 10px;
  min-width: 160px;
}
.char-indicator .char-indicator-name { font-size: 18px; font-weight: 700; }
.char-indicator .char-indicator-sub { font-size: 13px; color: #8b949e; margin-top: 2px; }
.char-indicator .char-indicator-dots {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.char-indicator-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #30363d;
}
.char-indicator-dots span.active { background: #58a6ff; }

.enter-btn {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 32px;
  background: #238636;
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.enter-btn:disabled { background: #30363d; color: #6e7681; cursor: not-allowed; }
.enter-btn:not(:disabled):hover { background: #2ea043; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 4;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* New-character modal sits on the right so the 3D model stays visible on the left */
#newCharModal.modal-backdrop {
  justify-content: flex-end;
  align-items: stretch;
  background: linear-gradient(90deg, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0.15) 45%, rgba(0,0,0,0.55) 70%);
  padding: 24px 24px 24px 0;
  pointer-events: none; /* clicks pass through empty left area onto canvas if needed */
}
#newCharModal .modal {
  pointer-events: auto;
  align-self: center;
  margin-right: 2vw;
}
.modal {
  width: 320px;
  padding: 24px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid #30363d;
  border-radius: 12px;
  backdrop-filter: blur(8px);
}
.modal h3 { margin-top: 0; }
.modal input, .modal select {
  width: 100%;
  padding: 10px;
  margin-bottom: 12px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #e6edf3;
}

/* New Character modal: three scrollable picker columns (race, gender,
   class) side by side, each a vertically-scrolling list of tap targets,
   with name/color/buttons in a full-width row below. Narrower per-column
   width than before since there are now three instead of two, with a
   stacked fallback on very narrow screens so nothing gets clipped. */
.new-char-modal {
  width: 100%;
  max-width: 480px;
}
.new-char-columns {
  display: flex;
  gap: 10px;
}
.new-char-col-label {
  font-size: 12px;
  color: #8b949e;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.new-char-picker-col {
  flex: 1;
  min-width: 0;
}
.new-char-details-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #21262d;
}
.new-char-details-row input,
.new-char-details-row select {
  margin-bottom: 10px;
}
.race-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}
.race-item {
  text-align: left;
  padding: 8px 8px;
  border-radius: 6px;
  border: 1px solid #30363d;
  background: #0d1117;
  color: #c9d1d9;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.race-item:hover { border-color: #58a6ff; }
.race-item.selected {
  border-color: #58a6ff;
  background: #12233a;
  color: #58a6ff;
  font-weight: 600;
}

@media (max-width: 480px) {
  .new-char-columns { flex-direction: column; }
  .race-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding-bottom: 4px;
  }
  .race-item { flex: 0 0 auto; }
}
.modal-actions { display: flex; gap: 10px; }
.modal-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.modal-actions .confirm { background: #238636; color: white; }
.modal-actions .cancel { background: #30363d; color: #e6edf3; }

.hint {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #8b949e;
  background: rgba(22,27,34,0.7);
  padding: 6px 14px;
  border-radius: 20px;
}

/* ============================================================
   Mobile virtual controls (joystick, jump bar, action bar)
   Always visible for now so they show on phone + desktop testing.
   ============================================================ */
.mobile-controls {
  display: block !important;
  pointer-events: none; /* children re-enable */
  z-index: 50;
}

.mobile-controls > * {
  pointer-events: auto;
}

/* --- Joystick (bottom-left) --- */
.joystick-base {
  position: fixed;
  left: 20px;
  bottom: 28px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(22, 27, 34, 0.55);
  border: 2px solid rgba(88, 166, 255, 0.35);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 100;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  margin-top: -26px;
  border-radius: 50%;
  background: rgba(88, 166, 255, 0.75);
  border: 2px solid rgba(230, 237, 243, 0.5);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: background 0.1s;
}

.joystick-base.active .joystick-knob {
  background: rgba(88, 166, 255, 0.95);
}

/* --- Jump bar (bottom center) --- */
.mobile-jump-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 28px;
  min-width: 140px;
  height: 48px;
  padding: 0 28px;
  border-radius: 24px;
  border: 2px solid rgba(46, 160, 67, 0.55);
  background: rgba(35, 134, 54, 0.75);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1px;
  z-index: 100;
  pointer-events: auto;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: background 0.1s, transform 0.08s;
}

.mobile-jump-bar:active,
.mobile-jump-bar.pressed {
  background: rgba(46, 160, 67, 0.95);
  transform: translateX(-50%) scale(0.96);
}

/* --- 8-slot action bar (right side, vertical) --- */
.action-bar {
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: auto;
}

.action-slot {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid #30363d;
  background: rgba(22, 27, 34, 0.8);
  color: #8b949e;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}

.action-slot:active,
.action-slot.pressed {
  background: rgba(31, 111, 235, 0.55);
  border-color: #58a6ff;
  color: #e6edf3;
  transform: scale(0.94);
}

/* --- Character coordinates readout (bottom right) --- */
.coords-display {
  position: fixed;
  right: 14px;
  bottom: 28px;
  z-index: 90;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(230, 237, 243, 0.65);
  background: rgba(13, 17, 23, 0.45);
  border: 1px solid rgba(48, 54, 61, 0.6);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

/* Slightly larger targets on very small phones */
@media (max-width: 400px) {
  .joystick-base {
    width: 100px;
    height: 100px;
    left: 12px;
    bottom: 20px;
  }
  .joystick-knob {
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
  }
  .mobile-jump-bar {
    min-width: 110px;
    height: 42px;
    font-size: 13px;
    bottom: 20px;
  }
  .action-slot {
    width: 42px;
    height: 42px;
    font-size: 13px;
  }
  .action-bar {
    right: 10px;
    gap: 6px;
  }
}

/* Hide desktop hint when mobile controls are active */
body.mobile-ui .hint {
  display: none;
}

/* Viewer login choice modal */
.viewer-choice-modal {
  max-width: 380px;
  width: 92%;
  padding: 22px 20px;
  background: #141b24;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  color: #e8eef7;
}
.viewer-choice-modal h3 { margin: 0 0 8px; font-size: 18px; }
.viewer-choice-msg { margin: 8px 0; font-size: 14px; }
.viewer-choice-sub { opacity: 0.8; font-size: 13px; margin: 0 0 4px; }
.viewer-choice-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.viewer-choice-actions button {
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #1c2430;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.viewer-choice-actions .btn-viewer {
  background: #2a5f8f;
  border-color: #5b9fd4;
}
.viewer-choice-actions .btn-player { background: #2a3a2a; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
