@font-face {
  font-family: 'Press Start 2P';
  src: url('./vendor/fonts/press-start-2p.woff2') format('woff2');
  font-display: swap;
}

:root {
  --bg: #0b0811;
  --bg-2: #130f1d;
  --panel: #161021;
  --panel-2: #1d162b;
  --line: #332748;
  --line-2: #4a3864;
  --ink: #f6eadb;
  --muted: #a394b3;
  --dim: #6d5f7d;
  --pink: #ff4fa3;
  --cyan: #52e5ff;
  --lime: #b6ff5c;
  --amber: #ffbf4d;
  --red: #ff4d5e;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-ui: 'Consolas', 'Cascadia Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: none;
  user-select: none;
}

button, input, select { font-family: inherit; }
button { cursor: pointer; }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 120%, #2a1030 0%, transparent 60%),
    #08060d;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #08060d;
}

#gfx-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
#gfx-overlay .vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 45%, transparent 35%, rgba(4, 2, 9, .62) 88%, rgba(3, 1, 7, .9) 100%);
}
#gfx-overlay .scanlines {
  position: absolute; inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,.16) 0 1px, transparent 1px 3px);
  opacity: .35;
  mix-blend-mode: multiply;
}
#gfx-overlay .grain {
  position: absolute; inset: -50%;
  opacity: .055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 1.2s steps(3) infinite;
}
@keyframes grain-shift {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-2%, 1%); }
  66% { transform: translate(1%, -2%); }
  100% { transform: translate(0, 0); }
}
#damage-flash {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(255, 40, 70, .55) 100%);
  opacity: 0;
  transition: opacity .18s ease-out;
}
#damage-flash.on { opacity: 1; transition: none; }

#ui {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}
#ui input, #ui button, #ui select { pointer-events: auto; }

/* ===================== generic bits ===================== */
.hidden { display: none !important; }
.muted { color: var(--muted); }
kbd {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 4px 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 3px;
  background: #221a30;
  color: var(--ink);
  border-radius: 3px;
  display: inline-block;
  line-height: 1;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 5;
  pointer-events: auto;
}
.screen.active { display: flex; }
.screen.overlay { z-index: 20; background: rgba(6, 4, 10, .72); backdrop-filter: blur(3px); align-items: center; justify-content: center; }

.modal {
  position: relative;
  width: min(570px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(30, 22, 45, .97), rgba(17, 12, 26, .98));
  border: 2px solid var(--line-2);
  box-shadow: 0 0 0 4px rgba(0,0,0,.45), 0 22px 70px rgba(0,0,0,.75), inset 0 0 60px rgba(255, 79, 163, .04);
  padding: 30px;
}
.modal.small { width: min(420px, calc(100vw - 32px)); }
.modal::before, .modal::after {
  content: ''; position: absolute; width: 14px; height: 14px; border-color: var(--pink); border-style: solid; pointer-events: none;
}
.modal::before { top: -2px; left: -2px; border-width: 2px 0 0 2px; }
.modal::after { bottom: -2px; right: -2px; border-width: 0 2px 2px 0; }

.modal-close {
  position: absolute; top: 10px; right: 10px;
  width: 32px; height: 32px;
  background: transparent; color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  line-height: 1;
}
.modal-close:hover { color: var(--ink); border-color: var(--pink); }
.modal-kicker {
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: .2em;
  color: var(--pink);
  margin-bottom: 14px;
}
.modal-title {
  font-family: var(--font-pixel);
  font-size: clamp(16px, 3vw, 22px);
  line-height: 1.5;
  color: var(--ink);
  margin: 0 0 18px;
  text-shadow: 3px 3px 0 rgba(255,79,163,.22);
}
.modal-text { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 18px; }
.ghost-btn {
  display: block; width: 100%;
  margin-top: 14px;
  background: transparent; color: var(--dim);
  border: 1px dashed var(--line-2);
  padding: 10px; font-family: var(--font-pixel); font-size: 8px; letter-spacing: .1em;
}
.ghost-btn:hover { color: var(--red); border-color: var(--red); }

/* ===================== menu ===================== */
#screen-menu {
  flex-direction: column;
  padding: clamp(14px, 3vh, 34px) clamp(16px, 4vw, 56px);
  background:
    linear-gradient(90deg, rgba(7,5,12,.94) 0%, rgba(7,5,12,.72) 42%, rgba(7,5,12,.12) 72%, rgba(7,5,12,.4) 100%),
    linear-gradient(0deg, rgba(7,5,12,.9) 0%, transparent 40%);
}
.menu-top {
  display: flex; align-items: center; justify-content: space-between;
  pointer-events: none;
}
.build-tag {
  font-family: var(--font-pixel); font-size: 7px; letter-spacing: .16em;
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 6px 9px;
  background: rgba(15,11,23,.6);
}
.menu-top-right { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 38px; height: 38px;
  background: rgba(20,14,30,.8);
  border: 1px solid var(--line-2);
  color: var(--muted);
  font-size: 14px;
  transition: .15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--pink); box-shadow: 0 0 18px rgba(255,79,163,.35); }
.icon-btn.off { color: var(--dim); opacity: .55; }

.menu-grid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 40px;
  min-height: 0;
  padding: clamp(8px, 3vh, 40px) 0;
}
.menu-left {
  display: flex;
  flex-direction: column;
  gap: clamp(16px, 3vh, 34px);
  min-width: 0;
  max-width: 620px;
}
.logo-wrap { position: relative; }
.logo-sub {
  font-family: var(--font-pixel);
  font-size: clamp(7px, 1vw, 10px);
  letter-spacing: .38em;
  color: var(--cyan);
  margin-bottom: 14px;
  text-shadow: 0 0 16px rgba(82,229,255,.55);
}
.logo {
  margin: 0;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: clamp(38px, 7.4vw, 96px);
  line-height: .92;
  letter-spacing: .02em;
}
.logo-line { display: block; position: relative; }
.l-shadow {
  position: absolute; left: 7px; top: 8px;
  color: #50143c;
  -webkit-text-stroke: 2px #2a0a20;
}
.l-main {
  position: relative;
  color: #fff4e2;
  text-shadow:
    4px 0 0 #1b0c24, -4px 0 0 #1b0c24, 0 4px 0 #1b0c24, 0 -4px 0 #1b0c24,
    8px 8px 0 rgba(255,79,163,.28),
    0 0 34px rgba(255,79,163,.25);
}
.logo-line:nth-child(2) .l-main { color: var(--pink); text-shadow: 4px 0 0 #1b0c24, -4px 0 0 #1b0c24, 0 4px 0 #1b0c24, 0 -4px 0 #1b0c24, 8px 8px 0 rgba(82,229,255,.22), 0 0 40px rgba(255,79,163,.4); }
.logo-rule {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0 14px;
  color: var(--pink);
  font-size: 9px;
}
.logo-rule i { display: block; height: 2px; width: 74px; background: linear-gradient(90deg, var(--pink), transparent); }
.logo-rule i:last-child { background: linear-gradient(270deg, var(--cyan), transparent); }
.logo-rule em { font-style: normal; color: var(--amber); }
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(11px, 1.2vw, 14px);
  letter-spacing: .06em;
  max-width: 46ch;
}

.menu-buttons { display: flex; flex-direction: column; gap: 9px; max-width: 470px; }
.menu-btn {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  background: linear-gradient(90deg, rgba(32,24,47,.92), rgba(22,16,33,.78));
  border: 2px solid var(--line);
  color: var(--ink);
  transition: transform .12s ease, border-color .12s, box-shadow .12s, background .12s;
  overflow: hidden;
}
.menu-btn::after {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--line-2);
  transition: background .12s;
}
.menu-btn:hover {
  transform: translateX(5px);
  border-color: var(--pink);
  background: linear-gradient(90deg, rgba(58,26,52,.95), rgba(28,18,40,.86));
  box-shadow: 0 0 26px rgba(255,79,163,.22), inset 0 0 22px rgba(255,79,163,.06);
}
.menu-btn:hover::after { background: var(--pink); }
.menu-btn.primary { border-color: rgba(255,79,163,.55); background: linear-gradient(90deg, rgba(76,22,58,.92), rgba(32,18,42,.85)); }
.menu-btn.primary::after { background: var(--pink); }
.menu-btn.primary .mb-key { color: var(--pink); border-color: rgba(255,79,163,.5); }
.menu-btn.danger:hover { border-color: var(--red); }
.menu-btn.danger:hover::after { background: var(--red); }
.menu-btn.wide { width: 100%; }
.mb-key {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line-2);
  color: var(--cyan);
  font-size: 14px;
  background: rgba(8,6,14,.5);
}
.mb-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.mb-body b { font-family: var(--font-pixel); font-size: 11px; letter-spacing: .03em; font-weight: 400; }
.mb-body small { font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.menu-btn:hover .mb-body small { color: var(--ink); opacity: .8; }

.menu-foot {
  display: flex; flex-wrap: wrap; gap: 18px;
  color: var(--dim); font-size: 11px;
}
.menu-foot span { display: flex; align-items: center; gap: 7px; }

.menu-card {
  width: 336px;
  flex: 0 0 auto;
  align-self: center;
  background: linear-gradient(180deg, rgba(25,18,37,.9), rgba(15,11,23,.92));
  border: 2px solid var(--line);
  padding: 20px;
  backdrop-filter: blur(7px);
  box-shadow: 0 18px 60px rgba(0,0,0,.55), inset 0 0 40px rgba(82,229,255,.03);
}
.card-label {
  font-family: var(--font-pixel); font-size: 8px; letter-spacing: .2em; color: var(--cyan);
  display: flex; align-items: center; gap: 10px;
}
.card-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.rat-stage {
  position: relative;
  height: 168px;
  display: grid;
  place-items: center;
  margin: 8px 0 14px;
}
.rat-glow {
  position: absolute; inset: 14% 12%;
  background: radial-gradient(ellipse at center, rgba(255,79,163,.28), transparent 68%);
  filter: blur(12px);
}
.rat-sprite { position: relative; z-index: 1; animation: rat-bob 2.6s ease-in-out infinite; }
.rat-sprite svg { display: block; width: 178px; height: auto; image-rendering: pixelated; filter: drop-shadow(0 10px 14px rgba(0,0,0,.55)); }
@keyframes rat-bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-7px) } }
.rat-shadow {
  position: absolute; bottom: 8px; width: 120px; height: 14px;
  background: radial-gradient(ellipse, rgba(0,0,0,.55), transparent 70%);
}
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field > span {
  font-family: var(--font-pixel); font-size: 7px; letter-spacing: .2em; color: var(--dim);
}
.field input {
  background: #0d0a14;
  border: 2px solid var(--line);
  color: var(--ink);
  padding: 10px 12px;
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: .1em;
  outline: none;
  width: 100%;
}
.field input:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(255,79,163,.12); }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 30px; height: 30px;
  border: 2px solid #0a0710;
  outline: 1px solid var(--line);
  padding: 0;
  transition: transform .1s, outline-color .1s;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.active { outline: 2px solid var(--ink); transform: translateY(-2px); }
.card-sep { height: 1px; background: var(--line); margin: 16px 0 14px; }
.meta-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.meta-stats > div { display: flex; flex-direction: column; gap: 6px; }
.meta-stats span { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .1em; color: var(--dim); }
.meta-stats b { font-family: var(--font-pixel); font-size: 12px; color: var(--amber); }
.card-note { margin-top: 14px; font-size: 10px; line-height: 1.6; color: var(--dim); }

.menu-bottom {
  display: flex; justify-content: space-between; gap: 20px;
  color: #554864;
  font-size: 10px;
  letter-spacing: .05em;
  border-top: 1px solid rgba(51,39,72,.55);
  padding-top: 12px;
}
.seedline { color: var(--dim); }

/* ===================== lobby ===================== */
.lobby-modal { width: min(540px, calc(100vw - 32px)); }
#lobby-create { margin-bottom: 22px; }
.lobby-modal .menu-btn { margin-top: 8px; }
.join-row { display: flex; gap: 10px; }
.join-row input {
  flex: 1; min-width: 0;
  background: #0d0a14; border: 2px solid var(--line);
  color: var(--ink); padding: 12px;
  font-family: var(--font-pixel); font-size: 14px; letter-spacing: .3em;
  text-align: center; outline: none; text-transform: uppercase;
}
.join-row input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(82,229,255,.1); }
.join-row .menu-btn { width: auto; flex: 0 0 auto; }
.room-code-wrap {
  display: flex; align-items: center; gap: 12px;
  border: 1px dashed var(--line-2);
  padding: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.room-code-label { font-family: var(--font-pixel); font-size: 7px; color: var(--dim); letter-spacing: .18em; }
.room-code {
  font-family: var(--font-pixel); font-size: 34px; letter-spacing: .22em;
  color: var(--amber); text-shadow: 0 0 24px rgba(255,191,77,.45);
  flex: 1;
}
.mini-btn {
  background: transparent; border: 1px solid var(--line-2); color: var(--muted);
  font-family: var(--font-pixel); font-size: 7px; padding: 7px 9px;
}
.mini-btn:hover { color: var(--ink); border-color: var(--cyan); }
.lobby-players { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.lobby-player {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 12px;
  background: rgba(12,9,18,.5);
}
.lobby-player .dot { width: 9px; height: 9px; background: var(--pink); box-shadow: 0 0 10px currentColor; }
.lobby-player .tag { margin-left: auto; font-family: var(--font-pixel); font-size: 6px; color: var(--amber); letter-spacing: .12em; }
.lobby-status { color: var(--muted); font-size: 11px; margin: 12px 0; min-height: 16px; }
.lobby-status.err { color: var(--red); }

/* ===================== settings ===================== */
.opt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid rgba(51,39,72,.5);
}
.opt-row > div { display: flex; flex-direction: column; gap: 4px; }
.opt-row b { font-size: 13px; }
.opt-row small { color: var(--dim); font-size: 11px; }
.opt-row input[type=range] { width: 170px; accent-color: var(--pink); }
.opt-row select {
  background: #0d0a14; border: 1px solid var(--line-2); color: var(--ink);
  padding: 7px 9px; font-size: 12px; outline: none;
}
.toggle {
  min-width: 64px; padding: 8px 10px;
  background: #22182f; color: var(--dim);
  border: 1px solid var(--line-2);
  font-family: var(--font-pixel); font-size: 8px;
}
.toggle.on { color: #0b0811; background: var(--lime); border-color: var(--lime); box-shadow: 0 0 18px rgba(182,255,92,.28); }
.opt-hint { margin-top: 16px; font-size: 11px; color: var(--dim); }

/* ===================== credits ===================== */
.credits-body { font-size: 12.5px; line-height: 1.75; color: var(--muted); }
.credits-body p { margin: 0 0 14px; }
.credits-body ul { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; }
.credits-body li { display: flex; gap: 10px; justify-content: space-between; border-bottom: 1px dotted rgba(51,39,72,.7); padding-bottom: 6px; }
.credits-body li span { font-family: var(--font-pixel); font-size: 7px; letter-spacing: .12em; color: var(--dim); }
.credits-body li em { font-style: normal; color: var(--ink); font-size: 12px; text-align: right; }

/* ===================== cards ===================== */
#screen-cards { flex-direction: column; }
.cards-wrap { display: flex; flex-direction: column; align-items: center; width: min(940px, 96vw); }
.cards-kicker {
  font-family: var(--font-pixel); font-size: 8px; letter-spacing: .24em; color: var(--cyan);
  margin-bottom: 16px;
}
.cards-title {
  font-family: var(--font-pixel); font-size: clamp(14px, 2.6vw, 22px);
  margin: 0 0 30px; text-shadow: 4px 4px 0 rgba(255,79,163,.2);
  text-align: center;
}
.cards-row { display: flex; gap: 18px; justify-content: center; flex-wrap: wrap; width: 100%; }
.mutation-card {
  position: relative;
  width: min(250px, 30vw); min-width: 200px;
  padding: 22px 18px 20px;
  text-align: left;
  background: linear-gradient(180deg, rgba(34,25,50,.98), rgba(16,12,24,.98));
  border: 2px solid var(--line-2);
  color: var(--ink);
  transition: transform .12s ease, box-shadow .12s, border-color .12s;
  animation: card-in .28s ease backwards;
}
.mutation-card:nth-child(2) { animation-delay: .07s; }
.mutation-card:nth-child(3) { animation-delay: .14s; }
@keyframes card-in { from { opacity: 0; transform: translateY(24px) scale(.96); } }
.mutation-card:hover { transform: translateY(-8px); border-color: var(--rar, var(--pink)); box-shadow: 0 24px 44px rgba(0,0,0,.55), 0 0 30px color-mix(in srgb, var(--rar, var(--pink)) 30%, transparent); }
.mutation-card .rarity {
  font-family: var(--font-pixel); font-size: 6px; letter-spacing: .2em; color: var(--rar, var(--pink));
  margin-bottom: 12px;
}
.mutation-card .card-icon {
  width: 58px; height: 58px; display: grid; place-items: center;
  border: 1px solid var(--line-2);
  margin-bottom: 16px;
  font-size: 26px;
  background: rgba(9,7,14,.6);
  color: var(--rar, var(--pink));
  text-shadow: 0 0 18px currentColor;
}
.mutation-card h3 { font-family: var(--font-pixel); font-size: 11px; line-height: 1.6; margin: 0 0 10px; }
.mutation-card p { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
.mutation-card .card-pick {
  margin-top: 16px; font-family: var(--font-pixel); font-size: 7px; letter-spacing: .18em;
  color: var(--dim); display: flex; align-items: center; gap: 8px;
}
.mutation-card:hover .card-pick { color: var(--ink); }
.cards-timer { width: min(420px, 82vw); height: 4px; background: #221a30; margin-top: 30px; }
.cards-timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); }

/* ===================== pause / end ===================== */
.pause-actions { display: flex; flex-direction: column; gap: 8px; }
.pause-controls {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}
.pause-controls div { display: flex; align-items: center; gap: 6px; }
.end-modal { text-align: center; width: min(560px, calc(100vw - 32px)); }
.end-crown { font-size: 46px; line-height: 1; margin-bottom: 14px; color: var(--red); text-shadow: 0 0 30px currentColor; }
.end-modal.win .end-crown { color: var(--amber); }
.end-modal.win .modal-kicker { color: var(--amber); }
.end-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 22px 0 24px;
}
.end-stats > div {
  border: 1px solid var(--line);
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 7px;
  background: rgba(9,7,14,.4);
}
.end-stats span { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .1em; color: var(--dim); }
.end-stats b { font-family: var(--font-pixel); font-size: 14px; color: var(--ink); }
.end-stats b.gold { color: var(--amber); }
.end-actions { display: flex; gap: 10px; justify-content: stretch; }
.end-actions .menu-btn { flex: 1; }

/* ===================== HUD ===================== */
#hud {
  position: absolute; inset: 0;
  z-index: 4;
  pointer-events: none;
  font-size: 12px;
}
.hud-top-left { position: absolute; top: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; }
.player-chip {
  display: flex; gap: 11px; align-items: center;
  background: linear-gradient(90deg, rgba(12,9,18,.86), rgba(12,9,18,.42));
  border: 1px solid rgba(74,56,100,.7);
  border-left: 3px solid var(--pink);
  padding: 9px 16px 9px 10px;
  min-width: 292px;
  backdrop-filter: blur(4px);
}
.chip-avatar {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 60%, rgba(255,79,163,.18), rgba(8,6,13,.9));
  flex: 0 0 auto;
}
.chip-avatar svg { width: 36px; height: auto; }
.chip-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.chip-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.chip-row b {
  font-family: var(--font-pixel); font-size: 9px; letter-spacing: .06em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}
.chip-lvl { font-family: var(--font-pixel); font-size: 7px; color: var(--amber); letter-spacing: .06em; }
.chip-lvl i { font-style: normal; color: var(--ink); }
.bar {
  position: relative; height: 14px;
  background: #150f20;
  border: 1px solid #06040a;
  outline: 1px solid rgba(74,56,100,.6);
  overflow: hidden;
}
.bar i { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width .18s ease-out; }
.bar.hp i { background: linear-gradient(180deg, #ff7390, #d42a4c 55%, #8f0f2c); box-shadow: 0 0 12px rgba(255,77,94,.45); }
.bar.xp { height: 6px; }
.bar.xp i { background: linear-gradient(180deg, #8df6ff, #2bb8d8); box-shadow: 0 0 10px rgba(82,229,255,.4); }
.bar span {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--font-pixel); font-size: 6px; letter-spacing: .1em;
  color: #fff; text-shadow: 1px 1px 0 #000;
  z-index: 1;
  pointer-events: none;
}
.bar.xp span { display: none; }
.chip-resources { display: flex; gap: 6px; }
.res {
  display: flex; align-items: center; gap: 6px;
  background: rgba(12,9,18,.8);
  border: 1px solid rgba(74,56,100,.5);
  padding: 5px 9px;
  font-family: var(--font-pixel); font-size: 8px;
}
.res small { font-family: var(--font-ui); font-size: 8px; color: var(--dim); letter-spacing: .08em; }
.res b { color: var(--amber); font-size: 9px; }
.res-icon { width: 9px; height: 9px; display: block; background: var(--amber); box-shadow: 0 0 8px currentColor; }
.res-icon.crumb { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.res-icon.kill { clip-path: polygon(0 0, 100% 0, 50% 100%); background: var(--red); }
.res-icon.mut { clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); background: var(--cyan); }
.party { display: flex; flex-direction: column; gap: 5px; }
.party-member {
  display: flex; align-items: center; gap: 8px;
  background: rgba(12,9,18,.72); border: 1px solid rgba(74,56,100,.5);
  padding: 5px 9px; font-size: 10px;
}
.party-member .pdot { width: 8px; height: 8px; }
.party-member .pbar { width: 70px; height: 5px; background: #221a30; }
.party-member .pbar i { display: block; height: 100%; background: var(--pink); }
.party-member.down { opacity: .55; }
.party-member.down .pdot { animation: blink .7s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.hud-top-right { position: absolute; top: 16px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.minimap-frame {
  position: relative;
  padding: 6px;
  background: rgba(10,7,16,.82);
  border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0,0,0,.5), inset 0 0 30px rgba(82,229,255,.04);
  backdrop-filter: blur(4px);
}
#minimap { display: block; width: 180px; height: 180px; image-rendering: pixelated; }
.minimap-cross { position: absolute; width: 8px; height: 8px; border: 1px solid var(--cyan); opacity: .7; }
.minimap-cross.tl { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.minimap-cross.tr { top: -1px; right: -1px; border-width: 1px 1px 0 0; }
.minimap-cross.bl { bottom: -1px; left: -1px; border-width: 0 0 1px 1px; }
.minimap-cross.br { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.minimap-label {
  position: absolute; bottom: 8px; left: 10px;
  font-family: var(--font-pixel); font-size: 6px; letter-spacing: .16em; color: var(--cyan);
  background: rgba(8,6,13,.75); padding: 3px 5px;
}
.compass {
  font-family: var(--font-pixel); font-size: 8px; color: var(--dim);
  border: 1px solid var(--line); padding: 4px 8px; background: rgba(10,7,16,.7);
}

.hud-objective {
  position: absolute; left: 16px; bottom: 18px;
  width: min(340px, 34vw);
  background: linear-gradient(90deg, rgba(12,9,18,.9), rgba(12,9,18,.55));
  border-left: 3px solid var(--cyan);
  border-top: 1px solid rgba(74,56,100,.6);
  border-bottom: 1px solid rgba(74,56,100,.6);
  padding: 11px 14px;
  backdrop-filter: blur(4px);
}
.obj-kicker { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .2em; color: var(--cyan); margin-bottom: 7px; }
.obj-name { font-family: var(--font-pixel); font-size: 10px; line-height: 1.5; margin-bottom: 5px; }
.obj-desc { font-size: 11px; color: var(--muted); line-height: 1.5; }
.obj-bar { height: 5px; background: #221a30; margin-top: 9px; }
.obj-bar i { display: block; height: 100%; width: 0%; background: var(--amber); transition: width .2s; }
.obj-meta { margin-top: 8px; font-size: 10px; color: var(--dim); letter-spacing: .04em; }

.hud-abilities {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px;
}
.ability {
  position: relative;
  width: 72px; height: 78px;
  background: rgba(12,9,18,.84);
  border: 1px solid var(--line-2);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 8px;
  overflow: hidden;
}
.ab-icon {
  font-family: var(--font-pixel); font-size: 22px; line-height: 1;
  color: var(--ink); text-shadow: 0 0 14px currentColor;
  margin-bottom: 6px;
}
.ab-name { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .08em; }
.ab-key { font-size: 8px; color: var(--dim); margin-top: 4px; }
.ab-cd {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(4,2,8,.72);
  height: 0%;
  pointer-events: none;
  border-top: 1px solid rgba(255,79,163,.4);
}

.item-bar {
  display: flex; gap: 6px; margin-left: 6px;
}
.item-slot {
  position: relative;
  width: 56px; height: 78px;
  background: rgba(12,9,18,.84);
  border: 1px solid var(--line-2);
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 8px 3px 0;
  overflow: hidden;
}
.item-slot.empty { opacity: .42; border-style: dashed; }
.it-icon {
  font-family: var(--font-pixel); font-size: 17px; line-height: 1;
  color: var(--cyan); text-shadow: 0 0 12px currentColor;
}
.it-name {
  margin-top: 6px;
  font-family: var(--font-pixel); font-size: 5px; line-height: 1.6;
  letter-spacing: .04em; text-align: center; color: var(--muted);
}
.it-key {
  position: absolute; right: 4px; bottom: 3px;
  font-size: 8px; color: var(--dim);
}

.hud-hint {
  position: absolute; bottom: 108px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-pixel); font-size: 7px; color: var(--dim); letter-spacing: .1em;
  text-align: center; min-height: 10px;
}
.banner {
  position: absolute; top: 20%; left: 50%; transform: translate(-50%, 0) scale(.96);
  font-family: var(--font-pixel);
  font-size: clamp(12px, 2.2vw, 20px);
  letter-spacing: .08em;
  color: var(--ink);
  text-align: center;
  text-shadow: 3px 3px 0 rgba(0,0,0,.8), 0 0 30px rgba(255,79,163,.6);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: pre-line;
  width: 90vw;
}
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner .b-kicker { display: block; font-size: .55em; color: var(--amber); margin-bottom: 12px; letter-spacing: .24em; }

.damage-numbers { position: absolute; inset: 0; overflow: hidden; }
.dmg {
  position: absolute;
  font-family: var(--font-pixel); font-size: 9px;
  color: #fff; text-shadow: 2px 2px 0 #4a0014;
  animation: dmg-float .8s ease-out forwards;
  will-change: transform, opacity;
}
.dmg.crit { color: var(--amber); font-size: 12px; }
.dmg.heal { color: var(--lime); }
@keyframes dmg-float {
  0% { transform: translate(-50%, 0) scale(1.25); opacity: 1; }
  100% { transform: translate(-50%, -46px) scale(.85); opacity: 0; }
}
.revive-prompt {
  position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%);
  background: rgba(12,9,18,.9); border: 1px solid var(--amber); color: var(--ink);
  font-family: var(--font-pixel); font-size: 8px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 0 30px rgba(255,191,77,.25);
}
.revive-prompt b { color: var(--amber); }

#toasts {
  position: absolute; right: 16px; bottom: 18px;
  display: flex; flex-direction: column; gap: 7px; align-items: flex-end;
  z-index: 25; pointer-events: none;
}
.toast {
  max-width: 320px;
  background: rgba(14,10,21,.94);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--cyan);
  padding: 9px 12px;
  font-size: 11px; line-height: 1.5; color: var(--ink);
  animation: toast-in .22s ease;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.warn { border-left-color: var(--amber); }
.toast.bad { border-left-color: var(--red); }
.toast.good { border-left-color: var(--lime); }
.toast b { font-family: var(--font-pixel); font-size: 7px; color: var(--cyan); display: block; margin-bottom: 5px; letter-spacing: .1em; }
.toast.out { animation: toast-out .3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

#net-badge {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-family: var(--font-pixel); font-size: 7px; letter-spacing: .1em;
  color: var(--dim); background: rgba(10,7,16,.7);
  border: 1px solid var(--line); padding: 6px 9px;
  z-index: 26;
}
#net-badge .pill { color: var(--lime); }

/* ===================== responsive ===================== */
@media (max-width: 700px) {
  .hud-top-left { top: 8px; left: 8px; gap: 6px; }
  .player-chip { min-width: 0; width: 214px; padding: 6px 8px; }
  .chip-avatar { width: 34px; height: 34px; }
  .chip-avatar svg { width: 27px; }
  .chip-row b { font-size: 7px; max-width: 94px; }
  .bar { height: 12px; }
  .chip-resources { gap: 4px; }
  .res { padding: 4px 6px; font-size: 7px; }
  .res small { display: none; }
  .party-member { padding: 4px 6px; font-size: 9px; }
  .party-member .pbar { width: 46px; }
  .hud-top-right { top: 8px; right: 8px; }
  .minimap-frame { transform: scale(.57); transform-origin: top right; padding: 4px; }
  #minimap { width: 172px; height: 172px; }
  .minimap-label, .compass { display: none; }
  .hud-objective { width: 206px; left: 8px; bottom: 86px; padding: 8px 10px; }
  .obj-kicker { font-size: 5px; margin-bottom: 5px; }
  .obj-name { font-size: 8px; margin-bottom: 4px; }
  .obj-desc { font-size: 10px; }
  .obj-meta { font-size: 9px; margin-top: 5px; }
  .hud-abilities { bottom: 8px; gap: 5px; }
  .ability { width: 56px; height: 58px; padding-top: 5px; }
  .ab-icon { font-size: 16px; margin-bottom: 2px; }
  .ab-name { font-size: 5px; }
  .ab-key { display: none; }
  #toasts { bottom: 74px; right: 8px; }
  .toast { max-width: 236px; font-size: 10px; padding: 7px 9px; }
  .hud-hint { bottom: 70px; font-size: 6px; }
  .revive-prompt { font-size: 7px; bottom: 26%; padding: 9px 12px; }
  .banner { font-size: 12px; }
}

@media (max-width: 1050px) {
  .menu-card { width: 300px; }
  .rat-stage { height: 140px; }
  .rat-sprite svg { width: 150px; }
  .logo { font-size: clamp(34px, 6.6vw, 74px); }
}
@media (max-width: 860px) {
  #screen-menu { justify-content: flex-start; padding-top: 16px; }
  .menu-top { position: absolute; top: 14px; right: 14px; left: 14px; }
  .menu-grid { flex-direction: column; align-items: stretch; justify-content: center; gap: 20px; overflow-y: auto; padding-top: 46px; }
  .menu-left { max-width: none; }
  .logo { font-size: clamp(30px, 9vw, 56px); }
  .tagline { font-size: 11px; }
  .menu-buttons { max-width: none; }
  .menu-card { order: 2; width: 100%; max-width: 440px; align-self: center; }
  .rat-stage { height: 110px; margin: 4px 0 8px; }
  .rat-sprite svg { width: 118px; }
  .menu-foot { display: none; }
  .menu-bottom { font-size: 8px; }
  .hud-objective { width: 260px; bottom: 108px; }
  .hud-abilities { bottom: 12px; }
  .ability { width: 60px; height: 66px; }
  #toasts { bottom: 110px; }
  .minimap-frame { transform: scale(.8); transform-origin: top right; }
}
@media (max-height: 700px) {
  .menu-grid { padding: 4px 0; gap: 16px; }
  .logo { font-size: clamp(30px, 5.6vw, 62px); }
  .logo-rule { margin: 12px 0 8px; }
  .rat-stage { height: 118px; margin: 0 0 8px; }
  .rat-sprite svg { width: 128px; }
  .menu-btn { padding: 9px 14px; }
  .menu-foot { display: none; }
}

/* ================= NIGHT CLOCK / NEW HUD ================= */
.night-clock {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  min-width: 190px; padding: 8px 16px 10px;
  background: linear-gradient(180deg, rgba(20,15,30,.92), rgba(10,7,16,.92));
  border: 1px solid var(--line-2);
  text-align: center;
  box-shadow: 0 8px 22px rgba(0,0,0,.45);
}
.nc-kicker { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .2em; color: var(--muted); margin-bottom: 5px; }
.nc-kicker b { color: var(--amber); }
.nc-time { font-family: var(--font-pixel); font-size: 16px; letter-spacing: .1em; color: var(--ink); text-shadow: 0 0 16px rgba(255,191,77,.5); }
.nc-bar { display: block; height: 4px; margin-top: 7px; background: rgba(255,255,255,.08); overflow: hidden; }
.nc-bar span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); transition: width .2s linear; }
.nc-dawn { display: none; margin-top: 6px; font-family: var(--font-pixel); font-size: 6px; letter-spacing: .18em; color: var(--amber); }
.night-clock.dawn { border-color: var(--amber); box-shadow: 0 0 30px rgba(255,191,77,.35); }
.night-clock.dawn .nc-dawn { display: block; animation: dawn-pulse .8s ease-in-out infinite alternate; }
.night-clock.dawn .nc-time { color: var(--amber); }
.night-clock.upgrade { border-color: var(--cyan); }
.night-clock.upgrade .nc-dawn { display: block; color: var(--cyan); }
.night-clock.upgrade .nc-dawn::after { content: ' - SCEGLI UN POTENZIAMENTO'; }
@keyframes dawn-pulse { from { opacity: .45; } to { opacity: 1; } }

.res-icon.ally { clip-path: polygon(50% 0, 100% 100%, 0 100%); background: var(--lime); }
.res-icon.dump { background: var(--pink); clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%); }

#ab-ruggito .ab-icon { color: var(--lime); }
#ab-ruggito .ab-icon::before { content: '\2620'; }
.ability.cooling { border-color: var(--line); }
.ability.cooling .ab-icon { opacity: .4; }

/* ================= LOOT MODAL ================= */
#screen-loot { background: radial-gradient(ellipse at 50% 40%, rgba(30,20,10,.6), rgba(4,2,8,.9)); align-items: center; justify-content: center; }
.loot-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 1040px; padding: 20px; }
.loot-sub { margin: 0 0 14px; font-size: 12px; color: var(--muted); text-align: center; }
.loot-row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px; }
.loot-card {
  width: min(240px, 28vw); min-width: 190px;
  padding: 20px 16px 18px;
  text-align: left;
  background: linear-gradient(180deg, rgba(34,25,50,.98), rgba(16,12,24,.98));
  border: 2px solid var(--line-2);
  color: var(--ink);
  transition: transform .12s ease, box-shadow .12s, border-color .12s;
  animation: card-in .28s ease backwards;
}
.loot-card:nth-child(2) { animation-delay: .07s; }
.loot-card:nth-child(3) { animation-delay: .14s; }
.loot-card:hover { transform: translateY(-8px); }
.loot-card.food:hover { border-color: var(--lime); box-shadow: 0 0 30px rgba(182,255,92,.25); }
.loot-card.buff:hover { border-color: var(--cyan); box-shadow: 0 0 30px rgba(82,229,255,.25); }
.loot-card.trash:hover { border-color: var(--red); box-shadow: 0 0 30px rgba(255,77,94,.25); }
.loot-icon {
  width: 54px; height: 54px; display: grid; place-items: center;
  border: 1px solid var(--line-2); margin-bottom: 14px;
  font-family: var(--font-pixel); font-size: 18px;
}
.loot-card.food .loot-icon { color: var(--lime); }
.loot-card.buff .loot-icon { color: var(--cyan); }
.loot-card.trash .loot-icon { color: var(--red); }
.loot-card h3 { font-family: var(--font-pixel); font-size: 9px; line-height: 1.6; margin: 0 0 10px; }
.loot-card p { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
.loot-card .card-pick {
  margin-top: 14px; font-family: var(--font-pixel); font-size: 7px;
  letter-spacing: .1em; color: var(--dim);
}
.loot-card:hover .card-pick { color: var(--ink); }

@media (max-width: 720px) {
  .night-clock { top: 8px; min-width: 130px; padding: 6px 10px 8px; }
  .nc-time { font-size: 12px; }
  .loot-card { min-width: 0; width: 100%; }
  .loot-row { flex-direction: column; }
}

/* ===================== menu: green phosphor text ===================== */
#screen-menu { --menu-green: #86ff9e; --menu-green-soft: #b7ffc4; }
#screen-menu .logo-sub {
  color: #9dff6a;
  text-shadow: 0 0 16px rgba(134,255,158,.6);
}
#screen-menu .l-shadow { color: #10381b; -webkit-text-stroke: 2px #07220e; }
#screen-menu .l-main {
  color: #dcffdf;
  text-shadow:
    4px 0 0 #06140b, -4px 0 0 #06140b, 0 4px 0 #06140b, 0 -4px 0 #06140b,
    8px 8px 0 rgba(80,255,128,.24),
    0 0 34px rgba(134,255,158,.3);
}
#screen-menu .logo-line:nth-child(2) .l-main {
  color: #86ff9e;
  text-shadow:
    4px 0 0 #06140b, -4px 0 0 #06140b, 0 4px 0 #06140b, 0 -4px 0 #06140b,
    8px 8px 0 rgba(134,255,158,.22),
    0 0 40px rgba(134,255,158,.45);
}
#screen-menu .logo-rule { color: #86ff9e; }
#screen-menu .logo-rule i { background: linear-gradient(90deg, #86ff9e, transparent); }
#screen-menu .logo-rule i:last-child { background: linear-gradient(270deg, #86ff9e, transparent); }
#screen-menu .logo-rule em { color: #9dff6a; }
#screen-menu .tagline { color: #9fe8ad; }
#screen-menu .build-tag {
  color: #5fbf78;
  border-color: #245c33;
  background: rgba(8,26,14,.62);
}
#screen-menu .mb-body b { color: #a6ffb8; }
#screen-menu .mb-body small { color: #6fcf86; }
#screen-menu .menu-btn { color: #bfffd0; }
#screen-menu .menu-btn:hover .mb-body b { color: #d6ffdf; }
#screen-menu .menu-btn:hover .mb-body small { color: #b7ffc4; opacity: .9; }
#screen-menu .mb-key { color: #86ff9e; }
#screen-menu .menu-btn.primary { border-color: rgba(134,255,158,.55); background: linear-gradient(90deg, rgba(18,64,34,.92), rgba(14,34,22,.85)); }
#screen-menu .menu-btn.primary::after { background: #86ff9e; }
#screen-menu .menu-btn.primary .mb-key { color: #d8ffdf; border-color: rgba(134,255,158,.5); }
#screen-menu .menu-btn:hover { border-color: #86ff9e; background: linear-gradient(90deg, rgba(20,70,38,.95), rgba(14,34,22,.86)); box-shadow: 0 0 26px rgba(134,255,158,.22), inset 0 0 22px rgba(134,255,158,.06); }
#screen-menu .menu-btn:hover::after { background: #86ff9e; }
#screen-menu .menu-foot { color: #4fbf72; }
#screen-menu .menu-bottom { color: #4f9f66; border-top-color: rgba(36,92,51,.6); }
#screen-menu .seedline { color: #5fbf78; }
#screen-menu .card-label { color: #86ff9e; }
#screen-menu .field > span { color: #5fbf78; }
#screen-menu .field input { color: #b7ffc4; border-color: #245c33; }
#screen-menu .field input:focus { border-color: #86ff9e; box-shadow: 0 0 0 3px rgba(134,255,158,.14); }
#screen-menu .meta-stats span { color: #5fbf78; line-height: 1.5; }
#screen-menu .meta-stats b { color: #9dff6a; }
#screen-menu .card-note { color: #4f9f66; }
#screen-menu .card-sep { background: #245c33; }
#screen-menu .rat-glow { background: radial-gradient(ellipse at center, rgba(134,255,158,.26), transparent 68%); }

/* five-item loot from the big bins: keep all cards on one row on desktop */
.loot-row.many { gap: 10px; }
.loot-row.many .loot-card {
  width: min(180px, 17.5vw);
  min-width: 140px;
  padding: 16px 12px 14px;
}
.loot-row.many .loot-card h3 { font-size: 8px; }
.loot-row.many .card-pick { font-size: 6px; }
@media (max-width: 720px) {
  .loot-row.many .loot-card { width: 100%; min-width: 0; }
}

/* ===================== mobile / touch ===================== */
/* keep every modal centred; before this, only .overlay screens were centred */
.screen.active:not(#screen-menu) { align-items: center; justify-content: center; }

#touch-ui { display: none; position: absolute; inset: 0; z-index: 9; pointer-events: none; }
body.touch #touch-ui { display: block; }

#touch-stick {
  position: absolute;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 126px; height: 126px;
  pointer-events: auto;
  touch-action: none;
}
#touch-stick-base {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(82,229,255,.42);
  background: radial-gradient(circle at 50% 45%, rgba(20,16,34,.72), rgba(8,6,14,.42));
  box-shadow: inset 0 0 28px rgba(82,229,255,.12), 0 8px 24px rgba(0,0,0,.4);
}
#touch-stick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(160,250,255,.95), rgba(44,120,160,.75));
  border: 2px solid #bffaff;
  box-shadow: 0 0 20px rgba(82,229,255,.55);
  will-change: transform;
}

#touch-actions {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: auto;
}
.ta-top { display: flex; gap: 8px; }
.ta-row { display: flex; gap: 10px; }
.touch-btn {
  width: 76px; height: 76px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, rgba(40,30,58,.94), rgba(10,8,16,.94));
  border: 2px solid rgba(255,79,163,.55);
  color: var(--ink);
  touch-action: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.45), inset 0 0 18px rgba(255,79,163,.08);
}
.touch-btn b { font-family: var(--font-pixel); font-size: 18px; line-height: 1; color: #ffb7d5; }
.touch-btn small { font-family: var(--font-pixel); font-size: 6px; letter-spacing: .06em; margin-top: 5px; color: var(--muted); }
.touch-btn.held, .touch-btn:active { transform: scale(.94); border-color: var(--pink); background: radial-gradient(circle at 50% 35%, rgba(92,30,70,.96), rgba(20,10,22,.96)); }
.touch-mini {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(10,8,16,.8);
  border: 1px solid rgba(82,229,255,.45);
  color: var(--cyan);
  font-family: var(--font-pixel); font-size: 10px;
  touch-action: none;
}
.touch-mini:active { transform: scale(.94); border-color: var(--pink); color: var(--pink); }

/* the existing ability + item bars become the mobile action bar (top centre) */
body.touch .hud-abilities {
  top: auto;
  bottom: calc(172px + env(safe-area-inset-bottom));
  width: max-content;
  gap: 5px;
  max-width: calc(100vw - 16px);
  flex-wrap: wrap;
  justify-content: center;
}
body.touch .ability { width: 46px; height: 52px; padding-top: 6px; border-color: rgba(82,229,255,.4); pointer-events: auto; touch-action: none; }
body.touch .ab-icon { font-size: 17px; margin-bottom: 3px; }
body.touch .ab-name { font-size: 5px; }
body.touch .ab-key { display: none; }
body.touch .item-bar { gap: 5px; margin-left: 0; }
body.touch .item-slot { width: 40px; height: 52px; padding: 6px 2px 0; pointer-events: auto; touch-action: none; border-color: rgba(255,79,163,.35); }
body.touch .it-icon { font-size: 15px; }
body.touch .it-name { display: none; }
body.touch .it-key { display: none; }

body.touch .hud-objective {
  top: calc(118px + env(safe-area-inset-top));
  bottom: auto;
  width: min(210px, 56vw);
  padding: 7px 10px;
}
body.touch .obj-desc { display: none; }
body.touch .obj-meta { margin-top: 4px; font-size: 9px; }
body.touch .hud-hint { bottom: calc(102px + env(safe-area-inset-bottom)); width: 50vw; font-size: 6px; }
body.touch #toasts { top: auto; bottom: calc(236px + env(safe-area-inset-bottom)); right: 10px; }
body.touch .toast { max-width: 58vw; font-size: 10px; }
body.touch .minimap-frame { pointer-events: none; }
body.touch #hud { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

@media (max-width: 900px), (max-height: 560px) {
  #screen-menu {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
  .menu-top { position: static; align-self: stretch; }
  .menu-grid { flex: 0 0 auto; overflow: visible; padding: 18px 0 28px; justify-content: flex-start; }
  .menu-card { width: min(100%, 430px); }
  .menu-bottom { flex-shrink: 0; }
  .icon-btn { width: 44px; height: 44px; }
  .menu-btn { min-height: 48px; }
  .modal { padding: 22px 18px; max-height: calc(100dvh - 24px); }
  .end-stats { gap: 6px; }
  .pause-controls { display: none; }
  #screen-cards { justify-content: flex-start; overflow-y: auto; padding: 16px 0 26px; }
  #screen-cards .cards-wrap { width: min(520px, 94vw); }
  .cards-title { margin-bottom: 18px; }
  .mutation-card { width: min(430px, 92vw); min-width: 0; padding: 18px 16px; }
  #screen-loot { align-items: flex-start; overflow-y: auto; }
  .loot-wrap { padding: 16px 12px 24px; }
  .loot-row { gap: 8px; margin-bottom: 12px; }
  .loot-card {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    column-gap: 10px;
    align-items: center;
    width: 100%; min-width: 0;
    padding: 10px 12px;
  }
  .loot-icon { width: 40px; height: 40px; margin: 0; font-size: 15px; grid-row: 1 / span 3; }
  .loot-card h3 { margin: 0 0 4px; font-size: 8px; }
  .loot-card p { font-size: 11px; line-height: 1.45; }
  .loot-card .card-pick { grid-column: 2; margin-top: 6px; font-size: 7px; }
  .loot-row.many .loot-card { width: 100%; min-width: 0; }
}

@media (max-width: 430px) {
  body.touch .ability { width: 42px; height: 48px; }
  body.touch .item-slot { width: 36px; height: 48px; }
  #touch-stick { width: 112px; height: 112px; }
  #touch-stick-knob { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
  .touch-btn { width: 68px; height: 68px; }
  .touch-btn b { font-size: 16px; }
  .touch-btn small { font-size: 5.5px; }
  .hud-objective { display: none; }
  .player-chip { width: 200px; }
  .minimap-frame { transform: scale(.5); }
  .night-clock { min-width: 118px; }
}

/* touch devices: keep the player chip compact at every width (landscape phones too) */
body.touch .player-chip { min-width: 0; width: 218px; padding: 6px 8px; }
body.touch .chip-avatar { width: 34px; height: 34px; }
body.touch .chip-avatar svg { width: 27px; }
body.touch .chip-row b { font-size: 7px; max-width: 94px; }
body.touch .bar { height: 12px; }
body.touch .chip-resources { gap: 4px; }
body.touch .res { padding: 4px 6px; font-size: 7px; }
body.touch .res small { display: none; }
body.touch .party-member { padding: 4px 6px; font-size: 9px; }
body.touch .party-member .pbar { width: 46px; }

/* landscape phones: two-column menu instead of a very tall scrolling column */
@media (max-height: 560px) and (orientation: landscape) {
  #screen-menu { justify-content: center; padding: 8px 16px; }
  .menu-top { position: absolute; top: 8px; right: 12px; left: 12px; justify-content: flex-end; }
  .build-tag { display: none; }
  .menu-grid {
    flex-direction: row; align-items: center; justify-content: center;
    gap: 22px; padding: 10px 0 0; overflow: visible; flex: 0 0 auto;
  }
  .menu-left { max-width: 48%; gap: 8px; }
  .logo-sub { margin-bottom: 4px; }
  .logo { font-size: clamp(24px, 4.6vw, 38px); }
  .logo-rule { margin: 6px 0 4px; }
  .tagline { display: none; }
  .rat-stage { display: none; }
  .menu-buttons { gap: 6px; }
  .menu-btn { padding: 8px 12px; min-height: 0; }
  .menu-btn small { display: none; }
  .menu-card { order: 0; width: min(360px, 44vw); max-width: 44vw; align-self: center; }
  .menu-bottom, .menu-foot { display: none; }

  /* keep the intro banner clear of the night clock and ability bar */
  body.touch .banner { top: 32%; font-size: clamp(11px, 1.7vw, 15px); }
  body.touch .banner .b-kicker { margin-bottom: 6px; }
}

/* portrait phones: move the night clock under the minimap so it never covers the player chip */
@media (max-width: 700px) and (orientation: portrait) {
  body.touch .night-clock {
    left: auto; right: 8px; top: 120px; transform: none;
    width: 132px; min-width: 0; padding: 6px 8px 8px;
  }
  body.touch .night-clock .nc-time { font-size: 12px; }
}
@media (max-width: 430px) and (orientation: portrait) {
  body.touch .night-clock { top: 106px; width: 120px; }
}
