/* The in-game HUD: chat, room info and modifier, upgrades, kills, minimap,
   leaderboard, XP / health bars, weapon mastery, trait choice, dash meter,
   banner and damage flash.
   Linked from index.html in a fixed order (the order is the cascade). */

#hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  user-select: none;
  font-family: "Russo One", system-ui, sans-serif;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

/* Chat: the log stays in the bottom-left corner (above the small
   indicators); Enter opens the field under it. */
/* The bottom-left stack, from the bottom: the horse panel (its height and a
   gap: --left-stack, set by hud.js), the SOUND OFF and AUTO FIRE badges
   while they're on (--badge-mute, --badge-auto), then the chat. */
:root {
  --badge-mute: 0px;
  --badge-auto: 0px;
}

:root:has(#mute-indicator:not([hidden])) {
  --badge-mute: 32px;
}

:root:has(#autofire-indicator:not([hidden])) {
  --badge-auto: 32px;
}

.chat {
  position: absolute;
  left: var(--edge);
  bottom: calc(var(--edge) + max(30px, var(--left-stack, 0px)) + var(--badge-mute) + var(--badge-auto) + 4px);
  width: min(380px, calc(100vw - 2 * var(--edge)));
  font: 600 13px/1.35 system-ui, "Segoe UI", sans-serif;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

/* Scrollable with the mouse wheel to read older messages; it sticks to
   the newest unless scrolled up. */
.chat-log {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  max-height: 168px;
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

/* Pushes the lines to the bottom while there are only a few. */
.chat-log > :first-child {
  margin-top: auto;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
}

.chat-line {
  flex-shrink: 0;
  max-width: calc(100% - 8px);
  padding: 2px 7px;
  color: #eef1f8;
  background: rgba(0, 0, 0, 0.42);
  border-radius: 5px;
  overflow-wrap: anywhere;
}

.chat-name {
  font-weight: 800;
}

/* Another player's name: click to report them. */
.chat-report {
  cursor: pointer;
}

.chat-report:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-system {
  color: #a3abbc;
  font-style: italic;
  font-weight: 500;
}

.chat-system.chat-milestone {
  color: var(--accent);
  font-style: normal;
  font-weight: 800;
  border-left: 3px solid var(--accent);
}

.chat-input {
  width: 100%;
  margin-top: 6px;
  padding: 7px 10px;
  box-sizing: border-box;
  font: 500 14px system-ui, "Segoe UI", sans-serif;
  color: #fff;
  background: rgba(10, 12, 18, 0.88);
  border: 1px solid var(--accent);
  border-radius: 7px;
  outline: none;
  pointer-events: auto;
  user-select: text;
}

/* Touch screens: Send, beside the field (chat.js). */
.chat-send {
  margin-top: 6px;
  padding: 7px 14px;
  font: 700 13px "Russo One", system-ui, sans-serif;
  color: #10131a;
  background: var(--accent);
  border: none;
  border-radius: 7px;
  pointer-events: auto;
}

.chat-send[hidden] {
  display: none;
}

.chat:has(.chat-send:not([hidden])) .chat-input {
  width: calc(100% - 82px);
  margin-right: 6px;
}

.chat-input[hidden] {
  display: none;
}

.hud-room {
  position: absolute;
  top: var(--edge);
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

#hud-room {
  font-size: 26px;
  letter-spacing: 1px;
  color: var(--accent);
}

/* A boss room: the boss's name and a big health bar under the room info
   (hud.js). Enraged, the bar pulses. */
.hud-boss {
  width: min(460px, 70vw);
  margin: 8px auto 0;
}

.hud-boss-name {
  margin-bottom: 4px;
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 15px;
  letter-spacing: 2px;
  color: #ff6a5a;
  text-shadow: 0 0 12px rgba(255, 58, 58, 0.5), 0 2px 4px rgba(0, 0, 0, 0.8);
}

.hud-boss-bar {
  height: 12px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 90, 80, 0.45);
  border-radius: 7px;
}

#hud-boss-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(#ff5a4a, #b8231a);
  border-radius: 5px;
  transition: width 0.15s;
}

.hud-boss.enraged #hud-boss-fill {
  animation: boss-enraged 0.6s ease-in-out infinite alternate;
}

@keyframes boss-enraged {
  from { box-shadow: 0 0 2px rgba(255, 58, 58, 0.4); }
  to { box-shadow: 0 0 14px rgba(255, 58, 58, 1); }
}

#hud-powerups {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 8px;
  max-width: min(760px, 96vw);
}

.hud-powerup {
  padding: 3px 10px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 12px;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* Where an effect's time comes from (POWER-UP, CHEST, BERSERK, a trait):
   small and dimmer, each followed by its seconds. */
.hud-powerup b {
  font-weight: inherit;
}

.hud-powerup-source {
  font-size: 9px;
  letter-spacing: 0.5px;
  opacity: 0.75;
}

/* A chest's boost waiting for the next fight. */
.hud-powerup.waiting {
  border-style: dashed;
  opacity: 0.7;
}

/* Desktop: the badges, the health bar and the berserk meter say more on
   hover (their tooltips). */
html:not(.touch) .hud-powerup,
html:not(.touch) .hud-health-bar,
html:not(.touch) #hud-health-text,
html:not(.touch) .hud-mastery,
html:not(.touch) .hud-berserk {
  pointer-events: auto;
  cursor: help;
}

#hud-room-modifier {
  margin-top: 4px;
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #ffcf6a;
}

#hud-room-modifier strong {
  font-family: "Russo One", system-ui, sans-serif;
  font-weight: 400;
  letter-spacing: 1px;
  margin-right: 6px;
}

#hud-room-modifier span {
  color: var(--muted);
}

#banner small {
  display: block;
  margin-top: 6px;
  font-size: 0.34em;
  letter-spacing: 5px;
  color: #ffcf6a;
}

#hud-room-info {
  margin-top: 2px;
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* BUILD in the top-left: the upgrades taken this run (they're picked on
   the level-up cards, and in their blue), hidden until the first. Always
   open on desktop, never scrolling (a line per upgrade, each total effect
   showing on hover); on touch screens it opens only when its tab is
   tapped (.open; hud.js): open by itself it'd cover a phone. */
.upgrade-summary {
  position: absolute;
  top: var(--edge);
  left: var(--edge);
  width: max-content;
  padding: 6px 10px;
  background: linear-gradient(170deg, rgba(120, 200, 255, 0.1), rgba(10, 12, 18, 0.72));
  border: 1px solid rgba(160, 215, 255, 0.28);
  border-radius: 10px;
  box-shadow: 0 0 18px rgba(90, 170, 255, 0.12);
  pointer-events: auto;
}

.upgrade-summary-tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  letter-spacing: 1px;
  color: #9fd4ff;
  opacity: 0.75;
}

#upgrade-summary-list {
  display: none;
}

/* Desktop: always open (it's only what's taken); touch: when tapped. */
html:not(.touch) .upgrade-summary,
.upgrade-summary.open {
  width: max-content;
  min-width: 210px;
  padding: 7px 12px 6px 7px;
}

html:not(.touch) .upgrade-summary-tab,
.upgrade-summary.open .upgrade-summary-tab {
  padding: 0 4px 4px;
  font-size: 12px;
  opacity: 1;
}

html:not(.touch) #upgrade-summary-list,
.upgrade-summary.open #upgrade-summary-list {
  display: block;
}

/* HEALING under the upgrades: what heals you, in green (brighter while
   regenerating). Folded away with the list on touch screens. */
.upgrade-summary-healing {
  display: none;
  margin-top: 5px;
  padding: 4px 4px 0;
  border-top: 1px solid rgba(160, 215, 255, 0.18);
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: #9fe8a8;
}

html:not(.touch) .upgrade-summary-healing:not([hidden]),
.upgrade-summary.open .upgrade-summary-healing:not([hidden]) {
  display: block;
}

.upgrade-summary-healing-title {
  font-family: "Russo One", system-ui, sans-serif;
  font-weight: 400;
  font-size: 11px;
  letter-spacing: 1px;
  color: #7fd98a;
}

.upgrade-summary-healing.active .upgrade-summary-healing-title {
  color: #b5ffbf;
  text-shadow: 0 0 6px rgba(110, 230, 120, 0.7);
}

.upgrade-summary-healing small {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

/* On touch screens the tab is a button: tap to open or close. The touch
   buttons under it step aside while the list is open. */
.touch .upgrade-summary-tab {
  cursor: pointer;
  opacity: 1;
  touch-action: manipulation;
}

.upgrades-open #touch-overlay .touch-buttons {
  visibility: hidden;
}

.touch .upgrade-summary-tab::after {
  content: '\25BE';
}

.touch .upgrade-summary.open .upgrade-summary-tab::after {
  content: '\25B4';
}

@keyframes points-pulse {
  from { box-shadow: 0 0 2px rgba(120, 200, 255, 0.4); }
  to { box-shadow: 0 0 10px rgba(120, 200, 255, 0.95); }
}

.upgrade-line {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 2px 4px;
  font: inherit;
  text-align: left;
  text-shadow: inherit;
  color: inherit;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: default;
}

.upgrade-line-name {
  font-size: 13px;
  color: var(--text);
}

/* Rows of ten (upgrades go up to 20 levels). */
.upgrade-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-width: 118px;
}

.upgrade-pip {
  width: 8px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(160, 215, 255, 0.35);
  border-radius: 2px;
}

.upgrade-pip.filled {
  background: #9fd4ff;
  box-shadow: 0 0 4px rgba(120, 200, 255, 0.6);
}

.upgrade-line.maxed .upgrade-pip.filled {
  background: #e6f4ff;
  border-color: #e6f4ff;
  box-shadow: 0 0 7px rgba(120, 200, 255, 0.95);
}

/* The total effect shows on hover (desktop only: opened on a phone, the
   list stays one line an upgrade, to fit). */
.upgrade-line-effect {
  display: none;
  grid-column: 1 / span 2;
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

html:not(.touch) .upgrade-summary:hover .upgrade-line-effect {
  display: block;
}

.hud-kills {
  position: absolute;
  top: var(--edge);
  right: var(--edge);
  text-align: right;
}

#hud-kills {
  display: block;
  font-size: 26px;
  color: var(--text);
}

#minimap {
  position: absolute;
  top: calc(var(--edge) + 56px);
  right: var(--edge);
  width: 168px;
  height: 168px;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

#minimap[hidden] {
  display: none;
}

/* The minimap's legend (minimap.js createLegend): a small ? in the
   minimap's bottom-left corner; hovering or tapping it shows what each
   mark is, to the minimap's left. */
#minimap-legend-button {
  position: absolute;
  top: calc(var(--edge) + 56px + 168px - 20px);
  right: calc(var(--edge) + 168px - 20px);
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 0 5px 0 6px;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.75);
  font: 700 11px/16px system-ui, "Segoe UI", sans-serif;
  text-shadow: none;
  cursor: help;
  pointer-events: auto;
}

#minimap-legend-button:hover {
  color: #fff;
  background: rgba(0, 0, 0, 0.8);
}

#minimap-legend-button[hidden],
#minimap-legend[hidden] {
  display: none;
}

#minimap-legend {
  position: absolute;
  top: calc(var(--edge) + 56px);
  right: calc(var(--edge) + 176px);
  z-index: 2;
  padding: 7px 10px 8px 6px;
  background: rgba(6, 8, 10, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  font: 600 12px/1.2 system-ui, "Segoe UI", sans-serif;
  color: #dfe3ea;
  text-shadow: none;
  pointer-events: none;
}

.minimap-legend-title {
  margin: 0 0 4px 4px;
  font: 13px "Russo One", system-ui, sans-serif;
  letter-spacing: 1px;
  color: #fff;
}

.minimap-legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 17px;
}

.minimap-legend-row canvas {
  width: 28px;
  height: 16px;
  flex: none;
}

/* Leaderboard under the minimap (moves up when the minimap is off). */
.leaderboard {
  position: absolute;
  top: calc(var(--edge) + 236px);
  right: var(--edge);
  width: 256px;
  padding: 6px 8px 7px;
  box-sizing: border-box;
  font: 600 12px/1.25 system-ui, "Segoe UI", sans-serif;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

#minimap[hidden] + .leaderboard {
  top: calc(var(--edge) + 56px);
}

.leaderboard[hidden] {
  display: none;
}

.leaderboard-title {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font: 400 11px "Russo One", system-ui, sans-serif;
  letter-spacing: 1.5px;
  color: var(--muted);
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 2px 0;
  color: #e6e9f2;
}

.leaderboard-row.gap {
  margin-top: 3px;
  padding-top: 4px;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
}

.leaderboard-row.self .leaderboard-name,
.leaderboard-row.self .leaderboard-rank {
  color: var(--accent);
}

/* Alive or dead at a glance: a dot before the name (green / red), and a
   dead player's name crossed out and dimmed, with DEAD in red. */
.leaderboard-status {
  flex: none;
  align-self: center;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade6a;
  box-shadow: 0 0 6px rgba(74, 222, 106, 0.7);
}

.leaderboard-row.dead .leaderboard-status {
  background: #ff4a3a;
  box-shadow: 0 0 6px rgba(255, 74, 58, 0.7);
}

.leaderboard-row.dead .leaderboard-name-text {
  opacity: 0.55;
  text-decoration: line-through;
  text-decoration-color: rgba(255, 90, 74, 0.8);
}

.leaderboard-level.leaderboard-dead {
  color: #ff5a4a;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.leaderboard-rank {
  width: 1.6em;
  flex-shrink: 0;
  color: var(--muted);
}

.leaderboard-name {
  display: flex;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  font-weight: 700;
}

.leaderboard-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-name .verified-mark,
.leaderboard-tag {
  flex: none;
  white-space: pre;
}

/* "(admin)": smaller, so the name still fits the narrow board. */
.leaderboard-tag {
  font-size: 10px;
  font-weight: 600;
}

.leaderboard-level {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--accent);
}

.leaderboard-xp {
  width: 3.4em;
  flex-shrink: 0;
  text-align: right;
  color: #ffe9a8;
  font-variant-numeric: tabular-nums;
}

.hud-kills-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
}

.hud-ping {
  display: block;
  font-size: 10px;
  color: var(--muted);
}

.hud-ping::before {
  content: "\25CF  ";
}

.hud-ping.good::before {
  color: #6adf7a;
}

.hud-ping.ok::before {
  color: #ffc94d;
}

.hud-ping.bad::before {
  color: #ff5a4a;
}

.hud-bottom {
  position: absolute;
  bottom: var(--edge);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.hud-xp {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-level {
  min-width: 52px;
  font-size: 15px;
  color: var(--accent);
  text-align: right;
}

.hud-xp-bar {
  width: min(280px, 60vw);
  height: 8px;
  padding: 1px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}

#hud-xp-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), #ffe9a8);
  border-radius: 5px;
  box-shadow: 0 0 8px rgba(255, 201, 77, 0.6);
  transition: width 0.2s;
}

.hud-health {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-health-bar {
  width: min(280px, 60vw);
  height: 14px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

#hud-health-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(#7fe07a, #3fae44);
  border-radius: 6px;
  transition: width 0.15s;
}

.hud-health-bar.low #hud-health-fill {
  background: linear-gradient(#ff7a6a, #d9372b);
}

/* Regenerating (unhurt for a while, not full): a soft green shimmer. */
.hud-health-bar.regen {
  animation: health-regen 1.2s ease-in-out infinite alternate;
}

@keyframes health-regen {
  from { box-shadow: 0 0 2px rgba(110, 230, 120, 0.2); }
  to { box-shadow: 0 0 9px rgba(110, 230, 120, 0.75); }
}

/* A heal landing: "+N" rising off the health number. */
.hud-health {
  position: relative;
}

.hud-heal-pop {
  position: absolute;
  right: -6px;
  bottom: 100%;
  font-size: 14px;
  color: #7dff9a;
  text-shadow: 0 0 8px rgba(80, 255, 130, 0.7), 0 2px 4px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
}

.hud-heal-pop.play {
  animation: heal-pop 0.9s ease-out;
}

@keyframes heal-pop {
  0% { opacity: 0; transform: translateY(6px) scale(0.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.15); }
  70% { opacity: 1; transform: translateY(-6px) scale(1); }
  100% { opacity: 0; transform: translateY(-12px); }
}

/* Dash meter in the bottom-right corner. */
/* Weapon mastery, above the dash meter. */
.hud-mastery {
  position: absolute;
  right: var(--edge);
  bottom: calc(var(--edge) + 62px);
  width: 256px;
  padding: 8px 10px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}

.hud-mastery-top {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text);
}

.hud-mastery-rank {
  color: var(--accent);
}

.hud-mastery-bar {
  height: 5px;
  margin-top: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

#hud-mastery-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #ff9a2a, var(--accent));
  transition: width 0.2s;
}

.hud-mastery-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.hud-mastery-traits:empty {
  display: none;
}

.hud-mastery-trait {
  padding: 1px 6px;
  font: 700 10px/1.5 system-ui, "Segoe UI", sans-serif;
  color: #ffe2a0;
  background: rgba(255, 201, 77, 0.12);
  border-radius: 999px;
  text-shadow: none;
}

/* Level-up cards: three upgrades dealt above the bars, one to pick (1, 2,
   3 or a click). Each deals in with a flip, one after another. */
.upgrade-choice {
  position: absolute;
  left: 50%;
  bottom: calc(var(--edge) + 128px);
  transform: translateX(-50%);
  width: 660px;
  max-width: calc(100% - 32px);
  padding: 12px;
  box-sizing: border-box;
  text-align: center;
  background: rgba(10, 12, 18, 0.88);
  border: 1px solid rgba(120, 200, 255, 0.5);
  border-radius: 14px;
  box-shadow: 0 0 34px rgba(90, 170, 255, 0.28);
  pointer-events: auto;
  animation: trait-choice-in 0.3s ease-out;
}

.upgrade-choice-title {
  margin-bottom: 8px;
  font-size: 15px;
  letter-spacing: 2px;
  color: #9fd4ff;
}

.upgrade-choice-options {
  display: flex;
  gap: 10px;
}

.upgrade-card {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 5px;
  padding: 10px 11px 9px;
  text-align: left;
  color: var(--text);
  background: linear-gradient(170deg, rgba(120, 200, 255, 0.1), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(160, 215, 255, 0.28);
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  animation: upgrade-card-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.upgrade-card:hover {
  transform: translateY(-4px) scale(1.03);
  background: linear-gradient(170deg, rgba(120, 200, 255, 0.22), rgba(255, 255, 255, 0.05));
  border-color: #9fd4ff;
  box-shadow: 0 6px 18px rgba(90, 170, 255, 0.3);
}

@keyframes upgrade-card-in {
  from { opacity: 0; transform: translateY(18px) rotateY(80deg) scale(0.9); }
  to { opacity: 1; transform: none; }
}

.upgrade-card strong {
  font-size: 15px;
  font-weight: 400;
}

.upgrade-card kbd {
  margin-right: 6px;
  padding: 0 6px;
  font: 700 11px/1.5 system-ui, "Segoe UI", sans-serif;
  color: #0c1622;
  background: #9fd4ff;
  border-radius: 4px;
}

.upgrade-card > span:not(.upgrade-card-level) {
  font: 500 12px/1.4 system-ui, "Segoe UI", sans-serif;
  color: var(--muted);
  text-shadow: none;
}

.upgrade-card-level {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}

.upgrade-card-level em {
  font: 700 10px/1 system-ui, "Segoe UI", sans-serif;
  font-style: normal;
  letter-spacing: 1px;
  color: #9fd4ff;
}

.upgrade-card.new .upgrade-card-level em {
  color: #7dff9a;
}

/* Rarer cards (CARD_RARITIES): rare in a deep, bright blue; epic in purple,
   a light sweeping across it. Each says its rarity and levels on top. */
.upgrade-card-rarity {
  font: 700 10px/1 system-ui, "Segoe UI", sans-serif;
  letter-spacing: 1.5px;
  color: rgba(200, 215, 235, 0.45);
}

.upgrade-card.rare {
  background: linear-gradient(170deg, rgba(60, 150, 255, 0.3), rgba(20, 40, 80, 0.25));
  border-color: #4aa8ff;
  box-shadow: 0 0 16px rgba(60, 150, 255, 0.55), inset 0 0 12px rgba(60, 150, 255, 0.2);
}

.upgrade-card.rare .upgrade-card-rarity {
  color: #7cc4ff;
}

.upgrade-card.epic {
  position: relative;
  overflow: hidden;
  background: linear-gradient(170deg, rgba(170, 90, 255, 0.36), rgba(40, 15, 70, 0.3));
  border-color: #c08cff;
  box-shadow: 0 0 22px rgba(170, 90, 255, 0.75), inset 0 0 14px rgba(170, 90, 255, 0.25);
}

.upgrade-card.epic::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.22) 45%, transparent 60%);
  animation: epic-sweep 1.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes epic-sweep {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.upgrade-card.epic .upgrade-card-rarity {
  color: #d9b8ff;
}

.upgrade-card.epic .upgrade-pip.next {
  border-color: #d9b8ff;
}

.upgrade-pip.next {
  border-color: #9fd4ff;
  animation: points-pulse 0.8s ease-in-out infinite alternate;
}

/* Both at once: the trait choice sits above the cards. */
.upgrade-choice:not([hidden]) ~ .trait-choice {
  bottom: calc(var(--edge) + 268px);
}

/* Picking a trait at a new mastery rank: two cards above the bars. */
.trait-choice {
  position: absolute;
  left: 50%;
  bottom: calc(var(--edge) + 128px);
  transform: translateX(-50%);
  width: 560px;
  max-width: calc(100% - 32px);
  padding: 12px;
  box-sizing: border-box;
  text-align: center;
  background: rgba(10, 12, 18, 0.88);
  border: 1px solid rgba(255, 201, 77, 0.55);
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(255, 177, 31, 0.25);
  pointer-events: auto;
  animation: trait-choice-in 0.35s ease-out;
}

@keyframes trait-choice-in {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.trait-choice-title {
  margin-bottom: 8px;
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--accent);
}

.trait-choice-options {
  display: flex;
  gap: 10px;
}

.trait-option {
  flex: 1;
  padding: 10px;
  text-align: left;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
}

.trait-option:hover {
  background: rgba(255, 201, 77, 0.12);
  border-color: var(--accent);
}

.trait-option strong {
  display: block;
  font-size: 15px;
  font-weight: 400;
}

.trait-option kbd {
  margin-right: 6px;
  padding: 0 5px;
  font: 700 11px/1.5 system-ui, "Segoe UI", sans-serif;
  color: #12141a;
  background: var(--accent);
  border-radius: 4px;
}

.trait-option span {
  display: block;
  margin-top: 4px;
  font: 500 12px/1.4 system-ui, "Segoe UI", sans-serif;
  color: var(--muted);
  text-shadow: none;
}

.hud-dash {
  position: absolute;
  right: var(--edge);
  bottom: var(--edge);
  width: 96px;
  height: 52px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  text-align: center;
}

.hud-dash kbd {
  position: relative;
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 1px;
}

#hud-dash-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background: rgba(140, 200, 255, 0.35);
}

.hud-dash-label {
  position: relative;
  display: block;
  margin-top: 7px;
  font-size: 15px;
  letter-spacing: 2px;
  color: var(--muted);
}

.hud-dash.ready {
  border-color: rgba(160, 215, 255, 0.7);
  box-shadow: 0 0 12px rgba(140, 200, 255, 0.35);
}

.hud-dash.ready .hud-dash-label {
  color: #dff1ff;
}

/* Berserk meter, left of the dash meter: charging (dark red filling, the
   time left), soon (the last 10 seconds ticking), ready (on fire,
   pulsing), raging (draining, flickering). */
/* A panel in the bottom-left corner, under the chat (the dungeon's
   horse). Lit when its key does something. */
.hud-corner {
  position: absolute;
  left: var(--edge);
  bottom: var(--edge);
  width: 250px;
  padding: 6px 9px 7px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.58);
  border: 1px solid rgba(255, 160, 64, 0.28);
  border-radius: 10px;
  font: 600 11px/1.3 system-ui, "Segoe UI", sans-serif;
  color: #ffd8a8;
}

.hud-corner.ready {
  border-color: rgba(125, 255, 154, 0.7);
  box-shadow: 0 0 14px rgba(125, 255, 154, 0.25);
}

.hud-corner-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.hud-corner-title {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: #ffa040;
}

.hud-corner-subtitle {
  font-size: 10px;
  color: rgba(255, 216, 168, 0.7);
}

.hud-corner-subtitle[hidden] {
  display: none;
}

.hud-corner-action {
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.75);
}

.hud-corner.ready .hud-corner-action {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 12px;
  letter-spacing: 1px;
  color: #7dff9a;
}

/* A panel over the left side: the trader (shopPanel.js) and the admin's
   test tools (adminTest.js). */
.side-panel {
  position: absolute;
  left: var(--edge);
  top: 50%;
  transform: translateY(-50%);
  width: 330px;
  max-height: calc(100% - 220px);
  overflow-y: auto;
  padding: 8px 10px 9px;
  box-sizing: border-box;
  background: rgba(6, 12, 18, 0.86);
  border: 1px solid rgba(156, 240, 255, 0.45);
  border-radius: 10px;
  box-shadow: 0 0 18px rgba(156, 240, 255, 0.15);
  font: 600 11px/1.3 system-ui, "Segoe UI", sans-serif;
  color: #d8f6ff;
  pointer-events: auto;
  text-shadow: none;
}

.side-panel-title {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  color: #9cf0ff;
}

.side-panel-row {
  margin-top: 6px;
}

.side-panel-label {
  margin-bottom: 2px;
  color: rgba(216, 246, 255, 0.65);
  font-size: 10px;
}

.side-panel-items {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.side-panel-item {
  display: flex;
  gap: 5px;
  align-items: baseline;
  padding: 3px 6px;
  border: 1px solid rgba(156, 240, 255, 0.35);
  border-radius: 5px;
  background: rgba(156, 240, 255, 0.08);
  color: #eafaff;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.side-panel-item:hover:not(:disabled) {
  background: rgba(156, 240, 255, 0.22);
}

.side-panel-item:disabled {
  cursor: default;
  opacity: 0.4;
}

.side-panel-item.owned {
  opacity: 1;
  border-color: #ffa040;
  background: rgba(255, 160, 64, 0.2);
  color: #ffe0b0;
}

.side-panel-cost {
  color: #ffd040;
  font-size: 10px;
}

.side-panel-note {
  margin-top: 6px;
  color: rgba(216, 246, 255, 0.5);
  font-size: 10px;
}

/* Gold on the HUD (hud.js), after the level bar. */
.hud-gold {
  min-width: 44px;
  font-size: 14px;
  color: #ffcc40;
}

.hud-berserk {
  position: absolute;
  right: calc(var(--edge) + 106px);
  bottom: var(--edge);
  width: 150px;
  height: 52px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 90, 50, 0.25);
  border-radius: 10px;
  text-align: center;
  font-family: "Russo One", system-ui, sans-serif;
}

.hud-berserk-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, rgba(120, 10, 0, 0.6), rgba(220, 60, 20, 0.6));
  transition: width 0.15s linear;
}

/* A kill took a chunk off the recharge. */
.hud-berserk-fill.play {
  animation: berserk-gain 0.35s ease-out;
}

@keyframes berserk-gain {
  0% { filter: brightness(2.6); }
  100% { filter: brightness(1); }
}

.hud-berserk-label {
  position: relative;
  display: block;
  margin-top: 5px;
  font-size: 14px;
  letter-spacing: 2px;
  color: #c89080;
}

.hud-berserk-state {
  position: relative;
  display: inline-block;
  font-size: 13px;
  letter-spacing: 1px;
  color: #ffb8a0;
}

.hud-berserk kbd {
  position: absolute;
  right: 6px;
  top: 6px;
  font-size: 9px;
  letter-spacing: 1px;
}

.hud-berserk[data-mode="soon"] {
  border-color: rgba(255, 120, 60, 0.7);
  box-shadow: 0 0 10px rgba(255, 90, 30, 0.4);
}

.hud-berserk[data-mode="soon"] .hud-berserk-state {
  font-size: 16px;
  color: #ffd27a;
}

.hud-berserk-state.play {
  animation: berserk-tick 0.6s ease-out;
}

@keyframes berserk-tick {
  0% { transform: scale(1.7); color: #fff; text-shadow: 0 0 12px #ff7a2a; }
  100% { transform: scale(1); }
}

.hud-berserk[data-mode="ready"] {
  border-color: #ffb040;
  animation: berserk-ready 0.9s ease-in-out infinite;
}

.hud-berserk[data-mode="ready"] .hud-berserk-fill {
  background: linear-gradient(90deg, #a01800, #ff5a1a, #ffb030, #ff5a1a, #a01800);
  background-size: 200% 100%;
  animation: berserk-flow 1.2s linear infinite;
}

.hud-berserk[data-mode="ready"] .hud-berserk-label,
.hud-berserk[data-mode="ready"] .hud-berserk-state {
  color: #fff6e0;
  text-shadow: 0 0 8px #ff3a00, 0 1px 2px #000;
}

@keyframes berserk-ready {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 80, 20, 0.6); transform: scale(1); }
  50% { box-shadow: 0 0 26px rgba(255, 120, 30, 0.95); transform: scale(1.05); }
}

@keyframes berserk-flow {
  from { background-position: 0% 0; }
  to { background-position: 200% 0; }
}

.hud-berserk[data-mode="raging"] {
  border-color: #ff3a1a;
  box-shadow: 0 0 18px rgba(255, 40, 0, 0.8);
  animation: berserk-flicker 0.15s steps(2) infinite;
}

.hud-berserk[data-mode="raging"] .hud-berserk-fill {
  background: linear-gradient(90deg, #ff2a00, #ff9a20);
}

.hud-berserk[data-mode="raging"] .hud-berserk-label,
.hud-berserk[data-mode="raging"] .hud-berserk-state {
  color: #fff;
  text-shadow: 0 0 6px #ff2a00, 0 1px 2px #000;
}

@keyframes berserk-flicker {
  50% { box-shadow: 0 0 28px rgba(255, 120, 0, 0.95); }
}

/* Raging: the screen's edges burn. */
#berserk-vignette {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(255, 60, 0, 0) 55%, rgba(255, 70, 0, 0.32) 85%, rgba(200, 20, 0, 0.55));
  transition: opacity 0.4s;
}

.berserk-active #berserk-vignette {
  opacity: 1;
  animation: berserk-heartbeat 0.75s ease-out infinite;
}

/* The world turns harsh while you rage (the fire stays vivid). */
#game canvas {
  transition: filter 0.6s;
}

.berserk-active #game canvas {
  filter: saturate(0.72) contrast(1.14) brightness(0.96);
}

/* A "lub" and a softer "dub" (rageView.js RAGE_BEAT). */
@keyframes berserk-heartbeat {
  0% { filter: brightness(1.45); }
  12% { filter: brightness(0.85); }
  24% { filter: brightness(1.25); }
  40% { filter: brightness(0.8); }
  100% { filter: brightness(0.8); }
}

@keyframes berserk-burn {
  from { filter: brightness(0.85); }
  to { filter: brightness(1.25); }
}

.callout[data-kind="berserk"] {
  color: #ffb040;
  text-shadow: 0 0 26px rgba(255, 90, 20, 0.9), 0 4px 10px rgba(0, 0, 0, 0.85);
}

.callout[data-kind="rage"] {
  color: #ff4a1a;
  font-size: clamp(36px, 7vw, 72px);
  text-shadow: 0 0 30px rgba(255, 40, 0, 1), 0 4px 10px rgba(0, 0, 0, 0.9);
}

#hud-health-text {
  min-width: 36px;
  font-size: 18px;
  color: var(--text);
}

#banner {
  position: fixed;
  top: 28%;
  left: 0;
  right: 0;
  z-index: 6;
  text-align: center;
  font-family: "Russo One", system-ui, sans-serif;
  font-size: clamp(40px, 9vw, 84px);
  letter-spacing: 3px;
  color: var(--accent);
  text-shadow: 0 0 30px rgba(255, 177, 31, 0.45), 0 4px 12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
}

#banner.play {
  animation: banner 2.2s ease-out;
}

@keyframes banner {
  0% { opacity: 0; transform: scale(1.4); }
  12% { opacity: 1; transform: scale(1); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.96); }
}

/* LEVEL N!: a short punch-in in the middle of the screen, under the
   room banner (hud.js showCallout). */
.callout {
  position: fixed;
  top: 31%;
  left: 0;
  right: 0;
  z-index: 6;
  text-align: center;
  font-family: "Russo One", system-ui, sans-serif;
  font-size: clamp(28px, 5.5vw, 54px);
  letter-spacing: 3px;
  opacity: 0;
  pointer-events: none;
}

/* The Arena: a player kill, and a kill streak. */
.callout[data-kind="kill"] {
  color: #ffd2c8;
  font-size: clamp(22px, 4vw, 40px);
  text-shadow: 0 0 22px rgba(255, 70, 50, 0.8), 0 4px 10px rgba(0, 0, 0, 0.85);
}

.callout[data-kind="streak"] {
  color: #ffcf4a;
  font-size: clamp(36px, 7vw, 72px);
  text-shadow: 0 0 30px rgba(255, 60, 40, 1), 0 4px 10px rgba(0, 0, 0, 0.9);
}

/* The titan combo: a callout per titan, and the meter (hud.js
   updateTitanCombo) counting down to the combo's end. */
.callout[data-kind="titan"] {
  color: #ffe08a;
  font-size: clamp(34px, 6.5vw, 66px);
  text-shadow: 0 0 30px rgba(255, 150, 30, 0.95), 0 4px 10px rgba(0, 0, 0, 0.9);
}

#titan-combo {
  position: fixed;
  top: 21%;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: "Russo One", system-ui, sans-serif;
  font-size: clamp(16px, 2.2vw, 22px);
  letter-spacing: 2px;
  color: #ffe08a;
  text-shadow: 0 0 16px rgba(255, 150, 30, 0.8), 0 2px 6px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

#titan-combo[hidden] {
  display: none;
}

.titan-combo-bar {
  width: 160px;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.titan-combo-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ff7a1a, #ffe08a);
}

/* A new titan in the combo: the count punches in. */
#titan-combo.bump .titan-combo-count {
  animation: titan-combo-bump 0.4s ease-out;
}

@keyframes titan-combo-bump {
  0% { transform: scale(1.6); }
  100% { transform: scale(1); }
}

/* Run out: it fades away. */
#titan-combo.ended {
  animation: titan-combo-end 0.8s ease-in forwards;
}

@keyframes titan-combo-end {
  0% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(8px); }
}

/* A dungeon room's name as you walk in (hud.js). */
.callout[data-kind="place"] {
  color: #f0d6a8;
  letter-spacing: 3px;
  text-shadow: 0 0 22px rgba(240, 180, 90, 0.55), 0 4px 10px rgba(0, 0, 0, 0.85);
}

.callout[data-kind="level"] {
  color: #9cf0ff;
  text-shadow: 0 0 26px rgba(80, 220, 255, 0.7), 0 4px 10px rgba(0, 0, 0, 0.85);
}

.callout.play {
  animation: callout 1.5s ease-out;
}

@keyframes callout {
  0% { opacity: 0; transform: scale(2); }
  10% { opacity: 1; transform: scale(0.94); }
  18% { transform: scale(1.04); }
  26% { transform: scale(1); }
  75% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-14px) scale(1); }
}

#damage-flash {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(180, 0, 0, 0) 45%, rgba(180, 0, 0, 0.55));
  opacity: 0;
}

#damage-flash.play {
  animation: damage-flash 0.45s ease-out;
}

@keyframes damage-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}


/* A loot chest opening (chestReveal.js): under the room info, in its
   rarity's color (--chest-color), spinning, then what was inside. */
.chest-reveal {
  position: fixed;
  top: 26%;
  left: 50%;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 280px;
  padding: 14px 26px 16px;
  text-align: center;
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
  color: var(--text);
  background: rgba(12, 15, 22, 0.92);
  border: 2px solid var(--chest-color, #c8ccd4);
  border-radius: 16px;
  box-shadow: 0 0 30px color-mix(in srgb, var(--chest-color, #c8ccd4) 45%, transparent);
  transform: translateX(-50%);
  pointer-events: none;
  animation: chest-in 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.chest-reveal[hidden] {
  display: none;
}

/* Climbing through the rarities before it lands (chestReveal.js): it
   shakes, harder (--shake) with every rarer color. */
.chest-reveal.teasing {
  animation: chest-tease 0.09s linear infinite alternate;
}

@keyframes chest-tease {
  from { transform: translateX(calc(-50% - var(--shake, 1px))) rotate(-1deg); }
  to { transform: translateX(calc(-50% + var(--shake, 1px))) rotate(1deg); }
}

.chest-reveal-title {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--chest-color, #c8ccd4);
}

.chest-reveal.legendary .chest-reveal-title {
  font-size: 28px;
  animation: chest-glow 0.6s ease-in-out infinite alternate;
}

.chest-reveal-reel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 26px;
  font-size: 16px;
  color: var(--muted);
}

.chest-reveal-reel.landed {
  animation: chest-land 0.35s ease-out;
}

.chest-reveal-prize {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 19px;
  color: var(--text);
}

.chest-reveal-skin {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 18px;
  color: var(--chest-color, #ffb02a);
}

/* (A weapon found: what it does, small, under its name.) */
.chest-reveal-weapon {
  max-width: 340px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-dim, #b8c0cc);
  text-align: center;
}

.chest-reveal-shards {
  font-size: 13px;
  font-weight: 700;
  color: #9ad8ff;
}

@keyframes chest-in {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6); }
  100% { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes chest-land {
  0% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

@keyframes chest-glow {
  0% { text-shadow: 0 0 6px var(--chest-color, #ffb02a); }
  100% { text-shadow: 0 0 22px var(--chest-color, #ffb02a); }
}

.touch .chest-reveal {
  top: 70px;
  min-width: 0;
  padding: 8px 16px;
}

/* "Achievement earned" popup, top center under the room info. */
.achievement-toast {
  position: fixed;
  top: 96px;
  left: 50%;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 260px;
  padding: 12px 22px;
  text-align: center;
  font: 13px/1.4 system-ui, "Segoe UI", sans-serif;
  color: var(--muted);
  background: rgba(12, 15, 22, 0.9);
  border: 2px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 0 24px rgba(255, 201, 77, 0.35);
  transform: translateX(-50%);
  pointer-events: none;
  animation: achievement-in 0.35s ease-out;
}

.achievement-toast[hidden] {
  display: none;
}

.achievement-toast strong {
  font-family: "Russo One", system-ui, sans-serif;
  font-size: 20px;
  font-weight: 400;
  color: var(--text);
}

.achievement-toast-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}

.achievement-toast-unlock {
  margin-top: 4px;
  font-weight: 700;
  color: #6fd3ff;
}

/* Phones and tablets: a slim, see-through one-line banner (no
   description) so the game stays visible behind it. */
.touch .achievement-toast {
  top: 58px;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 8px;
  min-width: 0;
  max-width: 70vw;
  padding: 4px 12px;
  font-size: 11px;
  background: rgba(12, 15, 22, 0.7);
  border-width: 1px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(255, 201, 77, 0.25);
}

.touch .achievement-toast strong {
  font-size: 13px;
}

.touch .achievement-toast-kicker {
  font-size: 10px;
  letter-spacing: 1px;
}

.touch .achievement-toast-description {
  display: none;
}

.touch .achievement-toast-unlock {
  margin-top: 0;
}

@keyframes achievement-in {
  from { opacity: 0; transform: translate(-50%, -16px) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* Touch controls (touchControls.js): the layer over the game catches the
   thumbs; joysticks appear where they land. */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 4;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#touch-controls[hidden] {
  display: none;
}

.touch-stick {
  position: absolute;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.touch-stick[hidden] {
  display: none;
}

.touch-stick-aim {
  border-color: rgba(255, 201, 77, 0.45);
}

/* Touch aim: a ring round the finger aiming a cursor weapon. */
.touch-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2px solid rgba(255, 201, 77, 0.7);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: translate(-50%, -50%);
}

.touch-stick-aim .touch-knob {
  background: rgba(255, 201, 77, 0.55);
}

.touch-buttons {
  position: absolute;
  top: calc(var(--edge) + 40px);
  left: var(--edge);
  display: flex;
  gap: 8px;
}

.touch-button {
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 20px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
}

/* On touch screens the dash meter is a big dash button (and the berserk
   meter a berserk button). */
.touch .hud-dash {
  width: 120px;
  height: 64px;
  pointer-events: auto;
  touch-action: none;
}

.touch .hud-corner {
  pointer-events: auto;
  touch-action: none;
}

.touch .hud-berserk {
  right: calc(var(--edge) + 130px);
  height: 64px;
  pointer-events: auto;
  touch-action: none;
}

.touch .hud-dash kbd,
.touch .hud-berserk kbd {
  display: none;
}

/* The chat log doesn't take thumbs meant for the move stick. */
.touch .chat-log {
  pointer-events: none;
}

.touch #game canvas {
  touch-action: none;
}

/* Over the HUD: the sticks (not catching touches) and the buttons. */
#touch-overlay {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

#touch-overlay[hidden] {
  display: none;
}

#touch-overlay .touch-buttons {
  pointer-events: auto;
}

/* Phones held sideways: a compact HUD (smaller minimap, no leaderboard,
   slimmer panels) so the game and the thumbs have room. */
@media (pointer: coarse) and (max-height: 600px) {
  .hud-room {
    top: 6px;
  }

  #hud-room {
    font-size: 20px;
  }

  .hud-kills {
    top: 6px;
    right: 12px;
  }

  #hud-kills {
    font-size: 20px;
  }

  #minimap {
    top: 48px;
    right: 12px;
    width: 104px;
    height: 104px;
  }

  #minimap-legend-button {
    top: calc(48px + 104px - 20px);
    right: calc(12px + 104px - 20px);
  }

  #minimap-legend {
    top: 48px;
    right: calc(12px + 112px);
    max-height: calc(100vh - 60px);
    overflow: hidden;
    font-size: 10px;
  }

  .leaderboard {
    display: none;
  }

  .hud-mastery {
    right: 12px;
    bottom: 90px;
    width: 170px;
    padding: 5px 8px;
    font-size: 11px;
  }

  /* Only the 4 newest traits: all 8 (Mk IX) would cover the minimap. */
  .hud-mastery-trait:nth-last-child(n + 5) {
    display: none;
  }

  .hud-dash {
    right: 12px;
    bottom: 14px;
  }

  .hud-berserk {
    right: 116px;
    bottom: 14px;
    width: 120px;
  }

  .hud-corner {
    left: 12px;
    bottom: 12px;
    width: 190px;
    padding: 4px 7px;
  }

  /* The side panels under the thumb buttons, above the corner panel;
     the cards and traits move right of them. */
  .side-panel {
    top: 104px;
    left: 12px;
    transform: none;
    width: 300px;
    max-height: calc(100% - 170px);
  }

  .side-panel-note {
    display: none;
  }

  :root:has(.side-panel:not([hidden])) .upgrade-choice,
  :root:has(.side-panel:not([hidden])) .trait-choice {
    left: auto;
    right: 12px;
    width: min(420px, calc(100% - 336px));
    transform: none;
    animation: none;
  }

  /* Typing in the chat: the choices wait (they'd cover the field). */
  :root:has(#chat-input:not([hidden])) .upgrade-choice,
  :root:has(#chat-input:not([hidden])) .trait-choice {
    visibility: hidden;
  }

  #hud-room-info {
    max-width: min(440px, calc(100vw - 280px));
    margin-inline: auto;
    font-size: 11px;
  }


  .hud-bottom {
    bottom: 12px;
  }

  .chat {
    bottom: calc(max(70px, var(--left-stack, 0px) + 50px));
    width: min(260px, calc(100vw - 20px));
    font-size: 12px;
  }

  /* The thumb buttons a little smaller, so the bars fit between them. */
  .touch .hud-dash {
    width: 96px;
    height: 52px;
  }

  .touch .hud-berserk {
    right: calc(var(--edge) + 104px);
    width: 96px;
    height: 52px;
  }

  .hud-mastery {
    bottom: 72px;
  }

  .hud-mastery-top {
    gap: 8px;
  }

  .hud-mastery-top > :first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .hud-corner {
    width: 176px;
    font-size: 10px;
  }

  /* Level and health between the corner panel and the thumb buttons. */
  .hud-bottom {
    left: calc(var(--edge) + 186px);
    right: calc(var(--edge) + 212px);
    transform: none;
    gap: 5px;
  }

  .hud-xp,
  .hud-health {
    width: 100%;
    gap: 6px;
  }

  .hud-level {
    min-width: 0;
    font-size: 12px;
  }

  .hud-xp-bar,
  .hud-health-bar {
    flex: 1;
    width: auto;
    min-width: 0;
  }

  .hud-health-bar {
    height: 11px;
  }

  /* The tutorial under the thumb buttons, smaller; out of the way while a
     choice is open. */
  .tip {
    top: 102px;
    gap: 8px;
    max-width: min(460px, calc(100% - 260px));
    padding: 5px 8px 5px 10px;
    font-size: 12px;
  }

  :root:has(.trait-choice:not([hidden]), .upgrade-choice:not([hidden])) .tip {
    display: none;
  }

  /* Level-up cards and the trait choice: small, low, clear of the soldier
     in the middle. */
  .upgrade-choice,
  .trait-choice {
    bottom: 64px;
    width: min(460px, calc(100% - 24px));
    padding: 6px;
    border-radius: 10px;
  }

  .upgrade-choice:not([hidden]) ~ .trait-choice {
    bottom: 176px;
  }

  .upgrade-choice-title,
  .trait-choice-title {
    margin-bottom: 5px;
    font-size: 11px;
    letter-spacing: 1px;
  }

  .upgrade-choice-options,
  .trait-choice-options {
    gap: 6px;
  }

  .upgrade-card {
    gap: 3px;
    padding: 6px 7px;
  }

  .upgrade-card strong,
  .trait-option strong {
    font-size: 12px;
  }

  .upgrade-card > span:not(.upgrade-card-level),
  .trait-option span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 10px;
    line-height: 1.3;
  }

  .upgrade-card-rarity,
  .upgrade-card-level em {
    font-size: 8px;
  }

  .trait-option {
    padding: 6px 8px;
  }

  .trait-option span {
    margin-top: 2px;
  }

  /* (Common cards don't need to say so; their level pips smaller.) */
  .upgrade-card:not(.rare):not(.epic) .upgrade-card-rarity {
    display: none;
  }

  .upgrade-card .upgrade-pips {
    gap: 1px;
    max-width: 80px;
  }

  .upgrade-card .upgrade-pip {
    width: 6px;
    height: 6px;
  }

  .hud-mastery-rank {
    flex: none;
    white-space: nowrap;
  }
}

/* Phones held upright: the game is played sideways. (Over everything but
   the start screen, which works upright.) */
.rotate-notice {
  display: none;
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 600px) {
  :root:has(#start-screen[hidden]) .rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 24px;
    text-align: center;
    font: 700 18px/1.4 system-ui, "Segoe UI", sans-serif;
    color: var(--text);
    background: rgba(8, 10, 14, 0.96);
  }

  .rotate-notice-icon {
    font-size: 64px;
    animation: rotate-phone 1.8s ease-in-out infinite;
  }

  .rotate-notice small {
    font-weight: 500;
    font-size: 13px;
    color: var(--muted);
  }
}

@keyframes rotate-phone {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

/* First-run tips (tips.js): under the room title, one at a time. */
.tip {
  position: absolute;
  top: calc(var(--edge) + 78px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100% - 32px);
  padding: 9px 10px 9px 16px;
  box-sizing: border-box;
  font: 700 15px/1.35 system-ui, "Segoe UI", sans-serif;
  color: #fff;
  background: rgba(10, 12, 18, 0.78);
  border: 1px solid rgba(255, 201, 77, 0.55);
  border-radius: 10px;
  animation: tip-in 0.25s ease-out;
}

.tip[hidden] {
  display: none;
}

/* The tutorial: step number, what to do, then Next once it's done. */
.tip {
  width: max-content;
  max-width: min(640px, calc(100% - 32px));
}

.tip-step {
  flex: none;
  font-size: 12px;
  color: var(--accent);
}

.tip-text {
  min-width: 0;
}

/* A one-time hint (hints.js): like a tutorial step, in blue. */
.tip.hint {
  border-color: rgba(106, 190, 255, 0.7);
}

.hint-icon {
  flex: none;
  font-size: 16px;
}

/* A new monster's picture, or a power-up's color (hints.js). */
.hint-icon.picture {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
}

.hint-portrait {
  max-width: 44px;
  max-height: 44px;
}

.hint-swatch {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.tip.done {
  border-color: rgba(74, 222, 106, 0.8);
}

.tip.done .tip-text {
  color: #b5f0b5;
}

.tip-next {
  flex: none;
  padding: 5px 14px;
  font: 800 13px/1.3 system-ui, "Segoe UI", sans-serif;
  color: #0c1a0f;
  background: #4ade6a;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  pointer-events: auto;
  animation: tip-in 0.25s ease-out;
}

.tip-next:hover {
  background: #6ef08a;
}

.tip-skip {
  flex: none;
  padding: 2px 4px;
  font: 500 11px/1.3 system-ui, "Segoe UI", sans-serif;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  pointer-events: auto;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@keyframes tip-in {
  from {
    opacity: 0;
    transform: translate(-50%, -6px);
  }
}

/* The admin test lobby's tools (adminTest.js): on the right, gold-edged. */
.test-tools {
  left: auto;
  right: var(--edge);
  width: 360px;
  max-height: calc(100% - 160px);
  border-color: rgba(255, 196, 80, 0.6);
}

.test-tools-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.test-tools-head .side-panel-title {
  flex: 1;
  color: #ffc450;
}

.test-tools .side-panel-item.active {
  border-color: #ffc450;
  background: rgba(255, 196, 80, 0.25);
  color: #fff0c8;
}

.test-tools-inline {
  display: flex;
  gap: 4px;
}

.test-tools input,
.test-tools select {
  font: inherit;
  color: #d8f6ff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(156, 240, 255, 0.35);
  border-radius: 4px;
  padding: 2px 4px;
}

.test-tools input {
  width: 56px;
}

.test-tools select {
  width: 100%;
}

.test-tools select option,
.test-tools select optgroup {
  background: #0b141c;
}

.test-tools-trait,
.test-tools-upgrade {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
}

.test-tools-rank {
  flex: 0 0 44px;
  color: rgba(216, 246, 255, 0.65);
}

.test-tools-trait .side-panel-item {
  flex: 1;
}

.test-tools-upgrade-label {
  flex: 1;
}

.test-tools-message {
  margin-top: 6px;
  color: #ffc450;
}

/* The dungeon's horse (hud.js updateHorse): the corner panel, in
   leather and gold. */
.hud-horse {
  border-color: rgba(217, 164, 65, 0.35);
  color: #f0d6a8;
}

.hud-horse.denied .hud-corner-action {
  color: #ff8a7a;
}

/* The emote picker (G, emotePicker.js): a row of big emoji over the
   bottom middle. */
.emote-picker {
  position: absolute;
  bottom: calc(var(--edge) + 90px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(10, 12, 18, 0.82);
  pointer-events: auto;
  z-index: 3;
}

.emote-picker[hidden] {
  display: none;
}

.emote-option {
  position: relative;
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
}

.emote-option:hover {
  border-color: var(--accent);
  background: rgba(255, 201, 77, 0.12);
}

.emote-icon {
  font-size: 28px;
  line-height: 1;
}

.emote-option kbd {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font: 10px/1 system-ui, sans-serif;
  color: var(--muted);
}

@media (max-width: 600px) {
  .emote-option {
    width: 40px;
    height: 40px;
  }

  .emote-icon {
    font-size: 22px;
  }
}
