/* Pixel Survivors — core stylesheet.
   Design tokens → layout regions → modals → debug → responsive (tablet/phone).
   Canvas is letterboxed via JS (fitCanvas). HUD/title/modals overlay #root viewport. */
:root {
  --bg-0: #08141a;
  --bg-1: #0f1f28;
  --bg-2: #14313e;
  --ink-0: #f1f5f9;
  --ink-1: #94a3b8;
  --acc-0: #ffd23f;      /* gold / xp */
  --acc-1: #e94f37;      /* red / hp / dmg */
  --acc-2: #1bc47d;      /* green / heal */
  --acc-3: #44b3ff;      /* blue / arcane */
  --acc-4: #c084fc;      /* purple / rare */
  --acc-5: #ff7ab6;      /* pink / synergy */
  --frame: #2b3d4a;
  --hp: linear-gradient(180deg, #ff6b6b 0%, #b91c1c 100%);
  --xp: linear-gradient(180deg, #ffe45e 0%, #ffaa00 100%);
  --shadow-deep: 0 4px 24px rgba(0,0,0,0.6);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  --safe-right: env(safe-area-inset-right, 0);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: var(--ink-0);
  font-family: 'Segoe UI', 'SF Pro', system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  /* touch-action manipulation: allows click/tap on UI, blocks pinch-zoom + scroll. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#game {
  touch-action: none;       /* canvas alone disables defaults during gameplay */
}
#root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at center, #0a1820 0%, #02060a 80%);
}
#game {
  display: block;
  background: #0a1820;
  image-rendering: pixelated;
  box-shadow: var(--shadow-deep);
}
.hidden { display: none !important; }

/* ============== PAUSE BUTTON ============== */
#pause-btn {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: rgba(8,20,26,0.78);
  border: 1px solid var(--frame);
  color: var(--ink-0);
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  pointer-events: auto;             /* HUD has pointer-events:none — re-enable for the button */
  box-shadow: var(--shadow-deep);
  z-index: 12;
}
#pause-btn:hover { background: var(--bg-2); }
#pause-btn:active { transform: scale(0.95); }

#paused {
  position: absolute;
  inset: 0;
  background: rgba(2,6,10,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 42;
  padding: calc(20px + var(--safe-top)) 14px calc(20px + var(--safe-bottom)) 14px;
}
.paused-card {
  background: var(--bg-1);
  border: 2px solid var(--frame);
  border-radius: 12px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0,0,0,0.6);
  max-width: 360px;
}
.paused-card h2 {
  margin: 0 0 18px 0;
  font-size: 36px;
  letter-spacing: 6px;
  color: var(--acc-0);
}
.paused-card .hint { margin-top: 12px; font-size: 11px; }

/* ============== LANG SWITCHER ============== */
#lang-switcher {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  z-index: 70;
  display: flex;
  gap: 4px;
  background: rgba(8,20,26,0.7);
  padding: 4px;
  border: 1px solid var(--frame);
  border-radius: 8px;
  pointer-events: auto;
}
.lang-btn {
  background: transparent;
  color: var(--ink-1);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
  font-family: inherit;
  min-width: 36px;
}
.lang-btn:hover { color: var(--ink-0); border-color: var(--frame); }
.lang-btn.active {
  background: var(--acc-0);
  color: #1a0a0a;
  border-color: var(--acc-0);
}

/* ============== TITLE ============== */
#title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 30;
  padding: calc(40px + var(--safe-top)) 14px calc(20px + var(--safe-bottom)) 14px;
  background: radial-gradient(ellipse at center, rgba(8,20,26,0.92) 0%, rgba(2,6,10,0.96) 80%);
  overflow-y: auto;
}
.logo {
  font-size: 72px;
  font-weight: 900;
  letter-spacing: 6px;
  margin: 0 0 4px 0;
  color: var(--ink-0);
  text-shadow: 0 4px 0 #000, 0 0 28px rgba(255,210,63,0.4);
  line-height: 1;
}
.logo span {
  background: linear-gradient(180deg, #ffd23f 0%, #e94f37 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tag {
  margin: 0 0 28px 0;
  font-size: 16px;
  letter-spacing: 4px;
  color: var(--ink-1);
  text-transform: uppercase;
}
#class-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 22px;
  max-width: 760px;
}
.class-card {
  width: 132px;
  padding: 12px 8px 10px 8px;
  background: var(--bg-1);
  border: 2px solid var(--frame);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 120ms ease;
}
.class-card:hover { transform: translateY(-3px); border-color: var(--acc-0); background: var(--bg-2); }
.class-card.selected { border-color: var(--acc-0); box-shadow: 0 0 0 3px rgba(255,210,63,0.25), 0 6px 16px rgba(0,0,0,0.6); transform: translateY(-3px); background: var(--bg-2); }
.class-card img {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.5));
}
.class-card .name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.class-card .perk {
  font-size: 11px;
  color: var(--ink-1);
  line-height: 1.3;
  text-align: center;
  min-height: 28px;
}
.cta {
  background: linear-gradient(180deg, #ffd23f 0%, #e94f37 100%);
  color: #1a0a0a;
  font-weight: 900;
  letter-spacing: 3px;
  font-size: 18px;
  border: none;
  border-radius: 8px;
  padding: 14px 36px;
  cursor: pointer;
  text-transform: uppercase;
  font-family: inherit;
  box-shadow: 0 4px 0 #6b1f10, 0 6px 18px rgba(233,79,55,0.5);
  transition: transform 80ms ease;
  min-height: 48px;     /* touch target */
}
.cta:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 0 #6b1f10, 0 10px 22px rgba(233,79,55,0.5); }
.cta:active { transform: translateY(1px); }
.cta:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-1);
  letter-spacing: 2px;
  max-width: 520px;
}

/* ============== HUD ============== */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-variant-numeric: tabular-nums;
  padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
}
.hud-top {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  background: rgba(8,20,26,0.78);
  border: 1px solid var(--frame);
  border-radius: 8px;
  padding: 6px 18px;
  box-shadow: var(--shadow-deep);
}
.hud-cell { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.hud-cell span:not(.cell-label) { font-size: 22px; font-weight: 900; }
.cell-label { font-size: 9px; letter-spacing: 2px; color: var(--ink-1); }
.hud-cell.timer span:not(.cell-label) { color: var(--acc-0); }
.hud-cell.kills span:not(.cell-label) { color: var(--acc-1); }
.hud-cell.lvl span:not(.cell-label) { color: var(--acc-3); }
.hud-cell.coins span:not(.cell-label) { color: var(--acc-0); }
.meta-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.meta-pill {
  background: rgba(8,20,26,0.72);
  border: 1px solid var(--frame);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--ink-1);
  font-weight: 700;
  letter-spacing: 0.4px;
}
.meta-pill .meta-k { color: var(--acc-0); margin-right: 4px; }

.hud-bottom {
  position: absolute;
  bottom: calc(12px + var(--safe-bottom));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label {
  font-size: 11px;
  font-weight: 900;
  width: 28px;
  text-align: right;
  color: var(--ink-1);
}
.bar {
  position: relative;
  flex: 1;
  height: 14px;
  background: rgba(8,20,26,0.78);
  border: 1px solid var(--frame);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.6);
}
.bar.hp .bar-fill { background: var(--hp); }
.bar.xp { height: 10px; }
.bar.xp .bar-fill { background: var(--xp); }
.bar.shield { height: 8px; }
.bar.shield .bar-fill { background: linear-gradient(180deg, #93c5fd 0%, #2563eb 100%); }
.bar-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transition: width 150ms ease;
}
.bar-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(0,0,0,0.8);
  letter-spacing: 0.5px;
}
.loadout {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
  background: rgba(8,20,26,0.78);
  border: 1px solid var(--frame);
  border-radius: 6px;
  padding: 4px;
  align-self: flex-start;
  max-width: 100%;
  overflow-x: auto;
}
.loadout .lo-row {
  display: flex;
  gap: 3px;
  align-items: center;
}
.loadout .lo-row::before {
  content: attr(class);
  display: none;             /* hidden marker — actual label via ::after below per row */
}
.loadout .lo-weapons::before { content: 'W'; display: inline-block; color: var(--acc-1); font-size: 9px; font-weight: 800; width: 14px; }
.loadout .lo-passives::before { content: 'P'; display: inline-block; color: var(--acc-3); font-size: 9px; font-weight: 800; width: 14px; }
.loadout .lo-abilities::before { content: 'A'; display: inline-block; color: var(--acc-4); font-size: 9px; font-weight: 800; width: 14px; }
.loadout .lo-evolutions::before { content: '★'; display: inline-block; color: var(--acc-5); font-size: 11px; font-weight: 800; width: 14px; }
.loadout .slot {
  position: relative;
  width: 32px;
  height: 32px;
  background: var(--bg-1);
  border: 1px solid var(--frame);
  border-radius: 4px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.loadout .slot img { width: 26px; height: 26px; image-rendering: pixelated; }
.loadout .slot .lvl-pill {
  position: absolute;
  bottom: -3px;
  right: -3px;
  background: var(--acc-0);
  color: #1a0a0a;
  font-size: 9px;
  font-weight: 900;
  padding: 0 3px;
  border-radius: 4px;
  border: 1px solid #1a0a0a;
}
.loadout .slot.evolved {
  border-color: var(--acc-5);
  box-shadow: 0 0 0 1px var(--acc-5), 0 0 10px rgba(255,122,182,0.6);
}
.loadout .slot.empty {
  background: rgba(255,255,255,0.04);
  border-style: dashed;
  opacity: 0.5;
}
.loadout .slot.empty .empty-mark {
  color: var(--ink-1);
  font-size: 14px;
  font-weight: 700;
}
.loadout .slot .cd-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.55);
  pointer-events: none;
}
.loadout .lo-abilities .slot { border-color: rgba(192,132,252,0.5); }
.loadout .lo-weapons .slot { border-color: rgba(233,79,55,0.5); }
.loadout .lo-passives .slot { border-color: rgba(68,179,255,0.5); }

/* ============== MINIMAP ============== */
#minimap {
  position: absolute;
  top: calc(56px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  width: 120px;
  height: 120px;
  border: 1px solid var(--frame);
  border-radius: 8px;
  background: rgba(8,20,26,0.75);
  z-index: 9;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
@media (max-width: 600px) {
  #minimap { width: 90px; height: 90px; top: calc(70px + var(--safe-top)); }
}

/* ============== PAUSED LOADOUT INSPECTOR ============== */
.paused-loadout {
  width: min(560px, 92vw);
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px 6px;
  margin: 14px 0 18px;
  background: rgba(8,20,26,0.6);
  border: 1px solid var(--frame);
  border-radius: 10px;
}
.pl-section { padding: 6px 8px; }
.pl-section h4 {
  margin: 4px 0 6px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--acc-0);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 4px;
}
.pl-section.pl-empty .pl-none {
  font-size: 11px;
  color: var(--ink-1);
  margin: 2px 0 8px;
}
.pl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.pl-row img {
  width: 28px; height: 28px;
  image-rendering: pixelated;
  background: var(--bg-1);
  border-radius: 4px;
  padding: 2px;
  flex-shrink: 0;
}
.pl-text { flex: 1; min-width: 0; text-align: left; }
.pl-label { font-size: 12px; font-weight: 800; color: var(--ink-0); letter-spacing: 0.5px; }
.pl-lvl { color: var(--acc-0); font-size: 10px; margin-left: 4px; }
.pl-desc { font-size: 10px; color: var(--ink-1); line-height: 1.3; margin-top: 1px; }

/* ============== ABILITY HOTBAR (Megabonk-style) ============== */
.ability-bar {
  position: absolute;
  right: calc(10px + var(--safe-right));
  bottom: calc(70px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  z-index: 11;
}
.ability-btn {
  position: relative;
  width: 56px;
  height: 56px;
  padding: 0;
  background: rgba(8,20,26,0.85);
  border: 2px solid var(--frame);
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: var(--shadow-deep);
  transition: transform 0.08s, border-color 0.12s;
}
.ability-btn img {
  width: 40px; height: 40px;
  image-rendering: pixelated;
  pointer-events: none;
}
.ability-btn.empty {
  border-style: dashed;
  opacity: 0.4;
  cursor: not-allowed;
}
.ability-btn.empty img { display: none; }
.ability-btn.ready {
  border-color: var(--acc-0);
  box-shadow: 0 0 0 1px var(--acc-0), 0 0 14px rgba(255,210,63,0.55);
}
.ability-btn:active:not(.empty) { transform: scale(0.94); }
.ability-btn .abk-key {
  position: absolute;
  top: 1px; left: 4px;
  font-size: 11px;
  font-weight: 900;
  color: var(--ink-0);
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
  pointer-events: none;
}
.ability-btn .abk-cd {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.65);
  pointer-events: none;
  height: 0%;
  transition: height 0.05s linear;
}

/* Smaller bar on narrow viewports — still ≥44px touch targets */
@media (max-width: 480px) {
  .ability-bar {
    bottom: calc(70px + var(--safe-bottom));
    right: calc(8px + var(--safe-right));
    gap: 6px;
  }
  .ability-btn { width: 48px; height: 48px; }
  .ability-btn img { width: 34px; height: 34px; }
}

/* ============== LEVEL-UP footer controls (Reroll / Skip) ============== */
.levelup-foot {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.ctl-btn {
  min-width: 130px;
  height: 44px;
  padding: 0 14px;
  background: rgba(20,49,62,0.85);
  color: var(--ink-0);
  border: 1px solid var(--frame);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.ctl-btn:hover:not([disabled]) { background: rgba(34,90,114,0.9); }
.ctl-btn:active:not([disabled]) { transform: scale(0.96); }
.ctl-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.ctl-btn .ctl-count {
  background: var(--acc-0);
  color: #1a0a0a;
  font-size: 11px;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: 8px;
}
.ctl-btn .ctl-sub {
  font-size: 11px;
  color: var(--acc-2);
  font-weight: 700;
  margin-left: 4px;
}

/* New level-up group variants */
.choice-card.ability { border-color: var(--acc-4); box-shadow: 0 0 12px rgba(192,132,252,0.35); }
.choice-card.shield { border-color: var(--acc-3); box-shadow: 0 0 12px rgba(68,179,255,0.35); }

/* ============== LEVEL UP modal ============== */
#levelup {
  position: absolute;
  inset: 0;
  background: rgba(2,6,10,0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 40;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade-in 240ms ease;
  padding: calc(20px + var(--safe-top)) 14px calc(20px + var(--safe-bottom)) 14px;
  overflow-y: auto;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
#levelup h2 {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 6px;
  margin: 0 0 4px 0;
  background: linear-gradient(180deg, #ffe45e 0%, #ffaa00 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 28px rgba(255,210,63,0.5);
  animation: pop 360ms ease;
  text-align: center;
}
@keyframes pop { from { transform: scale(0.7) } to { transform: scale(1.0) } }
#levelup-sub {
  margin: 0 0 26px 0;
  font-size: 14px;
  color: var(--ink-1);
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
}
#levelup-choices {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 920px;
}
.choice-card {
  width: 220px;
  padding: 16px 14px;
  background: var(--bg-1);
  border: 2px solid var(--frame);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  transition: all 120ms ease;
  min-height: 220px;
}
.choice-card:hover { transform: translateY(-4px); border-color: var(--acc-0); background: var(--bg-2); box-shadow: 0 8px 20px rgba(0,0,0,0.6); }
.choice-card.synergy { border-color: var(--acc-5); box-shadow: 0 0 0 1px var(--acc-5), 0 8px 24px rgba(255,122,182,0.4); background: linear-gradient(180deg, #2a1633 0%, #14313e 100%); }
.choice-card.weapon { border-color: var(--acc-3); }
.choice-card img {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,0.5));
}
.choice-card .ck-title {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.choice-card.synergy .ck-title { color: var(--acc-5); }
.choice-card.weapon .ck-title { color: var(--acc-3); }
.choice-card .ck-desc {
  font-size: 12px;
  color: var(--ink-1);
  line-height: 1.4;
  min-height: 44px;
}
.choice-card .ck-tag {
  font-size: 9px;
  letter-spacing: 2px;
  font-weight: 800;
  color: var(--ink-1);
  text-transform: uppercase;
  padding: 2px 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
}
.choice-card.synergy .ck-tag { color: var(--acc-5); background: rgba(255,122,182,0.12); }

/* ============== TITLE ACTIONS + RECORDS MODAL ============== */
.title-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.cta.secondary {
  background: linear-gradient(180deg, #475569 0%, #1e293b 100%);
  color: var(--ink-0);
  box-shadow: 0 4px 0 #0f172a, 0 6px 14px rgba(0,0,0,0.5);
  letter-spacing: 2px;
  font-size: 14px;
  padding: 12px 22px;
}
.cta.secondary:hover:not(:disabled) { box-shadow: 0 6px 0 #0f172a, 0 10px 18px rgba(0,0,0,0.55); }

#records {
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(2,6,10,0.94);
  padding: calc(20px + var(--safe-top)) 14px calc(20px + var(--safe-bottom)) 14px;
  overflow-y: auto;
}
.records-shell {
  max-width: 920px;
  margin: 0 auto;
}
.records-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.records-head h2 { margin: 0; font-size: 32px; font-weight: 900; letter-spacing: 4px; }
.close-btn {
  background: transparent;
  border: 1px solid var(--frame);
  color: var(--ink-0);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
}
.close-btn:hover { background: var(--bg-1); }
.records-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.rec-tab {
  background: var(--bg-1);
  border: 1px solid var(--frame);
  color: var(--ink-1);
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 800;
  letter-spacing: 1.5px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.rec-tab.active { background: var(--acc-0); color: #1a0a0a; border-color: var(--acc-0); }
.records-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-1);
  border: 1px solid var(--frame);
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
}
.records-table th {
  background: var(--bg-2);
  color: var(--ink-1);
  font-size: 10px;
  letter-spacing: 1.5px;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--frame);
}
.records-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.records-table .r-num { font-variant-numeric: tabular-nums; }
.records-table .r-wpn { width: 22px; height: 22px; image-rendering: pixelated; vertical-align: middle; margin-right: 2px; }
.records-table tr:last-child td { border-bottom: none; }
.r-win { color: var(--acc-2); font-weight: 900; letter-spacing: 1px; }
.r-lose { color: var(--acc-1); font-weight: 900; letter-spacing: 1px; }
.records-empty { color: var(--ink-1); padding: 20px; text-align: center; }
.records-foot { margin-top: 16px; text-align: center; }
.link-btn {
  background: transparent;
  color: var(--ink-1);
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  text-decoration: underline;
}
.link-btn:hover { color: var(--acc-1); }
.share-block { background: var(--bg-1); border: 1px solid var(--frame); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.share-block p { margin: 0 0 10px 0; color: var(--ink-1); font-size: 13px; }
.share-block label { display: block; font-size: 11px; color: var(--ink-1); letter-spacing: 1.5px; margin-bottom: 8px; }
.share-block textarea {
  width: 100%;
  background: var(--bg-0);
  color: var(--ink-0);
  border: 1px solid var(--frame);
  border-radius: 6px;
  padding: 10px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 11px;
  resize: vertical;
  min-height: 56px;
  margin-bottom: 8px;
  box-sizing: border-box;
}
#copy-feedback { color: var(--acc-2); font-size: 12px; margin-left: 8px; }
.imported-card {
  background: var(--bg-0);
  border: 1px solid var(--frame);
  border-radius: 8px;
  padding: 12px;
  margin-top: 10px;
}
.imported-card h3 { margin: 0 0 6px 0; font-size: 16px; }
.imported-card p { color: var(--ink-1); font-size: 12px; margin: 0 0 8px 0; }
.r-loadout { display: flex; flex-wrap: wrap; gap: 4px; }

/* ============== END CARD ============== */
#endcard {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(8,20,26,0.95) 0%, rgba(2,6,10,0.98) 80%);
  z-index: 50;
  text-align: center;
  padding: calc(40px + var(--safe-top)) 14px calc(20px + var(--safe-bottom)) 14px;
  overflow-y: auto;
}
#endcard h2 {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 6px;
  margin: 0 0 12px 0;
  line-height: 1;
}
#endcard h2.win {
  background: linear-gradient(180deg, #ffe45e 0%, #ffaa00 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#endcard h2.lose {
  background: linear-gradient(180deg, #ff6b6b 0%, #b91c1c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#endcard-stats {
  display: flex;
  gap: 22px;
  margin-bottom: 18px;
  font-size: 16px;
  flex-wrap: wrap;
  justify-content: center;
}
#endcard-stats .es-cell { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
#endcard-stats .es-val { font-size: 28px; font-weight: 900; color: var(--acc-0); }
#endcard-stats .es-label { font-size: 10px; letter-spacing: 2px; color: var(--ink-1); }
#endcard-loadout {
  display: flex;
  gap: 6px;
  margin-bottom: 28px;
  max-width: 720px;
  flex-wrap: wrap;
  justify-content: center;
}
#endcard-loadout .slot {
  width: 44px;
  height: 44px;
  background: var(--bg-1);
  border: 2px solid var(--frame);
  border-radius: 6px;
  display: grid;
  place-items: center;
  position: relative;
}
#endcard-loadout .slot.evolved { border-color: var(--acc-5); box-shadow: 0 0 12px rgba(255,122,182,0.5); }
#endcard-loadout .slot img { width: 36px; height: 36px; image-rendering: pixelated; }
#endcard-loadout .slot .lvl-pill {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--acc-0);
  color: #1a0a0a;
  font-size: 10px;
  font-weight: 900;
  padding: 1px 4px;
  border-radius: 4px;
}

/* ============== DEBUG ============== */
#debug {
  position: absolute;
  top: calc(48px + var(--safe-top));
  right: calc(8px + var(--safe-right));
  background: rgba(0,0,0,0.7);
  padding: 8px 10px;
  border-radius: 4px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 11px;
  color: #b5e853;
  white-space: pre;
  z-index: 60;
  pointer-events: none;
}

/* ============== TOUCH ============== */
#touch {
  display: none;                       /* hidden by default; shown on touch devices */
  position: absolute;
  bottom: calc(60px + var(--safe-bottom));
  left: calc(20px + var(--safe-left));
  z-index: 15;
  pointer-events: none;                /* visual only — input handler is on #root */
}
#stick {
  width: 160px;
  height: 160px;
  border-radius: 80px;
  background: rgba(20,49,62,0.28);
  border: 2px solid rgba(255,255,255,0.18);
  position: relative;
  touch-action: none;
}
#stick-knob {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 36px;
  background: rgba(255,210,63,0.62);
  top: 44px;
  left: 44px;
  box-shadow: 0 0 14px rgba(255,210,63,0.55);
  transition: top 50ms ease, left 50ms ease;
}
#touch-hint {
  position: absolute;
  bottom: 174px;
  left: 0;
  width: 160px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.55);
  text-transform: uppercase;
  pointer-events: none;
}

/* ============== RESPONSIVE — Tablet ============== */
@media (max-width: 900px) {
  .logo { font-size: 56px; letter-spacing: 4px; }
  .tag { font-size: 14px; letter-spacing: 3px; }
  .class-card { width: 116px; }
  .class-card img { width: 56px; height: 56px; }
  .choice-card { width: 180px; min-height: 200px; }
  #endcard h2 { font-size: 54px; }
}

/* ============== RESPONSIVE — Phone ============== */
@media (max-width: 600px) {
  .logo { font-size: 42px; letter-spacing: 3px; }
  .tag { font-size: 11px; letter-spacing: 2px; margin-bottom: 18px; }
  #class-picker { gap: 8px; }
  .class-card { width: calc(50% - 6px); max-width: 160px; padding: 10px 8px; }
  .class-card img { width: 56px; height: 56px; }
  .class-card .name { font-size: 13px; }
  .class-card .perk { font-size: 11px; min-height: 30px; }
  .cta { padding: 14px 28px; font-size: 16px; letter-spacing: 2px; }
  .hint { font-size: 11px; letter-spacing: 1px; }

  .hud-top { gap: 10px; padding: 4px 12px; }
  .hud-cell { min-width: 44px; }
  .hud-cell span:not(.cell-label) { font-size: 18px; }
  .cell-label { font-size: 8px; }
  .bar { height: 12px; }
  .bar.xp { height: 8px; }

  #levelup h2 { font-size: 30px; letter-spacing: 2px; margin-top: 4px; }
  #levelup-sub { font-size: 12px; letter-spacing: 2px; margin-bottom: 16px; }
  #levelup-choices { gap: 10px; }
  .choice-card { width: calc(100% - 8px); max-width: 320px; min-height: 0; padding: 12px 10px; flex-direction: row; text-align: left; gap: 10px; }
  .choice-card img { width: 56px; height: 56px; flex-shrink: 0; }
  .choice-card .ck-title { font-size: 14px; }
  .choice-card .ck-desc { font-size: 11px; line-height: 1.3; min-height: 0; }
  .choice-card > div { display: flex; flex-direction: column; gap: 4px; flex: 1; align-items: flex-start; text-align: left; }
  .choice-card .ck-tag { align-self: flex-start; }

  #endcard h2 { font-size: 40px; letter-spacing: 3px; }
  #endcard-stats { gap: 14px; }
  #endcard-stats .es-val { font-size: 22px; }
  #endcard-stats .es-cell { min-width: 60px; }

  #lang-switcher { padding: 3px; }
  .lang-btn { padding: 3px 7px; min-width: 30px; font-size: 10px; }

  .records-head h2 { font-size: 24px; letter-spacing: 3px; }
  .records-table { font-size: 11px; }
  .records-table th, .records-table td { padding: 6px 6px; }
  .records-table .r-wpn { width: 18px; height: 18px; }
  .rec-tab { padding: 6px 12px; font-size: 11px; }
  .title-actions { flex-direction: column; gap: 8px; }
  .cta.secondary { width: 100%; padding: 12px 18px; }
}

/* ============== Touch device → show joystick visual ============== */
@media (pointer: coarse), (hover: none) {
  #touch { display: block; }
}
