:root {
  --bg-dark: #070a14;
  --bg-panel: #11172a;
  --bg-card: #18213a;
  --border-glow: rgba(56, 189, 248, 0.25);
  --cyan: #38bdf8;
  --yellow: #facc15;
  --red: #f43f5e;
  --green: #22c55e;
  --line-green: #06c755;
  --purple: #a855f7;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  background: radial-gradient(circle at 30% 15%, #16203d 0%, var(--bg-dark) 80%);
  color: var(--text-main);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Noto Sans TC', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px;
  overscroll-behavior: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 490px 360px;
  gap: 16px;
  max-width: 880px;
  width: 100%;
  align-items: start;
}

.stage-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 8px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.hud-life-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.hud-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.hud-hp-num {
  font-weight: 800;
  color: var(--yellow);
}

.life-bars {
  display: flex;
  gap: 3px;
}

.life-pip {
  width: 9px;
  height: 15px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.3);
}

.life-pip.filled {
  background: linear-gradient(180deg, #fef08a, #facc15);
  box-shadow: 0 0 6px rgba(250, 204, 21, 0.65);
}

.life-pip.danger {
  background: linear-gradient(180deg, #fda4af, #f43f5e);
  box-shadow: 0 0 8px rgba(244, 63, 94, 0.8);
}

.hud-floor-box {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.floor-display {
  white-space: nowrap;
  font-size: 16px;
  font-weight: 900;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.floor-display span {
  font-size: 22px;
  color: var(--yellow);
  text-shadow: 0 0 10px rgba(250, 204, 21, 0.45);
}

.hud-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.hud-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 8px 9px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.15);
}

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(56, 189, 248, 0.35);
  background: #05070f;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.6);
  width: 100%;
  aspect-ratio: 480 / 600;
}

#shaftCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.touch-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.touch-btn {
  background: linear-gradient(180deg, #17223d, #10172a);
  color: var(--cyan);
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  border-radius: 12px;
  padding: 15px 12px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  transition: background 0.08s, transform 0.08s;
  touch-action: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

.touch-btn:active, .touch-btn.pressed {
  background: rgba(56, 189, 248, 0.3);
  border-color: var(--cyan);
  transform: scale(0.97);
}

.legend-bar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 11px;
  color: #cbd5e1;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.plat-icon {
  display: inline-block;
  width: 34px;
  height: 10px;
  vertical-align: middle;
}

.lb-tag {
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 999px;
  vertical-align: middle;
}

.lb-footnote {
  flex-shrink: 0;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 14px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.brand-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.brand-header h1 {
  font-size: 18px;
  font-weight: 900;
  color: var(--yellow);
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--green);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 4px 9px;
  border-radius: 999px;
}

.live-badge.offline {
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.35);
}
.live-badge.offline .pulse-dot {
  background: var(--text-muted);
  box-shadow: none;
}

.name-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--yellow);
}
.modal-input-row input.needs-name {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.35);
}

.btn-jump-board {
  display: none;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.player-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
  background: var(--bg-card);
  padding: 10px 12px;
  border-radius: 10px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.input-group label {
  font-size: 11px;
  color: var(--text-muted);
}

.input-group input {
  background: #0a0f1e;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text-main);
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.input-group input:focus {
  border-color: var(--cyan);
}

.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 2px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #cbd5e1;
  cursor: pointer;
}

.global-stats {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  padding: 7px 10px;
  border-radius: 8px;
}

.accent-yellow { color: var(--yellow); }
.accent-cyan { color: var(--cyan); }

.lb-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.lb-header {
  font-size: 13px;
  font-weight: 800;
  color: var(--cyan);
}

.lb-hint {
  font-size: 10px;
  color: var(--text-muted);
}

.leaderboard-list {
  min-height: 240px;
  max-height: 310px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}

.lb-item.has-ghost {
  cursor: pointer;
}

.lb-item.has-ghost:hover {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.1);
}

.lb-item.active-ghost {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.16);
}

.lb-item.top-1 {
  background: linear-gradient(90deg, rgba(250, 204, 21, 0.16), rgba(250, 204, 21, 0.02));
  border-color: rgba(250, 204, 21, 0.45);
}

.lb-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.lb-rank {
  font-weight: 800;
  width: 22px;
  text-align: center;
}

.lb-name-wrap {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lb-name {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-cause {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-cause:empty {
  display: none;
}

.lb-right {
  margin-left: auto;
  flex-shrink: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.lb-score {
  font-weight: 900;
  font-size: 13px;
  color: var(--yellow);
}

.lb-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
}

.lb-pk {
  flex-shrink: 0;
  margin-left: 8px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.lb-del {
  flex-shrink: 0;
  margin-left: 6px;
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.5);
  border-radius: 7px;
  padding: 6px 7px;
  font-size: 12px;
  cursor: pointer;
}

.admin-uid {
  font-size: 11px;
  word-break: break-all;
}
.admin-row {
  margin-top: 8px;
}
.admin-status {
  min-height: 1em;
  font-size: 12px;
  color: var(--yellow);
}
#gameVersion {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.version-button {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  -webkit-touch-callout: none;
}
.version-new {
  font-size: 9px;
  font-weight: 900;
  color: #fff;
  background: var(--red);
  padding: 1px 5px;
  border-radius: 999px;
  text-decoration: none;
}
.version-new.hidden {
  display: none;
}
.release-notes-list {
  text-align: left;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.release-notes-list h3 {
  font-size: 14px;
  color: var(--yellow);
  margin-bottom: 4px;
}
.release-notes-list ul {
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lb-item.active-ghost .lb-pk {
  background: var(--cyan);
  color: #04121d;
}

.ghost-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ghost-status {
  font-size: 12px;
  color: #cbd5e1;
}

.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.15s;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--cyan);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.hidden {
  display: none !important;
}

/* Modal & Upload / Share Buttons */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 15, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
}

.modal.hidden {
  display: none;
}

.modal-box {
  background: var(--bg-panel);
  border: 2px solid var(--yellow);
  border-radius: 16px;
  padding: 16px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 0 35px rgba(250, 204, 21, 0.25);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.modal-badge {
  align-self: center;
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
  border: 1px solid var(--red);
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.modal-box h2 {
  font-size: 18px;
}

.title-pill {
  font-size: 12px;
  font-weight: 800;
  color: #e9d5ff;
  background: rgba(168, 85, 247, 0.18);
  border: 1px solid rgba(168, 85, 247, 0.45);
  padding: 4px 10px;
  border-radius: 8px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--bg-card);
  padding: 8px;
  border-radius: 10px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-item span {
  font-size: 10px;
  color: var(--text-muted);
}

.stat-item strong {
  font-size: 15px;
  color: var(--yellow);
}

.modal-inputs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
  border-radius: 9px;
}

.modal-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-input-row label {
  font-size: 11px;
  color: var(--text-muted);
  width: 32px;
  text-align: left;
  font-weight: 700;
}

.modal-input-row input {
  flex: 1;
  background: #080c18;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text-main);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
  user-select: text;
  -webkit-user-select: text;
}

.confirm-box {
  max-width: 300px;
  text-align: center;
}
.confirm-box p {
  margin: 8px 0 14px;
  color: var(--text-muted);
}
.confirm-actions {
  display: flex;
  gap: 10px;
}
#btnUploadRestart {
  display: none;
}
/* Unsaved finished run: [放棄] [返回] [🚀 上傳後再玩], with 放棄 small and far from the thumb */
.unsaved .confirm-actions {
  gap: 8px;
}
.unsaved #btnConfirmRestart {
  order: 0;
  flex: 0 0 auto;
  width: auto;
  background: var(--bg-card);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.45);
  font-size: 12px;
  padding: 8px 12px;
}
.unsaved #btnCancelRestart {
  order: 1;
  flex: 0 0 auto;
  width: auto;
  padding: 8px 14px;
}
.unsaved #btnUploadRestart {
  display: block;
  order: 2;
  flex: 1;
}
.btn-cancel {
  width: 100%;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-glow);
  border-radius: 9px;
  padding: 10px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.btn-upload {
  width: 100%;
  background: linear-gradient(90deg, #facc15, #f97316);
  color: #090d16;
  border: none;
  border-radius: 9px;
  padding: 10px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(250, 204, 21, 0.35);
  transition: transform 0.12s, opacity 0.12s;
}

.btn-upload:disabled {
  background: rgba(34, 197, 94, 0.22);
  color: var(--green);
  border: 1px solid var(--green);
  box-shadow: none;
  cursor: default;
}

.share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.btn-img-card {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.btn-line {
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.btn-copy {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-retry-wide {
  width: 100%;
  background: rgba(56, 189, 248, 0.16);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  border-radius: 8px;
  padding: 9px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

/* Image Preview Modal */
.img-modal-box {
  max-width: 380px;
}

.img-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--yellow);
}

.btn-close-x {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.img-modal-tip {
  font-size: 11px;
  color: #cbd5e1;
}

.card-preview-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}

.modal-buttons {
  display: flex;
  gap: 8px;
}

.modal-buttons .btn-copy {
  flex: 1;
}

.btn-primary {
  flex: 1;
  background: var(--yellow);
  color: #090d16;
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  background: var(--green);
  color: #051b11;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 100;
  font-size: 13px;
  transition: opacity 0.25s;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 860px) {
  .btn-jump-board {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--yellow);
    background: var(--bg-card);
    border: 1px solid var(--border-glow);
    border-radius: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .btn-jump-board.locked {
    opacity: 0.45;
  }
  body {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    align-items: flex-start;
  }
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    max-width: 480px;
    gap: 12px;
  }
  /* HUD + game + controls fit in one screen, so nobody has to scroll mid-run */
  .canvas-wrap {
    width: min(100%, calc((100vh - 190px) * 0.8));
    width: min(100%, calc((100dvh - 190px) * 0.8));
    margin: 0 auto;
  }
  .touch-btn {
    padding: 18px 10px;
    font-size: 17px;
  }
  .hud-top {
    padding: 6px 8px;
    gap: 6px;
  }
  .hud-life-box {
    min-width: 0;
    flex-shrink: 1;
  }
  .life-bars {
    gap: 2px;
  }
  .floor-display {
    font-size: 13px;
  }
  .floor-display span {
    font-size: 19px;
  }
  .btn-icon {
    padding: 7px 7px;
    font-size: 12px;
  }
  .hud-sub {
    display: none;
  }
  .life-pip {
    width: 6px;
    height: 13px;
  }
  .legend-bar {
    justify-content: center;
    font-size: 10px;
  }
  .modal-box {
    padding: 14px;
  }
}

.lb-offline {
  color: #fbbf24;
}
