:root {
  --bg: #0b0a14;
  --bg-raised: #16142a;
  --fg: #39e6c4;
  --fg-dim: #256e60;
  --fg-bright: #f1ecff;
  --gold: #ffb84d;
  --gold-bright: #ffd98a;
  --danger: #ff5577;
  --border: #2a2750;
  --display: "Chakra Petch", ui-sans-serif, system-ui, sans-serif;
  --body: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg-bright);
  font-family: var(--body);
  min-height: 100%;
  /* A blanket "manipulation" so a double-tap anywhere -- not just the buttons that already
     set this individually -- never triggers the browser's native double-tap-to-zoom. Still
     allows normal panning/pinch-zoom, so index.html's scrollable character-select screens are
     unaffected; world.html's canvas goes further with touch-action: none (see world.html). */
  touch-action: manipulation;
}

body {
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.ambient-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background:
    radial-gradient(ellipse 70% 42% at 50% -8%, rgba(255, 184, 77, 0.1), transparent 60%),
    radial-gradient(ellipse 85% 55% at 50% 112%, rgba(57, 230, 196, 0.07), transparent 62%);
  mix-blend-mode: screen;
  animation: drift 9s ease-in-out infinite;
}

@keyframes drift {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.boot {
  text-align: center;
  margin-top: 40vh;
  font-family: var(--display);
  color: var(--gold-bright);
  text-shadow: 0 0 10px rgba(255, 184, 77, 0.6);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.boot::after {
  content: "";
  display: block;
  width: 130px;
  height: 2px;
  margin: 16px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  background-size: 220% 100%;
  animation: scan 2.6s linear infinite;
}

@keyframes scan {
  0% { background-position: 220% 0; }
  100% { background-position: -220% 0; }
}

h1, h2, h3 {
  font-family: var(--display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0;
}

h1 { font-size: 1.4rem; color: var(--gold-bright); text-shadow: 0 0 10px rgba(255, 184, 77, 0.5); }
h2 { font-size: 1.15rem; color: var(--fg-bright); text-shadow: 0 0 8px rgba(57, 230, 196, 0.45); }
h3 { font-size: 1rem; color: var(--fg-bright); text-shadow: 0 0 8px rgba(57, 230, 196, 0.4); }

p { line-height: 1.5; margin: 0; }

a { color: var(--gold-bright); }

.panel {
  border: 1px solid var(--border);
  background: linear-gradient(165deg, var(--bg-raised), var(--bg));
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: inset 0 0 0 1px rgba(57, 230, 196, 0.04), 0 10px 30px rgba(0, 0, 0, 0.45);
}

.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

label {
  font-size: 0.8rem;
  font-family: var(--display);
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-bright);
  font-family: var(--body);
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  width: 100%;
}

input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

button {
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.92rem;
  background: transparent;
  color: var(--fg-bright);
  border: 1.5px solid var(--fg-dim);
  border-radius: 8px;
  padding: 12px 16px;
  min-height: 44px;
  cursor: pointer;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
button:focus-visible { border-color: var(--fg); background: rgba(57, 230, 196, 0.1); }
button:active { background: rgba(57, 230, 196, 0.18); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  border-color: transparent;
  color: #1a1206;
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  box-shadow: 0 0 18px rgba(255, 184, 77, 0.35);
}
button.primary:hover,
button.primary:focus-visible { background: linear-gradient(135deg, #ffe6b0, var(--gold-bright)); box-shadow: 0 0 22px rgba(255, 184, 77, 0.5); }
button.primary:active { background: var(--gold); }

button.ghost { border-color: transparent; color: var(--fg); }
button.ghost:hover, button.ghost:focus-visible { background: rgba(57, 230, 196, 0.08); }
button.full { width: 100%; }

.error-text { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; font-family: var(--body); }

.currency { color: var(--gold-bright); font-family: var(--mono); letter-spacing: 0.03em; }

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

.race-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.race-card.selected { border-color: var(--gold); box-shadow: 0 0 14px rgba(255, 184, 77, 0.4); }
.race-card .mods { color: var(--fg); font-size: 0.85rem; font-family: var(--mono); }
.race-card .ability { font-size: 0.85rem; color: var(--fg-bright); }
.race-card .flavor { color: var(--fg); opacity: 0.75; font-size: 0.8rem; font-family: var(--body); font-style: italic; }

.category-label {
  display: inline-block;
  margin-top: 8px;
  background: var(--gold);
  color: #1a1206;
  text-transform: uppercase;
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  padding: 4px 16px 4px 20px;
  clip-path: polygon(10px 0%, 100% 0%, calc(100% - 10px) 100%, 0% 100%);
}

.stat-row {
  display: grid;
  grid-template-columns: 70px 1fr auto 70px;
  align-items: center;
  gap: 8px;
}

.stat-row .stat-name { color: var(--fg-bright); font-family: var(--display); letter-spacing: 0.04em; font-size: 0.92rem; }
.stat-row .stat-value { text-align: center; font-size: 1.1rem; font-family: var(--mono); color: var(--gold-bright); }
.stat-row .stepper { display: flex; gap: 4px; }
.stat-row .stepper button { padding: 6px 10px; min-height: 36px; min-width: 36px; }

.pool-remaining { text-align: center; font-size: 1.1rem; font-family: var(--mono); }
.pool-remaining.zero { color: var(--gold-bright); }
.pool-remaining.over { color: var(--danger); }

.hp-preview { text-align: center; font-size: 1.05rem; font-family: var(--mono); color: var(--fg-bright); }

.roster-sub {
  color: var(--fg);
  opacity: 0.85;
  font-size: 0.85rem;
  font-family: var(--display);
  letter-spacing: 0.03em;
}

.roster {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.contestant-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: linear-gradient(165deg, var(--bg-raised), var(--bg));
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease;
}

.contestant-card::before,
.contestant-card::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--fg-dim);
  opacity: 0.7;
  transition: opacity 0.15s ease, border-color 0.15s ease, width 0.15s ease, height 0.15s ease;
}

.contestant-card::before {
  top: -1px;
  left: -1px;
  border-right: none;
  border-bottom: none;
}

.contestant-card::after {
  bottom: -1px;
  right: -1px;
  border-left: none;
  border-top: none;
}

.contestant-card:hover::before,
.contestant-card:hover::after,
.contestant-card:focus-within::before,
.contestant-card:focus-within::after {
  opacity: 1;
  border-color: var(--gold);
  width: 20px;
  height: 20px;
}

.contestant-card:focus-within { border-color: var(--fg-dim); }

.contestant-name {
  font-size: 1.2rem;
  font-family: var(--display);
  color: var(--gold-bright);
  text-shadow: 0 0 8px rgba(255, 184, 77, 0.5);
  letter-spacing: 0.04em;
}

.contestant-meta {
  display: inline-block;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--fg-dim);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 3px 14px 3px 18px;
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}

.intro-text {
  animation: flicker 2.4s ease-in-out infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 1; }
  48% { opacity: 1; }
  50% { opacity: 0.82; }
  52% { opacity: 1; }
}

/* Toolbar slots — shared between the in-world action bar (world.html sets
   width/height via --slot) and the Storage screen's toolbar mock below. Icon art (WoW-style
   favicon-per-ability/item, see public/icons/SOURCES.md) now fills the slot instead of a text
   label -- name/rank/description moved entirely into the tap-for-details tooltip, the same
   interaction this project already had everywhere else an item/ability shows up. */
.slot-button {
  position: relative;
  width: 56px;
  height: 56px;
  clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
  background: linear-gradient(165deg, var(--bg-raised), var(--bg));
  border: 1.5px solid var(--fg-dim);
  color: var(--fg-bright);
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.62rem;
  text-align: center;
  line-height: 1.2;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  user-select: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.slot-button.active { border-color: var(--gold); background: rgba(255, 184, 77, 0.16); box-shadow: 0 0 16px rgba(255, 184, 77, 0.4); color: var(--gold-bright); }
.slot-button.empty { opacity: 0.35; border-style: dashed; }
.slot-button.depleted { opacity: 0.5; }
.slot-button.drop-hover { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset, 0 0 14px rgba(255, 184, 77, 0.5); }
/* Press-and-hold-to-swap's "charging" cue (see attachPayloadLongPress, world.ts) -- the ring
   tightens and brightens over the same duration as LONG_PRESS_MS so the glow visibly finishes
   right as the Arsenal actually opens, not before or after. The 450ms below is that constant
   restated in CSS (no shared source between the two files) -- keep them in sync if either
   changes. */
.slot-button.long-pressing { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset, 0 0 18px rgba(255, 184, 77, 0.65); transform: scale(0.94); transition-duration: 450ms; }
.slot-button[hidden] { display: none; }
.slot-button .slot-icon { width: 80%; height: 80%; object-fit: contain; pointer-events: none; }
.slot-button .slot-qty {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-family: var(--mono);
  font-size: 0.64rem;
  color: var(--gold-bright);
  text-shadow: 0 0 2px #000, 0 0 2px #000;
  pointer-events: none;
}

.toolbar-mock {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.action-bar-gap-mock { width: 16px; }

.storage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
}

.storage-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  background: var(--bg);
  /* Rarity border (WoW-style, see RARITY_COLORS/public/icons/SOURCES.md) is set inline per
     tile via --tile-rarity -- a plain var() with the old --border fallback so a tile built
     with no rarity (never happens today, every consumable has one, but kept defensive) still
     renders exactly as before. */
  border: 1.5px solid var(--tile-rarity, var(--border));
  border-radius: 10px;
  padding: 8px 6px 6px;
  min-height: 72px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease;
}
.storage-tile:hover { border-color: var(--fg-dim); }
.storage-tile:active { cursor: grabbing; }
.storage-tile.dragging { opacity: 0.3; }
.storage-tile .tile-icon { width: 36px; height: 36px; object-fit: contain; }
.storage-tile .tile-name {
  font-family: var(--display);
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.storage-tile .tile-qty {
  position: absolute;
  top: 3px;
  right: 5px;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--gold-bright);
  text-shadow: 0 0 3px #000;
}

/* Generic small icon thumbnail -- the WoW-style "favicon" for an item/ability wherever it
   shows up as a text ROW rather than a grid tile (Vendor, Arsenal, Character equip slots,
   Shop lists -- see iconForItem/iconForAbility, shared/rules.ts). Rarity border set inline
   the same way as .storage-tile above; rows with no rarity concept (abilities, empty slots)
   just keep the default border color. */
.item-icon {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  object-fit: contain;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg);
}

.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.92;
  box-shadow: 0 0 20px rgba(255, 184, 77, 0.45);
}

/* A row/tile that opens the shared item-tooltip popover on tap -- a plain visual hint that
   it's inspectable, independent of whatever else a tap on it might also do. */
.inspectable { cursor: pointer; }
.inspectable:active { opacity: 0.75; }

/* ---------- Shared item tooltip (Storage / Character / Inventory / toolbar) ---------- */
.item-popover {
  position: fixed;
  z-index: 20;
  /* 560px (not 280px) so the two-card equip-comparison layout (.it-compare below) has room
     to sit side by side on wider viewports -- harmless for every plain single-card tooltip
     since this is a max-width on a shrink-to-fit box: a normal card's own content is well
     under 280px already, so it renders at the same size it always has. */
  max-width: min(560px, calc(100vw - 32px));
  background: linear-gradient(165deg, var(--bg-raised), var(--bg));
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--body);
  color: var(--fg-bright);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}
.item-popover[hidden] { display: none; }
.it-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.it-icon { width: 32px; height: 32px; flex: 0 0 32px; object-fit: contain; border-radius: 7px; border: 1.5px solid var(--border); background: var(--bg); }
.it-name { font-family: var(--display); font-weight: 700; letter-spacing: 0.02em; font-size: 0.92rem; }
.it-rarity { font-family: var(--mono); font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.85; margin-top: 1px; margin-bottom: 5px; }
.it-desc { font-size: 0.8rem; opacity: 0.92; margin-bottom: 4px; }
.it-effect { font-family: var(--mono); font-size: 0.78rem; color: var(--gold-bright); margin-bottom: 2px; }
/* Epic-item "chance on hit" proc line (itemProcLine, shared/rules.ts) -- epic rarity's own
   purple (RARITY_COLORS.epic) so a proc reads as the same tier of flashy as the item's own
   name color, distinct from the plain gold flat-bonus effectLine right above it. */
.it-proc { font-family: var(--mono); font-size: 0.72rem; color: #c158ff; margin-bottom: 2px; }
.it-extra { font-family: var(--mono); font-size: 0.72rem; color: var(--fg); opacity: 0.8; margin-bottom: 2px; }
.it-qty { font-family: var(--mono); font-size: 0.72rem; color: var(--fg-dim); margin-top: 3px; }

/* Equip-comparison popover (see showItemComparisonPopover in client/tooltip.ts): the tapped
   item's card (plain .it-name/.it-rarity/etc, unchanged) next to a second "Equipped" card.
   flex-wrap, not a fixed two-column grid -- each card's 190px min-width means two of them
   plus the gap (390px) don't fit a ~390px-wide phone screen (minus the popover's own
   padding), so they stack instead of squeezing into an unreadable sliver; wider viewports
   get the side-by-side layout the "second tooltip next to it" request asked for. */
.it-compare { display: flex; flex-wrap: wrap; gap: 10px; }
.it-compare > .it-card { flex: 1 1 200px; min-width: 190px; }
.it-card-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
  margin-bottom: 5px;
}

/* ---------- Shared entity tooltip (player / NPC / mob) ---------- */
.et-name { font-family: var(--display); font-weight: 600; letter-spacing: 0.03em; }
.et-badge {
  display: inline-block;
  margin-top: 2px;
  font-family: var(--display);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 6px;
}
.et-hpbar { width: 100%; min-width: 90px; height: 5px; background: rgba(255, 255, 255, 0.14); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.et-hpbar-fill { height: 100%; background: linear-gradient(90deg, var(--danger), var(--gold)); }
.et-hptext { font-family: var(--mono); font-size: 0.68rem; margin-top: 2px; }
.et-stats { font-family: var(--mono); font-size: 0.7rem; margin-top: 2px; white-space: nowrap; }
.et-hint { font-family: var(--mono); font-size: 0.65rem; opacity: 0.7; margin-top: 2px; }

/* ---------- Shared toast notifications (see client/toast.ts) ---------- */
/* --topbar-h is only ever defined on pages with a top menu bar (world.html); the fallback
   keeps this usable as-is on any page that doesn't declare it. */
#toast-container {
  position: fixed; top: calc(var(--topbar-h, 0px) + 10px); left: 50%; transform: translateX(-50%);
  z-index: 20; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto; cursor: pointer; white-space: nowrap;
  background: linear-gradient(165deg, var(--bg-raised), var(--bg)); border: 1.5px solid var(--gold);
  border-radius: 10px; padding: 9px 16px; color: var(--fg-bright); font-family: var(--display);
  font-weight: 600; font-size: 0.78rem; letter-spacing: 0.02em; text-align: center;
  text-shadow: 0 0 8px rgba(255, 184, 77, 0.4); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0; transform: translateY(-10px); transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.open { opacity: 1; transform: translateY(0); }
.toast-info { border-color: var(--fg-dim); text-shadow: 0 0 8px rgba(57, 230, 196, 0.35); }
.toast-warning { border-color: var(--danger); color: var(--danger); text-shadow: 0 0 8px rgba(255, 85, 119, 0.4); }

@media (prefers-reduced-motion: reduce) {
  .ambient-overlay,
  .boot::after,
  .intro-text {
    animation: none;
  }
  .toast { transition: none; }
}

@media (min-width: 640px) {
  .race-grid { grid-template-columns: 1fr 1fr; }
}
