:root {
  --ink: #263445;
  --muted: rgba(38, 52, 69, 0.68);
  --panel: rgba(255, 255, 255, 0.82);
  --line: rgba(38, 52, 69, 0.16);
  --blue: #44a3ff;
  --violet: #9b68ff;
  --gold: #ffc94d;
  --green: #56c77a;
  --red: #ef6262;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #dfe7ef;
  user-select: none;
}

#world {
  display: block;
  width: 100vw;
  height: 100vh;
  background: #e7edf4;
  cursor: crosshair;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: 0 12px 32px rgba(45, 64, 88, 0.16);
  backdrop-filter: blur(12px);
}

.topbar {
  position: absolute;
  top: 14px;
  left: 50%;
  width: min(560px, calc(100vw - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}

.level-pill {
  width: fit-content;
  margin: 0 auto 8px;
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 800;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.24);
  background: rgba(38, 52, 69, 0.76);
}

.xp-shell {
  height: 16px;
  overflow: hidden;
  border: 2px solid rgba(38, 52, 69, 0.25);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

#xpFill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f6cf49, #f28d43);
  transition: width 140ms ease;
}

#leaderboard {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 230px;
  padding: 14px;
  border-radius: 8px;
}

#leaderboard h2,
#statsPanel h2 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0;
}

.leader-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 7px;
  align-items: center;
  height: 24px;
  font-size: 13px;
  color: var(--muted);
}

.leader-row strong {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#statsPanel {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: min(336px, calc(100vw - 36px));
  padding: 14px;
  border-radius: 8px;
  pointer-events: auto;
}

.stat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 9px;
  font-weight: 800;
}

.stat-row {
  display: grid;
  grid-template-columns: 26px 1fr 84px 28px;
  gap: 8px;
  align-items: center;
  min-height: 29px;
  color: var(--muted);
  font-size: 12px;
}

.stat-row.locked {
  opacity: 0.38;
}

.hotkey {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: white;
  background: #3c4c5f;
  font-weight: 800;
}

.bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.bar {
  height: 12px;
  border-radius: 3px;
  background: rgba(38, 52, 69, 0.14);
}

.bar.on {
  background: #61bf7b;
}

.stat-row button,
.toggles button,
.restart {
  height: 28px;
  border: 0;
  border-radius: 7px;
  color: white;
  background: #3c4c5f;
  font-weight: 800;
  cursor: pointer;
}

.stat-cap {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.stat-row button:disabled {
  cursor: default;
  opacity: 0.35;
}

.toggles {
  position: absolute;
  left: 18px;
  top: 18px;
  display: flex;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  pointer-events: auto;
}

.toggles button.active {
  background: var(--green);
}

.cheat-panel {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: min(310px, calc(100vw - 36px));
  padding: 12px;
  border-radius: 8px;
  pointer-events: auto;
}

.cheat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
}

.cheat-head span {
  color: var(--green);
  font-weight: 900;
}

.cheat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.cheat-grid button {
  min-height: 30px;
  border: 0;
  border-radius: 7px;
  color: white;
  background: #3c4c5f;
  font-weight: 800;
  cursor: pointer;
}

.cheat-grid button:hover {
  background: #51657d;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(22, 32, 44, 0.55);
  backdrop-filter: blur(7px);
  z-index: 5;
  pointer-events: auto;
}

.hidden {
  display: none;
}

.modal-card,
.death-card {
  width: min(980px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 22px;
  border-radius: 8px;
  background: rgba(247, 250, 253, 0.94);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.24);
}

.modal-card h1,
.death-card h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.class-card {
  min-height: 180px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.class-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(44, 66, 92, 0.16);
}

.class-card h3 {
  margin: 0 0 8px;
}

.class-card p {
  margin: 6px 0;
  font-size: 13px;
  color: var(--muted);
}

.tree-scroll {
  width: min(1180px, calc(100vw - 30px));
  height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border-radius: 8px;
  background: rgba(248, 251, 254, 0.96);
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.24);
}

#treeCanvas {
  width: 1600px;
  height: 920px;
  display: block;
}

.death-card {
  width: min(440px, calc(100vw - 30px));
  text-align: center;
}

.death-card dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  text-align: left;
}

.death-card dt {
  color: var(--muted);
}

.death-card dd {
  margin: 0;
  font-weight: 900;
}

@media (max-width: 760px) {
  #leaderboard {
    display: none;
  }

  .toggles {
    top: auto;
    left: 50%;
    bottom: 238px;
    transform: translateX(-50%);
  }

  .toggles button {
    width: 92px;
    font-size: 11px;
  }

  .cheat-panel {
    display: none;
  }
}
