@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;500;600;700&display=swap');

:root {
  --bg-dark: #12101a;
  --panel-bg: rgba(28, 22, 35, 0.94);
  --panel-border: rgba(140, 60, 60, 0.4);
  --accent-gold: #d4a840;
  --accent-gold-glow: rgba(212, 168, 64, 0.3);
  --accent-red: #9a2222;
  --accent-red-glow: rgba(154, 34, 34, 0.4);
  --accent-blue: #5a82b8;
  --accent-blue-glow: rgba(90, 130, 184, 0.45); /* votes: a teammate's suggested level */
  --accent-purple: #7d4a90;
  --text-primary: #e0d6c0;
  --text-muted: #a09480;
  --font-serif: 'Cinzel', serif;
  --font-sans: 'MedievalSharp', cursive;

  /* Pixel-medieval palette additions (DESIGN.md). Text-safe = >= 4.5:1 on --bg-dark and --panel-bg. */
  --bg-deep: #0d0812;           /* modal card bottom, deepest fill */
  --panel-top: #1a1020;         /* modal card top */
  --accent-gold-bright: #f2c14e;/* attention: tutorial rings, countdown, timers (text-safe) */
  --danger: #e0574a;            /* HP loss, warnings, error text (text-safe); --accent-red is borders only */
  --success: #6ebf6a;           /* success toasts, heals, ready (text-safe) */
  --accent-blue-light: #7fa6d8; /* blue text (text-safe); --accent-blue is fills/borders */
  --accent-purple-light: #b07ac8; /* purple text (text-safe); --accent-purple is fills/borders */
  --text-secondary: #c9bda3;    /* descriptions, secondary body text (text-safe) */
  --text-disabled: #4f4658;     /* locked / unavailable labels: dim on purpose */
  --border-subtle: #3b3245;     /* quiet dividers, slot outlines, bar tracks */
  --disabled-bg: #4a4252;       /* disabled / sold-out button fill */
  --bar-hp: #bf2a24;            /* HUD HP fill: must read instantly in combat */
  --bar-mana: #2b6dbd;          /* HUD mana/energy fill */
  --brand-discord: #5865f2;     /* "Continue with Discord" button fill (Discord's brand colour) */
  --brand-discord-text: #ffffff;/* text on the Discord button (4.6:1 on --brand-discord) */
  --font-ui: 'Chakra Petch', sans-serif; /* all DOM UI text */
  --font-display: 'Creepster', 'Cinzel', serif; /* canvas boss titles only */

  /* Spacing: 4px scale (2px allowed for pixel borders/insets) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 2px;  /* pixel corners: buttons, slots */
  --radius-md: 4px;  /* panels, cards */

  /* Page layers, bottom to top. Every page-level z-index uses one of these
     (see DESIGN.md "Layers"). Plain 1-5 is only for stacking inside one component. */
  --z-world: 1;          /* game canvas */
  --z-hud: 10;           /* HUD, chat, corner buttons */
  --z-hud-raised: 20;    /* stats overlay, tutorial hint bar */
  --z-touch: 50;         /* mobile controls, revive prompt */
  --z-touch-raised: 60;  /* fullscreen button over the touch controls */
  --z-banner: 90;        /* boss banner */
  --z-panel: 100;        /* modals, floating panels, big announcements */
  --z-callout: 1000;     /* tutorial rings/labels, room countdown: point at panels */
  --z-modal-stacked: 1100; /* modals opened on top of another modal */
  --z-alert: 1200;       /* toasts, iOS fullscreen prompt */
  --z-tour: 1300;        /* guided tour card + arrow */
  --z-popup: 1400;       /* small info popups opened from inside a modal */
  --z-death: 1500;       /* respawn / permadeath overlays */
  --z-system: 1600;      /* quit confirm: always on top */
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}

input,
textarea {
  user-select: text;
  -webkit-user-select: text;
}

.hidden:not(.modal-backdrop) {
  display: none !important;
}

body,
html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: var(--font-sans);
  color: var(--text-primary);
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: var(--z-world);
  touch-action: none; /* pinch zooms the camera (pinchZoom.js), not the page */
}

/* ==================== TOP HUD ==================== */
#hud {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: var(--z-hud);
  pointer-events: none;
}

#hud>* {
  pointer-events: auto;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 10px 16px;
  border-radius: 4px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7), inset 0 0 30px rgba(90, 20, 20, 0.08);
}

.hero-avatar {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--panel-top), var(--bg-deep));
  border: 2px solid var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 0 10px var(--accent-gold-glow);
}

.hero-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hero-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

#hud-hero-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

.badge-berserker {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(180, 40, 40, 0.3);
  color: var(--danger);
  border: 1px solid rgba(180, 40, 40, 0.5);
}

.badge-test {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(192, 38, 211, 0.3);
  color: var(--accent-purple-light);
  border: 1px solid rgba(192, 38, 211, 0.5);
}

.badge-ranger {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(40, 120, 50, 0.3);
  color: var(--success);
  border: 1px solid rgba(40, 120, 50, 0.5);
}

.badge-sorcerer {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(100, 50, 140, 0.3);
  color: var(--accent-purple-light);
  border: 1px solid rgba(100, 50, 140, 0.5);
}

.badge-chef {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(180, 120, 30, 0.3);
  color: var(--accent-gold);
  border: 1px solid rgba(180, 120, 30, 0.5);
}

.vitals-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vital-bar-wrapper {
  position: relative;
  width: 170px;
  height: 12px;
  background: rgba(10, 5, 5, 0.7);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(100, 40, 40, 0.3);
}

.vital-bar {
  height: 100%;
  transition: width 0.15s ease-out;
}

.hp-bar {
  width: 100%;
  background: linear-gradient(90deg, #8b1a1a, #c0392b);
  box-shadow: 0 0 6px rgba(192, 57, 43, 0.5);
}

.energy-bar {
  width: 100%;
  background: linear-gradient(90deg, #2e5a88, #4a8ec9);
  box-shadow: 0 0 6px rgba(74, 142, 201, 0.4);
}

.vital-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 1);
}

/* Pixel-art icons (see js/ui/icons.js): keep them crisp when scaled. */
.px-icon {
  image-rendering: pixelated;
  vertical-align: middle;
  display: inline-block;
}

/* Radial cooldown overlay for round HUD icons. The dark wedge's angle is set
   from JS via --cd-remaining (0..1) and shrinks clockwise as it recharges. */
.cooldown-sweep {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  z-index: 3;
  pointer-events: none;
  background: conic-gradient(rgba(0, 0, 0, 0.72) calc(var(--cd-remaining, 0) * 360deg), transparent 0);
}

.cooldown-text {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-primary);
  pointer-events: none;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}

.hud-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 2;
}

#hud > .hud-center {
  pointer-events: none;
}

#hud > .hud-center > * {
  pointer-events: auto;
}

.status-pill {
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 8px 18px;
  border-radius: 3px;
  border: 1px solid var(--panel-border);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.class-picker {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  background: rgba(15, 10, 20, 0.88);
  padding: 3px;
  border-radius: 3px;
  border: 1px solid var(--panel-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

.class-picker.open {
  min-width: 128px;
  background: rgba(15, 10, 20, 0.96);
  border-color: var(--accent-gold);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.8);
}

.btn-class-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}

.class-picker:not(.open) .btn-class-switch:not(.active) {
  display: none;
}

.btn-class-switch:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.btn-class-switch.active {
  order: -1;
  background: var(--accent-red);
  color: var(--text-primary);
  font-weight: 700;
  box-shadow: 0 0 8px var(--accent-red-glow);
}

.btn-class-switch.active::after {
  content: '\25BE';
  margin-left: auto;
  padding-left: 4px;
  font-size: 10px;
  line-height: 1;
  opacity: 0.9;
}

.class-picker.open .btn-class-switch.active::after {
  content: '\25B4';
}

/* Right HUD Currencies */
.hud-right {
  display: flex;
  gap: 10px;
}

.currency-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 3px;
  border: 1px solid var(--panel-border);
  font-weight: 700;
  font-size: 14px;
}

.gold-pill {
  color: var(--accent-gold);
  border-color: rgba(201, 168, 76, 0.3);
}

.gem-pill {
  color: var(--accent-purple-light);
  border-color: rgba(160, 108, 213, 0.3);
}

/* Controls Toggle (Bottom) */
#controls-toggle-wrapper {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: var(--z-hud);
}

#btn-toggle-controls {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--accent-gold);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 18px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

#btn-toggle-controls:hover {
  background: rgba(40, 30, 50, 0.95);
}

#controls-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  padding: 10px 18px;
  border-radius: 4px;
  border: 1px solid var(--panel-border);
  font-size: 12px;
  color: var(--text-muted);
  animation: modalPop 0.2s ease;
}

#controls-list.hidden {
  display: none;
}

#controls-list span {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#controls-list kbd {
  background: rgba(154, 34, 34, 0.2);
  color: var(--text-primary);
  padding: 2px 7px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
  border: 1px solid rgba(154, 34, 34, 0.3);
}

/* Chat Container */
#chat-container {
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: var(--z-hud);
}

#chat-messages {
  height: 110px;
  overflow-y: auto;
  background: rgba(12, 8, 16, 0.8);
  backdrop-filter: blur(6px);
  border-radius: 3px;
  border: 1px solid rgba(100, 40, 40, 0.2);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.chat-message .sender {
  font-weight: 700;
  color: var(--accent-gold);
}

.chat-message .text {
  color: var(--text-secondary);
}

.chat-input-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.chat-input-row #chat-input {
  flex: 1;
  min-width: 0;
}

#chat-input {
  background: rgba(12, 8, 16, 0.9);
  border: 1px solid rgba(120, 40, 50, 0.3);
  border-radius: 3px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}

#chat-input:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red-glow);
}

/* ==================== MODALS ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 2, 8, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-panel);
  transition: opacity 0.25s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: linear-gradient(160deg, var(--panel-top), var(--bg-deep));
  border: 2px solid var(--accent-red);
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.95), 0 0 20px var(--accent-red-glow);
  padding: 28px;
  width: 440px;
  max-width: 90%;
  animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% {
    transform: scale(0.92);
    opacity: 0;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(120, 40, 50, 0.3);
  padding-bottom: 12px;
}

.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--accent-gold);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  transition: color 0.15s;
}

.btn-close:hover {
  color: var(--danger);
}

/* Login Card */
.login-card {
  text-align: center;
  width: 420px;
}

/* Sign-up password rules, under the password box */
.password-hint {
  margin: -6px 0 12px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  text-wrap: pretty;
}

/* Main menu: sign out here / everywhere. Wraps onto two lines on narrow phones; 44px tall for thumbs. */
.sign-out-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.sign-out-btn {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--danger);
  border-color: var(--danger);
}

.logo-title {
  font-family: 'Cinzel', serif;
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0px var(--accent-red), 4px 4px 8px rgba(0,0,0,0.8);
  margin-bottom: 4px;
}

.logo-subtitle {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.logo-desc {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-secondary);
  max-width: 340px;
  margin: 0 auto var(--space-4);
  text-wrap: pretty;
}

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  text-align: left;
  color: var(--text-muted);
}

.text-input {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid rgba(120, 40, 50, 0.3);
  border-radius: 2px;
  padding: 12px 16px;
  font-size: 15px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  outline: none;
  margin-bottom: 18px;
}

.text-input:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 10px var(--accent-red-glow);
}

.btn-primary-glow {
  width: 100%;
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e);
  color: var(--text-primary);
  border: 1px solid var(--accent-gold);
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 700;
  padding: 14px;
  border-radius: 2px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(107, 26, 26, 0.6);
}

.btn-primary-glow:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #8b2a2a, #4d1414);
  box-shadow: 0 6px 18px rgba(139, 42, 42, 0.8);
}

.btn-fantasy-primary {
  background: linear-gradient(135deg, #7f1d1d, #450a0a);
  color: #fef08a;
  border: 1px solid #b45309;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6), inset 0 0 8px rgba(253, 230, 138, 0.2);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.btn-fantasy-primary:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #991b1b, #7f1d1d);
  box-shadow: 0 6px 16px rgba(127, 29, 29, 0.6), inset 0 0 12px rgba(253, 230, 138, 0.4);
  border-color: var(--accent-gold);
}

/* Dark Medieval Lobby Buttons */
.btn-party-start {
  display: none;
  width: 100%;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  padding: 15px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #1b5332 0%, #0d2c1b 100%) !important;
  color: #e2f8e9 !important;
  border: 2px solid var(--success) !important;
  border-radius: 0 !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(114, 219, 155, 0.25) !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.1s, background 0.2s !important;
}

.btn-party-start:hover:not(:disabled) {
  background: linear-gradient(180deg, #246a42 0%, #123923 100%) !important;
  border-color: var(--success) !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(114, 219, 155, 0.4) !important;
}

.btn-party-start:active:not(:disabled) {
  transform: translate(2px, 2px) !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}

.btn-party-ready {
  width: 100%;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  padding: 15px;
  background: linear-gradient(180deg, #8a651e 0%, #4e360b 100%) !important;
  color: #fef9c3 !important;
  border: 2px solid var(--accent-gold) !important;
  border-radius: 0 !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(254, 240, 138, 0.25) !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.1s, background 0.2s !important;
}

.btn-party-ready:hover {
  background: linear-gradient(180deg, #a07624 0%, #5d410f 100%) !important;
  border-color: var(--accent-gold) !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(254, 240, 138, 0.4) !important;
}

.btn-party-ready:active {
  transform: translate(2px, 2px) !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}

.btn-party-unready {
  width: 100%;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 700;
  padding: 15px;
  background: linear-gradient(180deg, #634015 0%, #362109 100%) !important;
  color: #e5cf9c !important;
  border: 2px solid #82591e !important;
  border-radius: 0 !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(245, 158, 11, 0.15) !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
  cursor: pointer;
  letter-spacing: 1px;
  transition: transform 0.1s, background 0.2s !important;
}

.btn-party-unready:hover {
  background: linear-gradient(180deg, #744b19 0%, #42290c 100%) !important;
  border-color: #9e6d24 !important;
}

.btn-party-unready:active {
  transform: translate(2px, 2px) !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}


.btn-fantasy-secondary {
  background: linear-gradient(135deg, #1e1b4b, #0f172a);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

.btn-fantasy-secondary:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #312e81, #1e293b);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.login-features {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Blacksmith Forge */
.weapon-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(10, 5, 12, 0.5);
  padding: 14px;
  border-radius: 4px;
  border: 1px solid rgba(120, 40, 50, 0.15);
  margin-bottom: 16px;
}

.weapon-icon-box {
  width: 54px;
  height: 54px;
  background: linear-gradient(135deg, var(--panel-top), var(--bg-deep));
  border: 2px solid var(--accent-gold);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.weapon-details h3 {
  font-family: var(--font-serif);
  font-size: 17px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.upgrade-tag {
  background: var(--accent-gold);
  color: #0d0812;
  font-weight: 900;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 2px;
}

.damage-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.forge-stats-box {
  background: rgba(10, 5, 12, 0.5);
  border-radius: 4px;
  padding: 12px 16px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.highlight-stat {
  color: var(--accent-blue-light);
}

.success-rate {
  color: var(--success);
}

.cost-text {
  color: var(--accent-gold);
}

.btn-forge-hammer {
  width: 100%;
  background: linear-gradient(135deg, #3a2a1a, #251a0e);
  border: 1px solid var(--accent-gold);
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 15px;
  padding: 14px;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
  transition: all 0.2s ease;
}

.btn-forge-hammer:hover:not(:disabled) {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #4a3a2a, #352a1e);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.9);
}

.btn-forge-hammer:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Dungeon Portal Modal */
.portal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.portal-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.party-code-join {
  display: flex;
  gap: 8px;
}

.code-input {
  margin-bottom: 0;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1px;
}

.btn-secondary {
  background: var(--panel-top);
  border: 1px solid rgba(120, 40, 50, 0.3);
  color: var(--text-primary);
  font-weight: 700;
  padding: 0 20px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #2a1a30;
}

.open-parties-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.open-parties-list {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Campaign Map Nodes */
.campaign-node {
  position: absolute;
  width: 36px;
  height: 36px;
  background: var(--panel-top);
  border: 3px solid var(--bg-deep);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-family: var(--font-serif);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
}

.campaign-node.locked {
  background: var(--bg-deep);
  border-color: var(--bg-deep);
  color: var(--text-disabled);
  cursor: not-allowed;
}

.campaign-node.unlocked {
  background: var(--accent-red);
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.campaign-node.unlocked:hover {
  transform: translate(-50%, -50%) scale(1.2);
  box-shadow: 0 0 15px var(--accent-red-glow);
}

.campaign-node.boss-node {
  width: 48px;
  height: 48px;
  background: #3d0e0e;
  border-color: var(--accent-gold);
  color: var(--text-primary);
}

.campaign-node.boss-node.unlocked:hover {
  box-shadow: 0 0 20px rgba(180, 40, 40, 0.6);
}

.campaign-node.boss-node.locked {
  background: #1a0a0c;
  border-color: #3a2a18;
  color: #5a4a3a;
}

/* Skull badge on levels that end with a boss */
.campaign-node .boss-badge {
  position: absolute;
  top: -12px;
  right: -12px;
  font-size: 18px;
  filter: drop-shadow(0 1px 2px #000);
  pointer-events: none;
}

.campaign-node.locked .boss-badge {
  opacity: 0.45;
}

.party-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 5, 12, 0.4);
  padding: 8px 12px;
  border-radius: 3px;
  border: 1px solid rgba(120, 40, 50, 0.15);
}

.party-code {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-gold);
}

.party-status {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

.btn-join-quick {
  background: var(--accent-purple);
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 3px;
  cursor: pointer;
}

.no-parties {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 12px;
}

/* Victory Screen */
.victory-card {
  text-align: center;
  width: 480px;
  border-color: rgba(201, 168, 76, 0.5);
}

.victory-title {
  font-family: var(--font-serif);
  font-size: 28px;
  color: var(--accent-gold);
  text-shadow: 0 0 12px rgba(201, 168, 76, 0.4);
}

.victory-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  margin-bottom: 20px;
}

.victory-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.vic-stat-box {
  background: rgba(10, 5, 12, 0.5);
  padding: 14px;
  border-radius: 4px;
  border: 1px solid rgba(120, 40, 50, 0.15);
}

.vic-stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.vic-stat-val {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.vic-stat-val.gold {
  color: var(--accent-gold);
}

.vic-stat-val.xp {
  color: var(--accent-blue-light);
}

/* Quest Failed */
.quest-failed-card {
  border-color: rgba(154, 34, 34, 0.7);
}

.quest-failed-title {
  color: var(--danger);
  text-shadow: 0 0 12px rgba(224, 82, 82, 0.45);
}

/* Game mode vote: shown on entering a room, before anything spawns. */
.mode-vote-backdrop {
  background: rgba(4, 2, 8, 0.7);
}

.mode-vote-card {
  width: 820px;
  max-width: calc(100vw - 32px);
  text-align: center;
  border-color: rgba(196, 60, 60, 0.6);
}

.mode-vote-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}

.mode-vote-title {
  font-family: var(--font-serif);
  font-size: 28px;
  color: var(--accent-gold);
  margin: 0;
}

/* Countdown ring: the gold arc empties as time runs out */
.mode-vote-ring {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.mode-vote-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.mode-vote-ring circle {
  fill: none;
  stroke-width: 3;
}

.mode-vote-ring-track {
  stroke: rgba(255, 255, 255, 0.1);
}

.mode-vote-ring-fill {
  stroke: var(--accent-gold);
  stroke-linecap: round;
  transition: stroke 0.3s;
}

.mode-vote-ring-fill.urgent {
  stroke: var(--danger);
}

#mode-vote-timer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.mode-vote-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

/* Border colour = difficulty */
.mode-option {
  --diff: var(--accent-blue);
  background: rgba(10, 5, 12, 0.6);
  border: 2px solid color-mix(in srgb, var(--diff) 45%, transparent);
  border-radius: 8px;
  padding: 18px 14px 14px;
  cursor: pointer;
  color: var(--text-primary);
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.mode-option.hard { --diff: var(--accent-gold); }
.mode-option.very_hard { --diff: var(--danger); }

.mode-option:hover {
  border-color: var(--diff);
  transform: translateY(-3px);
}

.mode-option.voted {
  border-color: var(--accent-gold);
  box-shadow: 0 0 18px var(--accent-gold-glow);
  transform: translateY(-3px);
}

.mode-option-art {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 46px;
  line-height: 1;
  background: radial-gradient(circle, color-mix(in srgb, var(--diff) 30%, transparent), transparent 70%);
}

.mode-option-art img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
}

.mode-option-name {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.mode-option-skulls {
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--text-primary);
}

.mode-option-goal {
  font-size: 15px;
  color: var(--text-secondary);
}

.mode-option-bonus {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-gold-bright);
  background: rgba(201, 168, 76, 0.14);
  border-radius: 999px;
  padding: 4px 12px;
}

.mode-option-voters {
  display: flex;
  justify-content: center;
  gap: 4px;
  min-height: 24px;
  margin-top: auto;
}

.mode-voter {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--border-subtle);
  color: var(--text-primary);
}

.mode-voter.me {
  background: var(--accent-gold);
  color: #1a120a;
}

.mode-vote-status {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--text-muted);
}

/* Phone width: one card per row, picture on the left */
@media (max-width: 760px) {
  .mode-vote-options {
    grid-template-columns: 1fr;
  }

  .mode-option {
    display: grid;
    grid-template-columns: 64px 1fr;
    column-gap: 12px;
    row-gap: 4px;
    align-items: center;
    text-align: left;
    padding: 12px;
  }

  .mode-option-art {
    grid-row: span 5;
    width: 64px;
    height: 64px;
    font-size: 36px;
  }

  .mode-option-art img {
    width: 48px;
    height: 48px;
  }

  .mode-option-bonus {
    justify-self: start;
  }

  .mode-option-voters {
    justify-content: flex-start;
    min-height: 0;
  }
}

/* Landscape phones (short screens): keep three cards side by side, but
   compact, so the whole vote fits without scrolling. */
@media (max-height: 500px) and (orientation: landscape) {
  .mode-vote-card {
    padding: 10px 12px;
  }

  .mode-vote-header {
    margin-bottom: 8px;
  }

  .mode-vote-title {
    font-size: 20px;
  }

  .mode-vote-ring {
    width: 30px;
    height: 30px;
  }

  #mode-vote-timer {
    font-size: 12px;
  }

  .mode-vote-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .mode-option {
    display: flex;
    text-align: center;
    padding: 8px 8px 6px;
    gap: 3px;
  }

  .mode-option-art {
    grid-row: auto;
    width: 48px;
    height: 48px;
  }

  .mode-option-art img {
    width: 40px;
    height: 40px;
  }

  .mode-option-name {
    font-size: 13px;
  }

  .mode-option-skulls img {
    width: 14px;
    height: 14px;
  }

  .mode-option-goal {
    font-size: 12px;
  }

  .mode-option-bonus {
    font-size: 11px;
    padding: 2px 8px;
    justify-self: auto;
  }

  .mode-option-voters {
    justify-content: center;
    min-height: 20px;
  }

  .mode-voter {
    width: 20px;
    height: 20px;
    font-size: 11px;
  }

  .mode-vote-status {
    margin-top: 6px;
    font-size: 12px;
  }
}

/* Main Menu / Roster */
.menu-card {
  width: 580px;
}

.menu-account-stats {
  display: flex;
  gap: 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.menu-stat {
  background: rgba(10, 5, 12, 0.5);
  padding: 4px 10px;
  border-radius: 3px;
  border: 1px solid rgba(120, 40, 50, 0.2);
}

.roster-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.roster-card {
  background: rgba(10, 5, 12, 0.5);
  border: 1px solid rgba(120, 40, 50, 0.2);
  border-radius: 4px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.roster-card:hover {
  background: rgba(80, 20, 20, 0.15);
  transform: translateY(-2px);
}

.roster-card.active {
  border-color: var(--accent-red);
  background: rgba(139, 26, 26, 0.15);
  box-shadow: 0 0 16px rgba(139, 26, 26, 0.2);
}

.roster-avatar {
  font-size: 32px;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--panel-top), var(--bg-deep));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(120, 40, 50, 0.2);
}

.roster-card.active .roster-avatar {
  border-color: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red-glow);
}

.roster-info {
  flex: 1;
  text-align: left;
}

.roster-name {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--text-primary);
  font-size: 16px;
  margin-bottom: 2px;
}

.roster-level {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.roster-level strong {
  color: var(--accent-gold);
}

.roster-xp-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid rgba(120, 40, 50, 0.15);
}

.roster-xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2e5a88, #4a8ec9);
}

/* ==================== MOBILE CONTROLS ==================== */
#mobile-controls-overlay {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-touch);
}

body.is-mobile #mobile-controls-overlay {
  display: block !important;
}

body.is-mobile #controls-toggle-wrapper {
  display: none !important;
}

#virtual-joystick-base {
  position: absolute;
  /* Kept well clear of the corner so the thumb can push left/down freely */
  bottom: max(32px, calc(env(safe-area-inset-bottom) + 20px));
  left: max(64px, calc(env(safe-area-inset-left) + 40px));
  width: 124px;
  height: 124px;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

#virtual-joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 50px;
  margin-top: -25px;
  margin-left: -25px;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  pointer-events: none;
}

/* Action buttons (MLBB style): a big attack button set in from the corner,
   skills on an arc of radius 100px around its centre (left, up-left, up) so
   the thumb pivots from attack to any skill; interact sits on an outer ring.
   Offsets are from the group's bottom-right corner; attack centre = (40, 40). */
.mobile-action-group {
  position: absolute;
  right: max(48px, calc(env(safe-area-inset-right) + 24px));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  width: 220px;
  height: 170px;
  pointer-events: none;
}

.mobile-action-btn {
  position: absolute;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.08s, background 0.08s;
}

.mobile-action-btn:active {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(0.9);
}

.mobile-action-btn .cooldown-text {
  font-size: 15px;
}

.attack-btn {
  right: 0;
  bottom: 0;
  width: 80px;
  height: 80px;
  border-color: rgba(239, 68, 68, 0.75);
}

/* 180°: left of attack */
.dash-btn {
  right: 111px;
  bottom: 11px;
  border-color: rgba(96, 165, 250, 0.75);
}

/* 135°: up-left */
.special-btn {
  right: 82px;
  bottom: 82px;
  border-color: rgba(192, 132, 252, 0.75);
}

/* 90°: straight up */
.charge-btn {
  right: 11px;
  bottom: 111px;
  border-color: rgba(245, 158, 11, 0.75);
}

/* Outer ring (radius 165px) at 160°, low-left like MLBB's battle spell */
.interact-btn {
  right: 172px;
  bottom: 73px;
  width: 46px;
  height: 46px;
}

/* ==================== CUSTOM SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--panel-border, rgba(140, 60, 60, 0.6));
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-red, rgba(160, 80, 80, 0.8));
}


/* ==================== MOBILE LAYOUT (Phones / MLBB Style) ==================== */
body.is-mobile #chat-container {
  display: none !important;
}

@media (max-width: 950px) {

  /* Hide desktop chat box & bottom-right hints on phones/narrow screens */
  #chat-container,
  #hud-bottom-right {
    display: none !important;
  }

  .hud-center {
    transform: translateX(-50%);
  }

  .status-pill {
    padding: 4px 10px;
    font-size: 10px;
  }

  .class-picker {
    padding: 2px;
  }

  .btn-class-switch {
    padding: 4px 8px;
    font-size: 11px;
  }

  .class-picker.open .btn-class-switch {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 12px;
  }

  #hud-tutorial-overlay {
    bottom: auto !important;
    top: 40px !important;
    transform: translateX(-50%) scale(0.75);
    background: rgba(0, 0, 0, 0.6);
  }

  .modal-card {
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.85);
  }
}

/* Fix for browser autofill overriding the dark background on login inputs */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 30px var(--bg-deep) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
}

/* Hero Profile Panel */
.profile-card {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.profile-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: bold;
  font-size: 14px;
  padding: 8px 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.profile-tab:hover {
  color: var(--text-muted);
}

.profile-tab.active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}

/* ---- Simple stat cards (Hero Profile) ---- */
.stat-card-ui {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--stat-color);
  border-radius: 6px;
  padding: 8px 12px 10px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.stat-card-ui:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(2px);
}

.stat-card-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-icon-ui {
  font-size: 22px;
  width: 30px;
  text-align: center;
  flex-shrink: 0;
}

.stat-text-ui {
  flex: 1;
  min-width: 0;
}

.stat-title-ui {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: bold;
}

.stat-big-val {
  color: var(--stat-color);
  font-size: 20px;
  font-weight: bold;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.8);
}

.stat-simple-bar {
  margin-top: 6px;
  height: 6px;
  background: var(--border-subtle);
  border-radius: 3px;
  overflow: hidden;
}

.stat-simple-fill {
  height: 100%;
  background: var(--stat-color);
  border-radius: 3px;
  box-shadow: 0 0 6px var(--stat-color);
  transition: width 0.6s ease-out;
}

.stat-sources-ui {
  display: none;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--border-subtle);
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-card-ui.open .stat-sources-ui {
  display: block;
}

.stat-sources-title {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-source-ui {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.stat-source-val {
  color: var(--text-primary);
  font-weight: bold;
}

.stat-subblock {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
}

.stat-subrow {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  padding-left: 22px;
  margin-top: 1px;
}

.ability-card-ui {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 10px;
  display: flex;
  gap: 12px;
}

.ability-icon-wrap {
  width: 48px;
  height: 48px;
  background: var(--panel-top);
  border: 2px solid var(--text-muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.ability-key-badge {
  margin-top: 4px;
  background: var(--border-subtle);
  color: var(--text-primary);
  font-size: 10px;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--text-muted);
  text-align: center;
}

.ability-details-ui h4 {
  margin: 0 0 4px 0;
  color: var(--text-primary);
  font-size: 15px;
}

.ability-details-ui p {
  margin: 0 0 6px 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
}

.ability-tags-ui {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.ability-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--panel-top);
  color: var(--accent-blue-light);
  border: 1px solid var(--accent-blue);
  font-weight: bold;
}

/* ==================== 8-BIT PIXEL UI OVERRIDES ==================== */

/* 1. Typography - Clean Game HUD Font (Chakra Petch) */
body,
button,
input,
div,
span,
h1,
h2,
h3,
h4,
p {
  font-family: 'Chakra Petch', sans-serif !important;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.8) !important;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings & Titles */
h1,
h2,
.modal-title {
  font-weight: 700 !important;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.9) !important;
  letter-spacing: 0.04em;
}

#hud-class-badge,
#profile-class-level {
  font-family: 'Chakra Petch', sans-serif !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: 0.04em !important;
  text-shadow: 1px 1px 0px #000 !important;
}

/* Give the XP bar sufficient room */
.exp-wrapper {
  height: 14px !important;
}

/* 2. Modals & Panels */
.modal-card,
.tooltip,
.hud-left,
.chat-container {
  border-radius: 0 !important;
  border-width: 2px !important;
  border-style: solid !important;
  box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.7) !important;
}

/* 3. Buttons */
.btn-primary,
.btn-primary-glow,
.btn-secondary,
.btn-danger,
.btn-forge-hammer {
  border-radius: 0 !important;
  border-width: 2px !important;
  border-style: solid !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8) !important;
  transition: transform 0.1s !important;
  transform: none !important;
}

.btn-primary:active,
.btn-primary-glow:active,
.btn-secondary:active,
.btn-danger:active,
.btn-forge-hammer:active {
  transform: translate(2px, 2px) !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}

.btn-primary-glow:hover {
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.8) !important;
}

button.btn-close {
  border: none !important;
  box-shadow: none !important;
  text-shadow: none !important;
}

/* 4. Stat & Ability Cards */
.stat-card-ui,
.ability-card-ui,
.forge-item {
  border-radius: 0 !important;
  border-width: 2px !important;
  border-style: solid !important;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.7) !important;
  transition: transform 0.1s !important;
}

.stat-card-ui:hover {
  transform: translateX(4px) !important;
  box-shadow: 0px 4px 0px rgba(0, 0, 0, 0.7) !important;
}

.hero-select-hitbox {
  cursor: pointer;
  padding: 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  transition: background 0.15s ease-out;
}

.hero-select-hitbox:hover {
  background: rgba(255, 255, 255, 0.05);
}

.hero-select-hitbox:hover #profile-portrait {
  transform: translateY(-4px) scale(1.05) !important;
  filter: drop-shadow(0 6px 12px rgba(245, 158, 11, 0.6)) !important;
}

#profile-portrait {
  transition: transform 0.15s ease-out, filter 0.15s ease-out !important;
}

/* 5. Avatars & Ability Icons */
.ability-icon-wrap,
.hero-avatar {
  border-radius: 0 !important;
  border-width: 2px !important;
  border-style: solid !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}

/* Stat Progress Bars - Larger, clear, and smooth-edged */
.stat-simple-bar {
  margin-top: 8px !important;
  height: 12px !important;
  background: rgba(10, 8, 15, 0.95) !important;
  border-radius: 4px !important;
  border: 1.5px solid #000 !important;
  box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5) !important;
  overflow: hidden !important;
  position: relative !important;
}

.stat-simple-fill {
  height: 100% !important;
  background: var(--stat-color) !important;
  border-radius: 2px !important;
  box-shadow: none !important;
  transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
}

#profile-stats-legend {
  display: none !important;
}

/* 6. Vital Bars - Smooth-edged Flat 2D Rectangles (No 3D / No reflection) */
.vital-bar-wrapper,
.profile-xp-wrapper {
  position: relative !important;
  height: 18px !important;
  border-radius: 4px !important;
  background: rgba(14, 11, 20, 0.9) !important;
  border: 1.5px solid #000 !important;
  box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.6) !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

/* Remove any pseudo-element reflections or highlights */
.vital-bar-wrapper::before,
.profile-xp-wrapper::before,
.vital-bar::before,
.vital-bar::after {
  content: none !important;
  display: none !important;
}

/* Fills - Smooth-edged flat bars */
.vital-bar {
  height: 100% !important;
  border-radius: 3px !important;
  position: relative !important;
  box-shadow: none !important;
  transition: width 0.15s ease-out;
}

#profile-xp-bar {
  height: 100% !important;
  border-radius: 3px !important;
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  box-shadow: none !important;
  transition: width 0.15s ease-out;
}

/* HP: Flat 2D Red */
.hp-bar {
  background: var(--bar-hp) !important;
  box-shadow: none !important;
}

/* Energy/Mana: Flat 2D Blue */
.energy-bar {
  background: var(--bar-mana) !important;
  box-shadow: none !important;
}

/* XP Bar: Smooth-edged flat bar */
.exp-wrapper {
  height: 12px !important;
  border-radius: 3px !important;
  margin-top: 4px !important;
}

.exp-bar,
#profile-xp-bar {
  background: var(--accent-blue) !important;
  box-shadow: none !important;
}

/* Numbers inside the bars: Clear, centered, readable in light grey */
.vital-text,
#profile-xp-text {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  font-family: 'Chakra Petch', sans-serif !important;
  font-size: 11px !important;
  font-weight: 700 !important;
  letter-spacing: 0.04em !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  color: var(--text-secondary) !important;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000 !important;
  z-index: 5 !important;
  pointer-events: none !important;
}

/* 7. Labels & Badges */
.ability-key-badge,
.badge-berserker,
.badge-ranger,
.badge-sorcerer,
.badge-chef,
.badge-test {
  border-radius: 0 !important;
  border-width: 2px !important;
  border-style: solid !important;
  box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.8) !important;
}
/* Boss defeated: golden ribbon banner over the game (ui/bossBanner.js) */
.boss-banner {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  z-index: var(--z-banner);
  opacity: 0;
  visibility: hidden;
}

.boss-banner.show {
  visibility: visible;
  animation: bossBannerLife 4.2s ease-out forwards;
}

.boss-banner::before {
  content: '';
  position: absolute;
  inset: -40px -80px;
  background: radial-gradient(ellipse at center, rgba(255, 200, 80, 0.35), transparent 65%);
  z-index: -1;
}

.boss-banner-emblem {
  width: 54px;
  height: 54px;
  margin-bottom: -18px;
  border-radius: 50%;
  border: 3px solid var(--accent-gold-bright);
  background: radial-gradient(circle at 40% 35%, #4a2160, #1c0d26);
  box-shadow: 0 0 18px rgba(242, 193, 78, 0.7), 0 3px 6px rgba(0, 0, 0, 0.8);
  color: #f6e2a8;
  font-size: 28px;
  line-height: 48px;
  text-align: center;
  z-index: 2;
}

.boss-banner-ribbon {
  position: relative;
  max-width: 94vw;
  padding: 22px clamp(34px, 8vw, 70px) 12px;
  text-align: center;
  background: linear-gradient(180deg, #fff2b8, var(--accent-gold-bright) 35%, #a8741a 70%, var(--accent-gold-bright));
  clip-path: polygon(0 50%, 30px 0, calc(100% - 30px) 0, 100% 50%, calc(100% - 30px) 100%, 30px 100%);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.8));
  overflow: hidden;
}

.boss-banner-ribbon::before {
  content: '';
  position: absolute;
  inset: 4px;
  background: linear-gradient(180deg, #4a2160, #1c0d26 55%, #33163f);
  clip-path: polygon(0 50%, 28px 0, calc(100% - 28px) 0, 100% 50%, calc(100% - 28px) 100%, 28px 100%);
}

/* Light sweep across the ribbon */
.boss-banner-ribbon::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  left: -80px;
  background: linear-gradient(100deg, transparent, rgba(255, 245, 210, 0.45), transparent);
  transform: skewX(-20deg);
}

.boss-banner.show .boss-banner-ribbon::after {
  animation: bossBannerShine 1.1s 0.45s ease-in-out;
}

.boss-banner-name,
.boss-banner-sub {
  position: relative;
  font-family: var(--font-serif);
  white-space: nowrap;
  text-transform: uppercase;
}

.boss-banner-name {
  font-size: clamp(16px, 4.6vw, 44px);
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--accent-gold-bright);
  text-shadow: 0 -1px 0 #fff4c4, 0 2px 0 #8a5410, 0 3px 0 #3a1a08, 0 0 14px rgba(255, 200, 80, 0.55);
}

.boss-banner-sub {
  font-size: clamp(10px, 2.4vw, 15px);
  font-weight: 700;
  letter-spacing: 6px;
  color: #f3e3b0;
}

@keyframes bossBannerLife {
  0% { opacity: 0; transform: translateX(-50%) scale(1.8); }
  8% { opacity: 1; transform: translateX(-50%) scale(0.94); }
  13% { transform: translateX(-50%) scale(1); }
  85% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-12px); }
}

@keyframes bossBannerShine {
  to { left: calc(100% + 80px); }
}

/* ==================== PHONE HUD (Soul Knight style) ====================
   Last in the file so it wins over the pixel-theme !important rules above.
   Top-left: one small dark block with avatar + thin bars. Top-right: one row
   of small chips. Everything clears the notch via safe-area insets. */
@media (max-width: 950px) {
  #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }

  .hud-left {
    gap: 6px;
    padding: 5px 7px;
    align-items: flex-start;
    background: rgba(0, 0, 0, 0.45);
    border: none !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    backdrop-filter: none;
  }

  .hero-avatar {
    width: 28px;
    height: 28px;
    border-width: 1px !important;
    box-shadow: none !important;
  }

  .hero-avatar img {
    width: 22px;
    height: 22px;
  }

  .hero-info {
    gap: 2px;
  }

  #hud-hero-name {
    display: none !important;
  }

  #hud-class-badge {
    font-size: 9px;
    padding: 0 4px;
    border-width: 1px !important;
    box-shadow: none !important;
  }

  .vitals-container {
    gap: 2px !important;
    margin-top: 2px !important;
  }

  .vital-bar-wrapper {
    width: 116px;
    height: 13px !important;
    border-width: 1px !important;
  }

  .vital-bar-wrapper.exp-wrapper {
    height: 8px !important;
    margin-top: 0 !important;
  }

  .vital-text {
    font-size: 9px !important;
  }

  .exp-wrapper .vital-text {
    font-size: 7px !important;
  }

  #hud-buff-bar {
    gap: 4px !important;
    margin-top: 3px !important;
  }

  #hud-buff-bar > div {
    width: 20px !important;
    height: 20px !important;
  }

  #hud-buff-bar img {
    width: 14px;
    height: 14px;
  }

  .hud-right {
    gap: 5px;
    align-items: center;
  }

  .currency-pill,
  #hud-dungeon-status {
    margin-top: 0 !important;
    padding: 3px 8px;
    gap: 4px;
    font-size: 12px !important;
    opacity: 1 !important;
    background: rgba(0, 0, 0, 0.45);
    border: none;
    border-radius: 4px;
    box-shadow: none;
    backdrop-filter: none;
    white-space: nowrap;
  }

  .currency-icon {
    width: 16px;
    height: 16px;
  }
}

/* ==================== LOGIN PASSWORD SHOW/HIDE ==================== */
.password-field {
  position: relative;
}

.password-field .text-input {
  display: block;
  margin: 0;
  padding-left: 44px;
  padding-right: 44px;
}

#btn-toggle-password {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--accent-gold);
  background: none;
  border: none;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-toggle-password .eye-closed,
#btn-toggle-password[aria-pressed="true"] .eye-open {
  display: none;
}

#btn-toggle-password[aria-pressed="true"] .eye-closed {
  display: block;
}

/* ==================== PHONE PORTRAIT ====================
   The chip row is wider than a portrait screen, which also makes phone browsers
   zoom out and leave black bands. Let it wrap beside the hero panel. */
@media (max-width: 950px) and (orientation: portrait), (max-width: 760px) {
  #hud {
    flex-wrap: wrap;
    column-gap: 6px;
  }

  #hud > .hud-left {
    flex: none;
  }

  #hud > .hud-right {
    flex: 1 1 0;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-self: flex-start;
  }

  .hud-center {
    position: static;
    transform: none;
    order: 3;
    flex-basis: 100%;
    margin-top: 6px;
    align-items: center;
  }
}

@media (max-width: 950px) and (orientation: portrait) {
  .hud-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    align-self: flex-start;
    min-width: 0;
  }

  /* body in the selector: the base rule comes later in this file */
  body #btn-mobile-fullscreen {
    top: calc(max(8px, env(safe-area-inset-top)) + 64px);
  }
}

/* ==================== HUD MENU BUTTON ====================
   Opens the same menu as Esc. The ::after widens the tap area on phones
   without making the chip row taller. */
#btn-hud-menu {
  position: relative;
  pointer-events: auto;
  padding: 4px 12px;
  font-size: 18px;
  line-height: 1;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.45);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
}

#btn-hud-menu::after {
  content: '';
  position: absolute;
  inset: -10px -6px;
}

/* ==================== PHONE FULLSCREEN BUTTON ====================
   Top-right under the currency chips (top-centre is the village class picker
   and the tutorial box). Shown only on phones that aren't already fullscreen
   or launched from the Home Screen (game.js sets body.app-fullscreen). */
#btn-mobile-fullscreen {
  display: none;
  position: fixed;
  top: calc(max(8px, env(safe-area-inset-top)) + 30px);
  right: max(10px, env(safe-area-inset-right));
  z-index: var(--z-touch-raised);
  padding: 7px 14px;
  font-family: var(--font-serif);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #1a1020;
  background: var(--accent-gold);
  border: 2px solid var(--accent-gold-bright);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  animation: fsPulse 1.6s ease-in-out infinite;
  touch-action: manipulation;
}

body.is-mobile:not(.app-fullscreen) #btn-mobile-fullscreen {
  display: block;
}

/* Flat text: the global pixel-UI text shadow made these look 3D. */
#btn-mobile-fullscreen,
#ios-fullscreen-modal,
#ios-fullscreen-modal * {
  text-shadow: none !important;
}

@keyframes fsPulse {
  50% { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), 0 0 14px rgba(212, 168, 64, 0.8); }
}

.ios-fs-title {
  font-family: var(--font-serif);
  color: var(--accent-gold);
  font-size: 20px;
  margin: 0 0 8px 0;
}

.ios-fs-text {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
  margin: 0 0 12px 0;
}

.ios-fs-steps {
  text-align: left;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.9;
  margin: 0 0 16px 0;
  padding-left: 22px;
}

.ios-fs-icon {
  vertical-align: -3px;
  color: var(--accent-blue-light);
}

/* Landscape phone in Safari leaves ~250px of height: keep the popup inside it */
#ios-fullscreen-modal .modal-card {
  padding: 16px 20px;
  max-height: 92dvh;
  overflow-y: auto;
}

/* ---- New-player tutorial card, mobile button highlights and village tour (js/ui/tutorialGuide.js) ---- */
#hud-tutorial-overlay {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
  width: max-content; max-width: min(560px, 92vw);
  background: rgba(0, 0, 0, 0.85); border: 2px solid var(--danger); border-radius: 8px;
  padding: 12px 22px; text-align: center; z-index: var(--z-hud-raised); color: var(--text-primary);
}
#hud-tutorial-overlay h3 { margin: 0 0 8px; color: var(--accent-gold); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
#hud-tutorial-text { font-size: 16px; font-weight: bold; line-height: 1.5; }
#hud-tutorial-overlay .tut-actions { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 10px; }
#btn-tutorial-ok { padding: 6px 22px; font-size: 14px; }
#btn-tutorial-skip { padding: 4px 14px; font-size: 12px; opacity: 0.8; }
.tut-kbd { background: rgba(255, 255, 255, 0.2); padding: 2px 7px; border-radius: 4px; margin: 0 2px; }
.tut-ring {
  position: fixed; z-index: var(--z-callout); border-radius: 50%; pointer-events: none;
  border: 3px solid var(--accent-gold-bright); box-shadow: 0 0 16px 4px rgba(250, 204, 21, 0.8);
  animation: tut-pulse 1s ease-in-out infinite;
}
.tut-arrow {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  color: var(--accent-gold-bright); font-size: 26px; line-height: 1; text-shadow: 0 0 6px #000;
  animation: tut-bob 0.8s ease-in-out infinite;
}
@keyframes tut-pulse { 50% { transform: scale(1.12); box-shadow: 0 0 24px 8px rgba(250, 204, 21, 0.9); } }
@keyframes tut-bob { 50% { transform: translateX(-50%) translateY(-8px); } }
.tour-card {
  position: fixed; z-index: var(--z-tour); left: 50%; bottom: 14%; transform: translateX(-50%);
  width: min(360px, 90vw); background: rgba(15, 15, 20, 0.95); border: 2px solid var(--accent-gold);
  border-radius: 12px; padding: 14px 18px; color: var(--text-primary); text-align: center;
}
.tour-card h3 { margin: 4px 0; color: var(--accent-gold-bright); }
.tour-card p { margin: 0 0 12px; color: var(--text-secondary); font-size: 14px; }
.tour-step { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.tour-actions { display: flex; gap: 10px; justify-content: center; }
.tour-arrow {
  position: fixed; z-index: var(--z-tour); transform: translate(-50%, -50%); pointer-events: none;
  color: var(--accent-gold-bright); font-size: 40px; text-shadow: 0 0 8px #000; animation: tour-bob 0.8s ease-in-out infinite;
}
@keyframes tour-bob { 50% { margin-top: -10px; } }

.roster-role { font-size: 11px; color: var(--text-muted); margin: 2px 0 4px; line-height: 1.3; }

/* Phones and short screens: the tour card is small and sits at the top so the village stays visible */
@media (max-width: 900px), (max-height: 520px) {
  .tour-card { bottom: auto; top: 8px; width: min(300px, 70vw); padding: 8px 12px; border-radius: 10px; }
  .tour-card h3 { margin: 2px 0; font-size: 15px; }
  .tour-card p { margin: 0 0 8px; font-size: 12px; line-height: 1.3; }
  .tour-actions button { padding: 6px 10px; font-size: 12px; }
  .tour-arrow { font-size: 30px; }
  #hud-tutorial-overlay { padding: 8px 14px; }
  #hud-tutorial-text { font-size: 13px; }
  #hud-tutorial-overlay h3 { margin-bottom: 4px; font-size: 11px; }
}

/* Rectangular highlight (the top-left health/energy/XP panel): the arrow sits underneath, pointing up */
.tut-ring.tut-box { border-radius: 12px; animation-name: tut-pulse-box; }
.tut-box .tut-arrow { bottom: auto; top: 100%; transform: translateX(-50%) rotate(180deg); animation-name: tut-bob-up; }
@keyframes tut-pulse-box { 50% { box-shadow: 0 0 24px 8px rgba(250, 204, 21, 0.9); } }
@keyframes tut-bob-up { 50% { transform: translateX(-50%) translateY(8px) rotate(180deg); } }

/* Bar tags: a small pill beside each bar with an arrow pointing back at it */
.tut-label {
  position: fixed; z-index: var(--z-callout); transform: translateY(-50%); pointer-events: none;
  background: rgba(0, 0, 0, 0.88); color: var(--text-primary); font-weight: bold; font-size: 13px; white-space: nowrap;
  padding: 4px 10px; border-radius: 8px; border: 2px solid var(--tut-label, var(--accent-gold-bright));
}
.tut-label::before {
  content: ''; position: absolute; right: 100%; top: 50%; transform: translateY(-50%);
  border: 7px solid transparent; border-right-color: var(--tut-label, var(--accent-gold-bright));
}
@media (max-width: 900px), (max-height: 520px) {
  /* Phones: the card sits at the bottom centre, between the stick and the buttons, clear of the top-left panel */
  #hud-tutorial-overlay { top: auto !important; bottom: 8px !important; transform: translateX(-50%) !important; max-width: 46vw; }
  .tut-label { font-size: 11px; padding: 3px 8px; }
}

/* Show FPS / Show ping (ui/statsOverlay.js): a small readout under the gold / gems row, where the HUD leaves room */
#stats-overlay {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  top: calc(max(16px, env(safe-area-inset-top)) + 44px);
  z-index: var(--z-hud-raised);
  display: flex;
  gap: 10px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text-primary);
  font: 600 11px/1.4 ui-monospace, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
#stats-overlay.hidden { display: none; }
#stats-overlay span:empty { display: none; }

.display-toggles { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.display-toggles-row { flex-direction: row; flex-wrap: wrap; margin: 14px 0 0; }
.display-toggles-row .display-toggle { flex: 1 1 180px; }
.display-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  text-align: left;
}
.display-toggle-label { display: block; color: var(--text-primary); font-weight: bold; font-size: 13px; }
.display-toggle-hint { display: block; color: var(--text-muted); font-size: 11px; }
.display-toggle input { width: 20px; height: 20px; flex: none; cursor: pointer; accent-color: var(--accent-gold); }
/* Phone HUD (max-width 950px): stay right-aligned below the top-right pills (statsOverlay.js tracks .hud-right exact bottom) */
@media (max-width: 950px) {
  #stats-overlay {
    right: max(10px, env(safe-area-inset-right));
    top: calc(max(8px, env(safe-area-inset-top)) + 64px);
  }
}

/* ==================== GUEST MODE ====================
   body.is-guest is set by js/ui/guestUi.js. Last in the file so the phone rules above don't override it. */
.guest-only { display: none !important; }
body.is-guest .guest-only { display: flex !important; }

/* Login card: "Play as Guest" under the main button */
.guest-play-block {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.guest-play-btn {
  width: 100%;
  min-height: 44px;
}

.guest-play-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  text-wrap: balance;
}

#guest-turnstile {
  min-height: 65px;
  display: flex;
  justify-content: center;
}

/* "Save my progress" mode: the login card sits above the main menu and loses the guest/sign-up switches */
#guest-upgrade-back { display: none; }

#login-modal.upgrading { z-index: var(--z-modal-stacked); }
#login-modal.upgrading .guest-play-block,
#login-modal.upgrading #auth-toggle-link { display: none; }

#login-modal.upgrading #guest-upgrade-back {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 12px;
  color: var(--text-muted);
  font-size: 15px;
  text-decoration: underline;
}

/* Guest banner (main menu) and pill (HUD) */
.guest-banner {
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 13px;
}

.guest-banner .guest-save-btn {
  min-height: 44px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--accent-gold);
  border-color: var(--accent-gold);
}

.guest-pill {
  align-items: center;
  gap: 8px;
  padding: 3px 4px 3px 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.guest-pill .guest-save-btn {
  position: relative;
  min-height: 26px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--accent-gold);
  border-radius: 3px;
  cursor: pointer;
  touch-action: manipulation;
}

/* Reaches a 44px tap area without making the chip row taller. It grows downward (over the game view) because the
   quick-chat button sits right above it on phones and needs that space for its own tap area. */
.guest-pill .guest-save-btn::after {
  content: '';
  position: absolute;
  inset: -1px -4px -18px;
}

.guest-short { display: none; }

/* Quick-chat: replaces the text box for guests. Desktop: a wrapped block under the chat log */
#quick-chat-bar {
  display: none;
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: 280px;
  max-height: 108px;
  overflow-y: auto;
  flex-wrap: wrap;
  gap: 6px;
  z-index: var(--z-hud);
}

body.is-guest #quick-chat-bar { display: flex; }
body.is-guest #chat-input,
body.is-guest .chat-input-row { display: none; }
body.is-guest #chat-container { bottom: 132px; }

.quick-chat-btn {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  cursor: pointer;
  touch-action: manipulation;
}

.quick-chat-btn:hover { border-color: var(--accent-gold); }

#btn-quick-chat,
#btn-mobile-chat {
  display: none;
  position: relative;
  pointer-events: auto;
  padding: 2px 10px;
  min-height: 24px;
  font-size: 16px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  align-items: center;
  justify-content: center;
}

#btn-quick-chat:hover,
#btn-mobile-chat:hover,
#btn-mobile-chat[aria-expanded="true"] {
  border-color: var(--accent-gold);
}

#btn-quick-chat::after,
#btn-mobile-chat::after {
  content: '';
  position: absolute;
  inset: -10px -6px;
}

body.is-mobile:not(.is-guest) #btn-mobile-chat { display: flex; }
body.is-guest #btn-mobile-chat { display: none !important; }
body.is-mobile.is-guest #btn-quick-chat { display: flex; }

/* Phones: the chat box is hidden by default, so chat and quick-chat open from the HUD/deck button */
@media (max-width: 950px) {
  .guest-pill .guest-long { display: none; }
  .guest-pill .guest-short { display: inline; }

  .guest-pill {
    padding: 2px 3px 2px 8px;
    gap: 6px;
    background: rgba(0, 0, 0, 0.45);
    border: none;
    margin-top: 4px; /* room for the quick-chat button's tap area above it */
  }

  body:not(.is-guest) #btn-mobile-chat { display: flex; }
  body.is-guest #btn-quick-chat { display: flex; }

  body.is-guest #quick-chat-bar { display: none; }

  body.is-guest #quick-chat-bar.open {
    display: flex;
    position: fixed;
    top: 50%;
    bottom: auto;
    left: max(16px, env(safe-area-inset-left));
    right: max(16px, env(safe-area-inset-right));
    width: auto;
    max-height: none;
    transform: translateY(-50%);
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    z-index: var(--z-touch-raised);
    -webkit-overflow-scrolling: touch;
  }

  .quick-chat-btn {
    flex: none;
    min-height: 44px;
    padding: 0 16px;
    font-size: 14px;
  }
}

/* ==================== FRIENDS PANEL ==================== */
#btn-hud-friends {
  position: relative;
  pointer-events: auto;
  padding: 2px 10px; /* + 2px border = same 40x24 box as the menu/chat buttons */
  line-height: 1;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#btn-hud-friends:hover {
  border-color: var(--accent-gold);
}

#btn-hud-friends::after {
  content: '';
  position: absolute;
  inset: -10px -8px;
}

#btn-hud-friends.has-requests {
  border-color: var(--accent-gold);
  color: var(--accent-gold-bright);
}

.friends-badge,
.friends-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger);
  background: var(--accent-red);
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-shadow: none !important;
}

#hud-friends-badge {
  position: absolute;
  top: -6px;
  right: -6px;
}

#main-menu-modal .modal-header {
  flex-wrap: wrap;
  gap: var(--space-2);
}

#main-menu-modal .menu-account-stats {
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

#btn-menu-friends {
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

#btn-menu-friends .px-icon,
.party-share-btn .px-icon {
  width: 16px;
  height: 16px;
}

.friends-panel {
  position: fixed;
  top: 64px;
  right: var(--space-4);
  bottom: var(--space-4);
  width: 340px;
  max-width: 100vw;
  z-index: var(--z-modal-stacked);
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, var(--panel-top), var(--bg-deep));
  border: 2px solid var(--accent-red);
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.95), 0 0 20px var(--accent-red-glow);
  font-family: var(--font-ui);
  color: var(--text-primary);
  overflow: hidden;
}

.friends-panel .px-icon {
  image-rendering: pixelated;
}
/* Icon-only controls (close X, row "more", decline) show the 16px art at 2x so the strokes read */
#btn-friends-close .px-icon,
.friends-more-btn .px-icon,
.friends-btn.icon-only .px-icon,
#btn-hud-copy-party .px-icon {
  width: 32px;
  height: 32px;
}

.friends-grab {
  display: none;
  width: 40px;
  height: 4px;
  border-radius: var(--radius-sm);
  background: var(--border-subtle);
  margin: var(--space-2) auto 0;
  flex: none;
}

.friends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(120, 40, 50, 0.3);
  flex: none;
}

.friends-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
}

.friends-header .btn-close {
  margin: 0 calc(var(--space-2) * -1) 0 0;
}

.friends-guest-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-4);
  padding: var(--space-5);
}

.friends-guest-msg {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  text-wrap: balance;
}

.friends-account-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.friends-tabs {
  display: flex;
  margin: 0 var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}

.friends-tab {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-1);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  transition: color 0.2s, border-color 0.2s;
}

.friends-tab:hover {
  color: var(--text-primary);
}

.friends-tab.active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}

.friends-tab-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.friends-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.friends-add-body {
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.friends-row,
.friends-req {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-3);
  background: rgba(10, 5, 12, 0.5);
  border: 1px solid rgba(120, 40, 50, 0.2);
  border-radius: var(--radius-md);
  position: relative;
  flex: none;
}

.friends-gem {
  width: 32px; /* 2x the 16px art, like the HUD icons; 1x was too small to read */
  height: 32px;
  flex: none;
  image-rendering: pixelated;
}

.friends-who {
  flex: 1;
  min-width: 0;
}

.friends-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friends-row.is-offline .friends-gem {
  opacity: 0.72;
}

.friends-row.is-offline .friends-name {
  color: var(--text-muted);
}

.friends-status {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friends-more-wrap {
  position: relative;
  flex: none;
}

.friends-more-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  touch-action: manipulation;
}

.friends-more-btn:hover,
.friends-more-btn[aria-expanded="true"] {
  background: rgba(80, 20, 20, 0.15);
}

.friends-row-menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 5;
  min-width: 128px;
  background: var(--panel-top);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.85);
  overflow: hidden;
}

.friends-row:last-child:not(:first-child) .friends-row-menu {
  top: auto;
  bottom: 100%;
}

.friends-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.friends-menu-item + .friends-menu-item {
  border-top: 1px solid rgba(120, 40, 50, 0.3);
}

.friends-menu-item:hover {
  background: rgba(80, 20, 20, 0.3);
}

.friends-menu-danger {
  color: var(--danger);
}

.friends-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 var(--space-4);
  padding: var(--space-1) 0;
  border-top: 1px solid rgba(120, 40, 50, 0.3);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex: none;
}

.friends-switch {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.friends-switch-track {
  width: 40px;
  height: 20px;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  border: 2px solid var(--border-subtle);
  position: relative;
}

.friends-switch.on .friends-switch-track {
  background: var(--accent-gold);
  border-color: var(--accent-gold-bright);
}

.friends-switch-thumb {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 0;
  background: var(--text-muted);
}

.friends-switch.on .friends-switch-thumb {
  transform: translateX(20px);
  background: var(--bg-deep);
}

.friends-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-gold);
  background: var(--panel-top);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.friends-btn .px-icon {
  width: 16px;
  height: 16px;
}

.friends-btn.solid {
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e);
  color: var(--accent-gold-bright);
  box-shadow: 0 4px 12px rgba(107, 26, 26, 0.6);
}

.friends-btn.solid:hover:not(:disabled) {
  background: linear-gradient(135deg, #8b2a2a, #4d1414);
}

.friends-btn.ghost {
  border-color: rgba(120, 40, 50, 0.3);
  color: var(--text-primary);
}

.friends-btn.ghost:hover {
  background: #2a1a30;
}

.friends-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.friends-section-label {
  padding: var(--space-1) 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.friends-section-gap {
  margin-top: var(--space-2);
}

.friends-empty,
.friends-empty-inline {
  padding: var(--space-2) 0;
  font-size: 12px;
  color: var(--text-muted);
}

.friends-empty {
  text-align: center;
  padding: var(--space-5) var(--space-3);
}

.friends-code-card {
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.9);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.friends-code-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

#friends-my-code {
  display: block;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--accent-gold-bright);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
  margin: var(--space-1) 0 var(--space-2);
  font-variant-numeric: tabular-nums;
}

.friends-add-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

#input-friend-add {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(120, 40, 50, 0.3);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  outline: none;
  user-select: text;
}

#input-friend-add:focus {
  border-color: var(--accent-red);
  box-shadow: 0 0 10px var(--accent-red-glow);
}

.friends-hint {
  margin-top: var(--space-2);
  font-size: 11px;
  color: var(--text-muted);
  text-wrap: pretty;
}

.friends-feedback {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 2px solid var(--success);
  background: var(--bg-deep);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
  word-break: break-word;
}

.friends-feedback.error {
  border-color: var(--danger);
  color: var(--danger);
}

.friends-blocked-section {
  margin-top: var(--space-4);
  padding-top: var(--space-2);
  border-top: 1px solid rgba(120, 40, 50, 0.3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

@media (max-width: 950px) {
  .friends-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: min(76vh, 500px);
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .friends-grab {
    display: block;
  }
}

/* ==================== PHASE 3: PARTY INVITES & SHAREABLE LINKS ==================== */
.login-join-banner {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent-gold);
  background: var(--bg-deep);
  color: var(--accent-gold-bright);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 0 12px var(--accent-gold-glow);
}

.login-join-banner[hidden] {
  display: none;
}

.party-share-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.party-share-btn {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-gold);
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e);
  color: var(--accent-gold-bright);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  box-shadow: 0 4px 12px rgba(107, 26, 26, 0.6);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.party-share-btn:hover {
  background: linear-gradient(135deg, #8b2a2a, #4d1414);
}

.party-share-btn:active {
  transform: translate(1px, 1px);
}

.party-share-btn.secondary {
  background: var(--panel-top);
  border-color: rgba(120, 40, 50, 0.3);
  color: var(--text-primary);
  box-shadow: none;
}

.party-share-btn.secondary:hover {
  background: #2a1a30;
  border-color: var(--accent-gold);
  color: var(--accent-gold-bright);
}

#hud-party-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-hud-party-action {
  position: relative;
  min-width: 32px;
  min-height: 32px;
  padding: 0 var(--space-1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-hud-party-action::after {
  content: '';
  position: absolute;
  inset: -6px;
}

.btn-hud-party-action:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold-bright);
}

.friends-invite-feedback {
  margin: var(--space-2) var(--space-4) 0;
}

.friends-btn.icon-only {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.party-invite-toast {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 4px);
  right: max(var(--space-4), env(safe-area-inset-right));
  z-index: var(--z-alert);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: min(400px, calc(100vw - 24px));
  background: linear-gradient(160deg, var(--panel-top), var(--bg-deep));
  border: 2px solid var(--accent-red);
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.95), 0 0 20px var(--accent-red-glow);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-ui);
  color: var(--text-primary);
}

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

.party-invite-toast-body {
  flex: 1;
  min-width: 0;
}

.party-invite-toast-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.party-invite-toast-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.party-invite-toast-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

@media (max-width: 950px) {
  .btn-hud-party-action {
    min-width: 44px;
    min-height: 44px;
  }

  .btn-hud-party-action::after {
    inset: 0;
  }

  .party-share-bar {
    flex-wrap: wrap;
  }

  .party-invite-toast {
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    max-width: none;
  }
}

/* ===== Layout & component classes (moved from index.html inline styles, 2026-11-15) ===== */

/* --- Shared utilities --- */
.flex-1 {
  flex: 1;
}

.full-width {
  width: 100%;
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.text-gold {
  color: var(--accent-gold);
}

.text-gold-bright {
  color: var(--accent-gold-bright);
}

.text-blue {
  color: var(--accent-blue-light);
}

.text-purple {
  color: var(--accent-purple-light);
}

.text-primary {
  color: var(--text-primary);
}

.modal-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.modal-header-centered {
  justify-content: center;
  margin-bottom: 20px;
}

.modal-actions-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* --- Grand announcement --- */
#grand-announcement {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent-gold-bright);
  font-size: 52px;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-shadow: 0 4px 10px rgba(0,0,0,0.8), 0 0 20px var(--accent-gold);
  pointer-events: none;
  z-index: var(--z-panel);
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
  font-family: 'Cinzel', serif;
}
#grand-announcement-level {
  font-size: 32px;
  color: var(--accent-gold-bright);
  text-shadow: 0 2px 4px rgba(0,0,0,0.9);
  letter-spacing: 4px;
  text-decoration: underline;
  text-underline-offset: 8px;
}
#grand-announcement-room {
  font-size: 64px;
  line-height: 1.1;
  color: var(--text-primary);
  text-shadow: 0 4px 8px rgba(0,0,0,0.9);
  letter-spacing: 2px;
}
#grand-announcement-mode {
  display: none;
  font-size: 40px;
  line-height: 1.2;
  color: var(--accent-gold-bright);
  letter-spacing: 1px;
  padding-top: 4px;
}

/* --- HUD --- */
.hud-vitals-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.vital-bar-tall {
  height: 18px;
}
.exp-wrapper-slim {
  height: 10px;
  margin-top: 4px;
  background: rgba(0,0,0,0.8);
  border: 1px solid rgba(140, 60, 60, 0.4);
}
#hud-exp-bar {
  background: linear-gradient(90deg, var(--accent-blue), #4a6fa5);
  width: 0%;
}
#hud-exp-text {
  font-size: 8px;
}
#hud-buff-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  max-width: 200px;
}
.hud-powerup {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel-bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
#hud-shockwave-container {
  border: 2px solid var(--accent-blue);
  overflow: hidden;
  box-shadow: 0 0 6px rgba(56,189,248,0.3);
}
.hud-powerup-icon {
  z-index: 2;
}
#hud-shockwave-cd {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0%;
  background: rgba(0,0,0,0.7);
  z-index: 3;
  transition: height 0.1s linear;
}
#hud-shield-container {
  border: 2px solid var(--accent-blue);
  box-shadow: 0 0 6px rgba(56,189,248,0.3);
}
.hud-cooldown-text {
  font-size: 9px;
}
#hud-shield-charges {
  position: absolute;
  bottom: -4px;
  right: -4px;
  z-index: 5;
  background: var(--danger);
  color: white;
  font-size: 8px;
  font-weight: bold;
  border-radius: 50%;
  padding: 1px 3px;
  border: 1px solid white;
}
#hud-leech-container {
  border: 2px solid var(--danger);
  box-shadow: 0 0 6px rgba(239,68,68,0.3);
}
#hud-desperate-run-container {
  border: 2px solid var(--accent-purple);
  box-shadow: 0 0 6px rgba(168,85,247,0.3);
}
.hud-powerup-icon-round {
  z-index: 2;
  border-radius: 50%;
}
#hud-bargainer-container {
  border: 2px solid var(--accent-gold);
  box-shadow: 0 0 6px rgba(234,179,8,0.3);
}
#hud-masochist-container {
  border: 2px solid var(--danger);
  box-shadow: 0 0 6px rgba(244,63,94,0.3);
}
#hud-executioners-edge-container {
  border: 2px solid var(--text-muted);
  box-shadow: 0 0 6px rgba(100,116,139,0.3);
}
#hud-reckless-dodge-container {
  border: 2px solid var(--success);
  box-shadow: 0 0 6px rgba(34,197,94,0.3);
}
#hud-dungeon-status {
  margin-top: 5px;
  opacity: 0.7;
  font-size: 11px;
}
.controls-toggle-row {
  display: flex;
  gap: 8px;
}
.btn-hud-small {
  padding: 5px 10px;
  font-size: 12px;
  border: 1px solid rgba(255,255,255,0.2);
}
#admin-panel {
  position: absolute;
  top: 98px;
  right: 20px;
  background: rgba(0,0,0,0.8);
  border: 2px solid var(--danger);
  border-radius: 8px;
  padding: 10px;
  color: var(--text-primary);
  z-index: var(--z-panel);
  min-width: 200px;
}
#admin-drag-handle {
  cursor: grab;
  display: flex;
  gap: 8px;
  align-items: center;
  user-select: none;
  touch-action: none;
}
.admin-title {
  color: var(--danger);
  margin: 0;
  font-size: 14px;
  pointer-events: none;
  flex: 1;
}
#btn-admin-collapse {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}
#btn-admin-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
}
#admin-panel-body {
  margin-top: 10px;
}
#btn-admin-clear {
  display: block;
  width: 100%;
  margin-bottom: 5px;
  font-size: 12px;
  padding: 5px;
}
.admin-btn-row {
  display: flex;
  gap: 5px;
  margin-bottom: 5px;
}
.admin-btn {
  font-size: 12px;
  padding: 5px;
  flex: 1;
}
#btn-admin-gems {
  border-color: var(--accent-blue);
}
#btn-admin-xp {
  border-color: var(--accent-purple);
}
#btn-admin-reset {
  border-color: var(--danger);
  color: var(--danger);
}
#btn-admin-kill {
  display: block;
  width: 100%;
  font-size: 12px;
  padding: 5px;
  background: var(--accent-red);
  border-color: var(--danger);
  color: white;
  margin-bottom: 5px;
}
.admin-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.admin-skip-row {
  display: flex;
  gap: 2px;
}
.admin-skip-btn {
  font-size: 10px;
  padding: 3px;
  flex: 1;
}
#btn-admin-skip-5 {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
#btn-admin-replay-tutorial {
  display: block;
  width: 100%;
  font-size: 12px;
  padding: 5px;
  margin-top: 5px;
  border-color: var(--accent-blue);
  color: var(--accent-blue-light);
}
#dev-console {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  background: rgba(0,0,0,0.9);
  border: 2px solid var(--accent-gold);
  padding: 10px;
  border-radius: 6px;
  z-index: var(--z-panel);
  font-family: monospace;
  display: flex;
  flex-direction: column;
}
.dev-console-title {
  color: var(--accent-gold);
  margin-bottom: 5px;
  font-weight: bold;
}
#dev-console-output {
  height: 150px;
  overflow-y: auto;
  color: var(--text-primary);
  font-size: 12px;
  margin-bottom: 10px;
}
#dev-console-input {
  width: 100%;
  padding: 8px;
  background: var(--border-subtle);
  border: 1px solid var(--disabled-bg);
  color: var(--text-primary);
  font-family: monospace;
}
.hud-hint-row {
  font-size: 14px;
  color: var(--text-secondary);
  width: fit-content;
  cursor: pointer;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}
#btn-show-hero-profile {
  margin-bottom: 2px;
}
.hud-key-chip {
  background: rgba(0,0,0,0.8);
  border: 1px solid var(--panel-border);
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: bold;
  color: var(--accent-gold-bright);
}
.hud-hint-label {
  text-shadow: 1px 1px 2px #000;
}
#hud-esc-hint {
  margin-bottom: 4px;
}
#hud-party-indicator {
  background: rgba(0,0,0,0.8);
  border: 1px solid var(--panel-border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 16px;
  text-shadow: 1px 1px 0 #000;
  color: var(--text-primary);
  width: fit-content;
  margin-bottom: 2px;
}
#hud-party-code {
  color: var(--accent-gold);
}
.chat-message .chat-highlight {
  font-weight: bold;
  color: var(--accent-gold-bright);
}
#hud-bottom-right {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  z-index: var(--z-hud);
}
#hud-charged-container {
  display: flex;
  align-items: center;
  gap: 8px;
}
#hud-charged-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
  text-align: right;
}
.hud-charged-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--panel-bg);
  border: 2px solid var(--accent-gold);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(245,158,11,0.35);
}
.hud-special-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
#hud-special-icon {
  filter: drop-shadow(0 0 3px #000);
}
.hud-cooldown-frame {
  height: 22px;
  width: 160px;
  background: rgba(0,0,0,0.8);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 2px;
}
#hud-cooldown-bar {
  background: var(--accent-gold);
  width: 100%;
  height: 100%;
  transition: width 0.1s linear;
}
#hud-cooldown-text {
  position: absolute;
  width: 100%;
  text-align: center;
  left: 0;
  line-height: 22px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
  font-size: 10px;
}
#revive-action-overlay {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  z-index: var(--z-touch);
}
.revive-prompt-text {
  color: var(--success);
  font-size: 20px;
  font-weight: bold;
  text-shadow: 1px 1px 4px #000;
  margin: 0 0 5px 0;
}
.revive-bar-track {
  width: 200px;
  height: 12px;
  background: rgba(0,0,0,0.7);
  border: 2px solid #000;
  border-radius: 6px;
  overflow: hidden;
}
#revive-action-bar {
  width: 0%;
  height: 100%;
  background: var(--success);
}

/* --- Login --- */
.auth-field-gap {
  margin-bottom: 15px;
}
.auth-input-centered {
  text-align: center;
}
.remember-me-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: center;
  margin-bottom: 20px;
  min-height: 44px;
}
#input-remember-me {
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.remember-me-label {
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  padding: 12px 0;
}
.auth-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}
#auth-toggle-link {
  color: var(--text-primary);
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
  margin-top: 5px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.auth-toggle-accent {
  color: var(--accent-gold-bright);
  font-weight: bold;
  text-decoration: underline;
}

/* --- Login: email code, forgot password, hero name, Google / Discord (js/ui/authSteps.js) --- */
.auth-msg {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 2px solid;
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  font-size: 14px;
  line-height: 1.4;
  text-wrap: pretty;
}
.auth-msg:empty { display: none; }
.auth-msg-error { color: var(--danger); border-color: var(--danger); }
.auth-msg-info { color: var(--text-secondary); border-color: var(--border-subtle); }

.auth-social {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
  width: 100%;
  max-width: 400px;
  margin: 0 auto var(--space-3);
}
.google-btn-host {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 40px;
}
.btn-discord {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  height: 40px;
  min-height: 40px;
  padding: 0 var(--space-3);
  background: var(--brand-discord);
  color: var(--brand-discord-text);
  border: 2px solid var(--brand-discord);
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
.btn-discord-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.btn-discord:hover,
.btn-discord:focus-visible { filter: brightness(1.12); }
.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: 13px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border-subtle);
}

.auth-forgot-link {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: calc(var(--space-2) * -1) 0 0;
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: underline;
}
/* Only in login mode: the sign-up fields (username box) are hidden then */
#input-username.hidden ~ .auth-forgot-link { display: flex; }

.auth-step-panel {
  display: none;
  flex-direction: column;
  gap: var(--space-2);
}
.auth-step-text {
  margin: 0 0 var(--space-2);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.4;
  text-wrap: pretty;
}
.auth-step-hint {
  margin: calc(var(--space-2) * -1) 0 var(--space-2);
  color: var(--text-muted);
  font-size: 12px;
}
.auth-code-input {
  font-family: var(--font-ui);
  font-size: 24px;
  letter-spacing: 0.4em;
  font-variant-numeric: tabular-nums;
  padding-left: calc(var(--space-4) + 0.4em); /* the trailing letter-spacing would push the digits left of centre */
}
.auth-step-links {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
}
.auth-link-btn {
  min-height: 44px;
  padding: 0 var(--space-3);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 14px;
  text-decoration: underline;
  cursor: pointer;
}
.auth-link-btn:disabled { color: var(--text-disabled); text-decoration: none; cursor: default; }

#login-modal[data-step="forgot"] #auth-step-forgot,
#login-modal[data-step="code"] #auth-step-code,
#login-modal[data-step="username"] #auth-step-username { display: flex; }

/* One step at a time: hide the parts that don't belong to it */
#login-modal[data-step="forgot"] :is(#input-username, .password-field, #password-hint, .auth-actions, .auth-social, .auth-forgot-link),
#login-modal[data-step="code"] :is(#input-email, #input-username, .password-field, #password-hint, .remember-me-row, .auth-actions, .auth-social, .auth-forgot-link),
#login-modal[data-step="username"] :is(#input-email, #input-username, .password-field, #password-hint, .remember-me-row, .auth-actions, .auth-social, .auth-forgot-link) { display: none; }
/* "Save my progress" has no Google/Discord/forgot options */
#login-modal.upgrading :is(.auth-social, .auth-forgot-link) { display: none; }

/* --- Main menu --- */
.main-menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.main-menu-actions > button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
#btn-enter-village {
  flex: 2 1 180px;
}
#btn-open-controls,
#btn-open-settings {
  flex: 1 1 120px;
}
#hero-select-modal {
  z-index: var(--z-modal-stacked);
}

/* --- Party lobby --- */
.party-lobby-card {
  max-width: 500px;
  text-align: center;
}
#party-lobby-subtitle {
  color: var(--text-secondary);
  margin-bottom: 20px;
}
#party-lobby-slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 25px;
}
#btn-party-leave {
  width: 100%;
  margin-top: 10px;
}

/* --- Blacksmith / forge --- */
.blacksmith-stat-col {
  text-align: right;
}
.stat-block {
  display: block;
}
.stat-block-sub {
  color: var(--accent-purple-light);
  font-size: 11px;
}
#forge-fail-modal {
  z-index: var(--z-modal-stacked);
}
.forge-fail-card {
  border-color: var(--danger);
  width: 380px;
  text-align: center;
}
.forge-fail-icon {
  font-size: 52px;
  margin-bottom: 10px;
}
.forge-fail-title {
  color: var(--danger);
  margin: 0 0 8px 0;
  font-size: 22px;
}
#forge-fail-reason {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px 0;
}
.forge-fail-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.forge-fail-btn {
  flex: 1;
  padding: 12px;
  font-size: 14px;
}

/* --- Shop --- */
.shop-card {
  border-color: var(--accent-purple-light);
}
.modal-header .shop-title {
  color: var(--accent-purple-light);
}
.shop-currency {
  color: var(--accent-blue-light);
  font-weight: bold;
}
.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 50vh;
  overflow-y: auto;
  padding-right: 10px;
}
.upgrade-row {
  background: rgba(0,0,0,0.5);
  border: 2px solid var(--border-subtle);
  padding: 15px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.upgrade-row-title {
  margin: 0 0 5px 0;
}
.upgrade-row-icon {
  vertical-align: middle;
  margin-right: 8px;
}
.upgrade-row-desc {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 250px;
}
.upgrade-row-btn {
  padding: 10px 20px;
}
.shop-title-orange {
  color: #f97316;
}
.shop-title-pink {
  color: #ec4899;
}

/* --- Barracks --- */
.barracks-card {
  border-color: var(--accent-gold);
  width: 450px;
}
#barracks-class-name {
  color: var(--accent-gold-bright);
  font-weight: bold;
}
.barracks-points-line {
  text-align: center;
  color: var(--text-primary);
  font-weight: bold;
  margin-bottom: 20px;
}
#barracks-stat-points {
  color: var(--success);
}
.upgrade-row-info {
  cursor: pointer;
  color: var(--accent-gold);
  font-size: 14px;
}
.upgrade-row-desc-plain {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* --- Portal --- */
.portal-card-compact {
  max-width: 450px;
  text-align: center;
}
#btn-close-portal {
  position: absolute;
  right: 15px;
  top: 15px;
}
#portal-view-mode {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.portal-mode-btn {
  padding: 15px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#portal-view-multi {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.portal-section {
  background: rgba(0,0,0,0.5);
  padding: 15px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}
.portal-section-title {
  margin-top: 0;
}
.portal-party-size-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-bottom: 15px;
}
#select-party-size {
  width: 100px;
  text-align: center;
  padding: 5px;
}
.portal-join-row {
  display: flex;
  gap: 10px;
}
#input-party-code {
  flex: 1;
  text-transform: uppercase;
}
#btn-back-mode {
  margin-top: 10px;
}

/* --- Campaign --- */
.campaign-card-box {
  width: 800px;
  max-width: 95vw;
  position: relative;
  padding: 20px;
}
.campaign-title {
  margin-top: 0;
  text-align: center;
  font-family: var(--font-serif);
  color: var(--accent-gold);
  font-size: 32px;
  text-shadow: 2px 2px 4px #000;
}
#campaign-map-container {
  position: relative;
  width: 100%;
  height: 450px;
  border: 4px solid #3f2e1a;
  border-radius: 8px;
  margin-bottom: 20px;
}
/* The art and the level circles live in this inner layer (phones size it to the image, see end of file) */
.campaign-map-art {
  position: absolute;
  inset: 0;
  background: url('assets/campaign_map_bg.jpg') no-repeat center center;
  background-size: cover;
  border-radius: 4px;
  box-shadow: inset 0 0 20px #000;
}
.campaign-map-hint { display: none; }

/* --- Pause modal Settings button --- */
.pause-settings-btn {
  width: 100%;
  min-height: 44px;
  margin-bottom: var(--space-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

/* --- Unified AAA Settings Modal --- */
#settings-modal {
  z-index: var(--z-modal-stacked);
  padding: var(--space-4);
}
body:has(#quit-modal:not(.hidden)) #settings-modal {
  z-index: var(--z-system);
}
.settings-card {
  width: min(820px, 100%);
  max-height: min(640px, 90vh);
  max-height: min(640px, 90dvh);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-color: var(--accent-red);
  font-family: var(--font-ui);
}
.settings-card:focus {
  outline: none;
}
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  margin-bottom: 0;
  border-bottom: 1px solid rgba(120, 40, 50, 0.35);
  background: rgba(10, 5, 12, 0.35);
  flex: none;
}
.settings-title-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
#settings-modal-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-gold);
  text-wrap: balance;
}
.settings-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}
.settings-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
.settings-nav {
  width: 210px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  background: rgba(10, 5, 12, 0.45);
  border-right: 1px solid rgba(120, 40, 50, 0.35);
  overflow-y: auto;
}
.settings-tab {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.settings-tab:hover {
  background: rgba(80, 20, 20, 0.18);
  color: var(--text-primary);
}
.settings-tab:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: -2px;
}
.settings-tab.active {
  background: rgba(139, 26, 26, 0.22);
  border-color: var(--accent-red);
  color: var(--accent-gold);
  box-shadow: 0 0 12px rgba(139, 26, 26, 0.25);
}
.settings-content {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.settings-tabpanel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.settings-tabpanel[hidden] {
  display: none;
}
.settings-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.settings-section-title {
  margin: 0 0 var(--space-1);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid rgba(120, 40, 50, 0.3);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-gold);
  text-wrap: balance;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3);
  background: rgba(10, 5, 12, 0.5);
  border: 1px solid rgba(120, 40, 50, 0.22);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.settings-row:hover {
  border-color: rgba(140, 60, 60, 0.4);
  background: rgba(80, 20, 20, 0.12);
}
.settings-row.is-muted {
  opacity: 0.6;
}
.settings-row-info {
  flex: 1 1 auto;
  min-width: 0;
}
.settings-row-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}
.settings-row-hint {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
  text-wrap: pretty;
}
.settings-row-note {
  margin-top: var(--space-1);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-gold-bright);
}
.settings-controls-note {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-wrap: pretty;
}
.settings-switch {
  position: relative;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  touch-action: manipulation;
}
.settings-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.settings-switch-track {
  width: 44px;
  height: 24px;
  box-sizing: border-box;
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  border: 2px solid rgba(120, 40, 50, 0.45);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.settings-switch-thumb {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.settings-switch input:checked + .settings-switch-track {
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e);
  border-color: var(--accent-gold);
}
.settings-switch input:checked + .settings-switch-track .settings-switch-thumb {
  transform: translateX(20px);
  background: var(--accent-gold-bright);
}
.settings-switch input:focus-visible + .settings-switch-track {
  outline: 2px solid var(--accent-gold-bright);
  outline-offset: 2px;
}
.settings-segmented {
  display: inline-flex;
  flex: none;
  border: 1px solid rgba(120, 40, 50, 0.4);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  overflow: hidden;
}
.settings-seg-btn {
  min-height: 40px;
  min-width: 44px;
  padding: 0 var(--space-3);
  border: none;
  border-right: 1px solid rgba(120, 40, 50, 0.28);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, color 0.15s ease;
}
.settings-seg-btn:last-child {
  border-right: none;
}
.settings-seg-btn:hover {
  background: #2a1a30;
  color: var(--text-primary);
}
.settings-seg-btn.active {
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e);
  color: var(--accent-gold-bright);
  box-shadow: inset 0 0 0 1px var(--accent-gold);
  font-weight: 700;
}
.settings-slider-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: none;
}
.settings-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 148px;
  height: 10px;
  background: var(--bg-deep);
  border: 1px solid rgba(120, 40, 50, 0.45);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
}
.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #8b2a2a, #4d1414);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #8b2a2a, #4d1414);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.settings-slider:focus-visible {
  outline: 2px solid var(--accent-gold-bright);
  outline-offset: 2px;
}
.settings-readout {
  min-width: 46px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
}
.settings-mini-btn {
  min-height: 36px;
  min-width: 44px;
  padding: 0 var(--space-2);
  font-size: 12px;
}
.settings-action-btn {
  box-sizing: border-box;
  width: 190px;
  height: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: 13px;
  white-space: nowrap;
  flex: none;
}
.settings-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.settings-keybind-btn {
  min-width: 120px;
  min-height: 40px;
  padding: 0 var(--space-3);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-gold);
  flex: none;
}
.settings-keybind-btn.is-rebinding {
  background: linear-gradient(135deg, #6b1a1a, #3d0e0e) !important;
  color: var(--accent-gold-bright) !important;
  border-color: var(--accent-gold) !important;
}
.settings-shortcuts-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.settings-shortcut-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  background: rgba(10, 5, 12, 0.5);
  border: 1px solid rgba(120, 40, 50, 0.25);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}
.kbd-chip {
  background: rgba(154, 34, 34, 0.22);
  border: 1px solid rgba(154, 34, 34, 0.38);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}
.settings-mods-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.mod-slot-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  background: rgba(10, 5, 12, 0.5);
  border: 1px solid rgba(120, 40, 50, 0.25);
  border-radius: var(--radius-sm);
}
.mod-slot-card.is-loaded {
  border-color: var(--accent-red);
  background: rgba(139, 26, 26, 0.14);
}
.mod-slot-card.is-boss {
  border-color: rgba(154, 34, 34, 0.55);
}
.mod-slot-top {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.mod-thumb {
  width: 48px;
  height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--panel-top), var(--bg-deep));
  border: 2px solid rgba(120, 40, 50, 0.35);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.mod-slot-card.is-loaded .mod-thumb {
  border-color: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red-glow);
}
.mod-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.mod-thumb-empty {
  font-size: 11px;
  color: var(--text-muted);
}
.mod-slot-meta {
  flex: 1 1 auto;
  min-width: 0;
}
.mod-slot-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}
.mod-slot-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mod-slot-card.is-loaded .mod-slot-status {
  color: var(--success);
}
.mod-slot-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.mod-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.mod-upload-btn,
.mod-clear-btn {
  flex: 1;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-2);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
}
.mod-clear-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.settings-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid rgba(120, 40, 50, 0.35);
  background: rgba(10, 5, 12, 0.35);
  flex: none;
}
.settings-footer-status {
  font-size: 12px;
  color: var(--text-muted);
}
.settings-footer-status.is-flash {
  color: var(--success);
  font-weight: 600;
}
.settings-footer-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.settings-footer-actions button {
  min-height: 44px;
  padding: 0 var(--space-4);
  white-space: nowrap;
}
@media (max-width: 760px) {
  #settings-modal {
    padding: var(--space-2);
  }
  .settings-card {
    width: 100%;
    max-height: 92dvh;
  }
  .settings-header {
    padding: var(--space-3) var(--space-4);
  }
  .settings-shell {
    flex-direction: column;
  }
  .settings-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid rgba(120, 40, 50, 0.35);
    padding: var(--space-2);
  }
  .settings-tab {
    flex: 0 0 auto;
    width: auto;
    min-height: 44px;
    white-space: nowrap;
    justify-content: center;
  }
  .settings-content {
    padding: var(--space-3) var(--space-4);
  }
  .settings-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }
  .settings-row:has(> .settings-switch),
  .settings-row.settings-keybind-row {
    flex-direction: row;
    align-items: center;
  }
  .settings-slider-wrap {
    width: 100%;
  }
  .settings-slider {
    flex: 1 1 auto;
    width: auto;
  }
  .settings-segmented {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }
  .settings-seg-btn {
    min-width: 0;
    min-height: 44px;
    padding: 0 var(--space-1);
    font-size: 12px;
    text-align: center;
  }
  .settings-keybind-btn,
  .settings-mini-btn,
  .mod-upload-btn,
  .mod-clear-btn {
    min-height: 44px;
  }
  .settings-keybind-btn {
    min-width: 84px;
  }
  .settings-mods-grid {
    grid-template-columns: 1fr;
  }
  .settings-footer {
    padding: var(--space-3) var(--space-4);
    flex-wrap: wrap;
  }
  .settings-footer-actions {
    width: 100%;
  }
  .settings-footer-actions button {
    flex: 1;
  }
}
@media (max-height: 480px) {
  #settings-modal {
    padding: var(--space-2);
  }
  .settings-card {
    max-height: 94dvh;
  }
  .settings-header {
    padding: var(--space-2) var(--space-4);
  }
  .settings-nav {
    width: 176px;
    padding: var(--space-2);
  }
  .settings-content {
    padding: var(--space-3) var(--space-4);
  }
  .settings-footer {
    padding: var(--space-2) var(--space-4);
  }
}
@media (prefers-reduced-motion: reduce) {
  .settings-card,
  .settings-tab,
  .settings-switch-track,
  .settings-switch-thumb,
  .settings-seg-btn {
    animation: none !important;
    transition: none !important;
  }
}

/* --- Replay tutorial / quit --- */
.replay-tutorial-card {
  border-color: var(--accent-gold-bright);
  width: 350px;
  max-width: 92vw;
}
.replay-tutorial-title {
  color: var(--accent-gold-bright);
  text-align: center;
  margin-bottom: 12px;
}
#quit-modal {
  z-index: var(--z-system);
}
.quit-card {
  border-color: var(--danger);
  width: 350px;
}
/* --- Notice card ("Playing Elsewhere"): one message, optional tip, one action --- */
#tab-stopped-modal {
  z-index: var(--z-system);
}
.notice-card {
  width: 420px;
  max-width: calc(100% - var(--space-6));
  padding: var(--space-6) var(--space-5) var(--space-5);
  border-color: var(--accent-gold);
  text-align: center;
}
.notice-title {
  margin: 0 0 var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 2px solid var(--border-subtle);
  font-family: var(--font-ui);
  font-size: 22px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-gold);
  text-wrap: balance;
}
.notice-text {
  margin: 0 0 var(--space-5);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  text-wrap: pretty;
}
.notice-tip {
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.25);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-align: left;
  text-wrap: pretty;
}
.notice-text:has(+ .notice-tip:not([hidden])) {
  margin-bottom: var(--space-4); /* text + tip sit closer as one group */
}
.notice-action {
  width: 100%;
  min-height: 44px;
}

#quit-modal-title {
  color: var(--danger);
  text-align: center;
  margin-bottom: 20px;
}

/* --- Death overlays --- */
#respawn-overlay {
  background: transparent;
  backdrop-filter: none;
  z-index: var(--z-death);
}
.death-overlay-layout {
  text-align: center;
  height: 100%;
  padding: 4vh 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.respawn-title {
  color: var(--accent-gold);
  font-size: clamp(30px, min(8vh, 12vw), 48px);
  margin-bottom: 6px;
  text-shadow: 2px 2px 8px #000;
}
#respawn-text {
  color: var(--text-primary);
  font-size: clamp(16px, 4vh, 24px);
  text-shadow: 1px 1px 4px #000;
}
.revive-progress-line {
  color: var(--success);
  font-size: clamp(14px, 3.4vh, 20px);
  text-shadow: 1px 1px 4px #000;
  height: 24px;
}
#btn-self-respawn {
  font-size: 18px;
  padding: 10px 20px;
}
#permadeath-overlay {
  background: transparent;
  backdrop-filter: none;
  z-index: var(--z-death);
}
.permadeath-title {
  color: var(--text-primary);
  font-size: clamp(30px, min(8vh, 12vw), 72px);
  margin-bottom: 6px;
  text-shadow: 2px 2px 8px #000;
}
.permadeath-text {
  color: var(--text-primary);
  font-size: clamp(14px, 3.4vh, 24px);
  text-shadow: 1px 1px 4px #000;
  margin-bottom: 6px;
}
.permadeath-actions {
  display: flex;
  gap: 20px;
  justify-content: center;
}

/* --- Spectator --- */
#spectator-ui {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 15, 20, 0.95);
  border: 2px solid var(--accent-gold);
  border-radius: 12px;
  padding: 15px 25px;
  text-align: center;
  z-index: var(--z-panel);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.8), inset 0 0 15px rgba(245, 158, 11, 0.2);
}
.spectator-nav-row {
  display: flex;
  align-items: center;
  gap: 20px;
}
.spectate-nav-btn {
  padding: 8px 16px;
  font-size: 18px;
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}
.spectator-name-col {
  min-width: 160px;
}
.spectator-label {
  font-size: 12px;
  color: var(--accent-gold-bright);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: bold;
  margin-bottom: 2px;
}
#spectate-target-name {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-primary);
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
#btn-spectate-leave {
  font-size: 14px;
  padding: 8px 20px;
  width: 100%;
  margin-top: 5px;
}

/* --- Hero profile --- */
.hero-profile-card {
  width: 650px;
  display: flex;
  flex-direction: row;
  gap: 20px;
  padding: 15px;
}
.profile-left-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-right: 2px solid var(--border-subtle);
  padding-right: 20px;
  position: relative;
}
#profile-portrait {
  width: 128px;
  height: 128px;
  margin-bottom: 10px;
  filter: drop-shadow(0 0 10px rgba(0,0,0,0.5));
  image-rendering: pixelated;
  background-repeat: no-repeat;
}
#profile-class-level {
  margin: 0;
  color: var(--text-primary);
  font-size: 24px;
  text-transform: uppercase;
}
.profile-xp-track {
  width: 100%;
  background: var(--border-subtle);
  border-radius: 4px;
  height: 18px;
  margin-top: 10px;
  position: relative;
  border: 1px solid #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#profile-xp-bar {
  height: 100%;
  background: linear-gradient(90deg, #f97316, #eab308, #f97316);
  width: 45%;
  border-radius: 3px;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
}
#profile-xp-text {
  position: relative;
  z-index: 2;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: bold;
  text-shadow: 1px 1px 2px #000, -1px -1px 2px #000;
}
.profile-section {
  width: 100%;
  margin-top: 20px;
  text-align: left;
}
.profile-section-title {
  margin: 0 0 5px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.profile-weapon-box {
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--accent-gold);
  padding: 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#profile-weapon-name {
  color: var(--accent-gold);
  font-weight: bold;
  font-size: 14px;
}
#profile-powerups {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.profile-right-col {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  position: relative;
}
#btn-close-profile {
  position: absolute;
  right: 0px;
  top: 0px;
}
.profile-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--border-subtle);
  margin-right: 30px;
}
#profile-stats-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 5px;
  max-height: 460px;
}
#profile-abilities-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-right: 5px;
  max-height: 460px;
}

/* --- iOS fullscreen --- */
#ios-fullscreen-modal {
  z-index: var(--z-alert);
}
.ios-fullscreen-card {
  width: 360px;
  text-align: center;
}
#btn-ios-fullscreen-close {
  padding: 10px 24px;
}

/* ===== Popup frame and phone layout fixes (2026-11-15) =====
   Phones used to shrink every popup to 85% (transform: scale), which made text tiny and
   let wide content spill out sideways. Popups now keep their real size and reflow instead. */

/* Close X: same look in every popup, with a 44px tap area. The negative margin keeps the header height. */
.btn-close {
  min-width: 44px;
  min-height: 44px;
  margin: -10px -10px -10px 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
/* The portal X was placed against the screen corner because its card wasn't positioned */
.portal-card-compact { position: relative; max-width: min(450px, 90%); }
#btn-close-portal { top: 6px; right: 6px; margin: 0; }
#btn-close-profile { top: -10px; right: -10px; margin: 0; }

/* Two equal hero columns that may shrink below their content width */
.roster-container { grid-template-columns: repeat(2, minmax(0, 1fr)); }

@media (max-width: 950px) {
  .modal-card {
    transform: none;
    padding: var(--space-4);
  }
}

/* Portrait phones */
@media (max-width: 600px) {
  /* Main menu heroes: icon above the text so two cards fit side by side */
  .roster-card { flex-direction: column; align-items: center; text-align: center; padding: var(--space-3); gap: var(--space-2); }
  .roster-info { text-align: center; width: 100%; }

  /* Hero profile: portrait and gear on top, stats below; the X goes to the card's top corner */
  .hero-profile-card { flex-direction: column; gap: var(--space-4); position: relative; }
  .profile-left-col { border-right: none; padding-right: 0; border-bottom: 2px solid var(--border-subtle); padding-bottom: var(--space-4); }
  .profile-right-col { position: static; }
  .profile-tabs { margin-right: 0; }
  #btn-close-profile { top: 4px; right: 4px; }

  /* Shop and barracks rows: text on top, a full-width 44px button underneath */
  .upgrade-row { flex-direction: column; align-items: stretch; gap: var(--space-2); }
  .upgrade-row-desc { max-width: none; }
  .upgrade-row-btn { width: 100%; min-height: 44px; }
}

/* ===== Portrait phones: handheld ("Gameboy") layout =====
   The game screen takes the top of the phone and a solid control deck the bottom, so the touch
   controls never cover the game or each other. Landscape keeps the floating controls.
   Deck layout, measured from the deck's bottom-right (fits 360-430px wide):
     top row  : ☰ menu, 💬 chat (left) · ✋ interact (centre) · ⛶ fullscreen (right)
     left     : thumb stick
     right    : a diamond around (110, 100): ⚔ attack (right, big), special (left), charge (top), dash (bottom) */
@media (max-width: 600px) and (orientation: portrait) {
  body.is-mobile {
    --deck-h: calc(clamp(250px, 31vh, 290px) + env(safe-area-inset-bottom));
    --deck-b: env(safe-area-inset-bottom);
    --deck-row: calc(var(--deck-h) - 54px); /* bottom offset of the 44px top row */
  }

  body.is-mobile #game-canvas { height: calc(100% - var(--deck-h)); }

  body.is-mobile #touch-deck {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--deck-h);
    z-index: var(--z-world);
    background: linear-gradient(180deg, var(--panel-top), var(--bg-deep));
    border-top: 2px solid var(--accent-gold);
    box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.6), 0 -4px 12px rgba(0, 0, 0, 0.6);
  }

  /* Thumb stick: left, centred on the diamond's middle line */
  body.is-mobile #virtual-joystick-base {
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(38px + var(--deck-b));
  }

  body.is-mobile .mobile-action-group {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: var(--deck-h);
  }

  body.is-mobile .mobile-action-btn { width: 58px; height: 58px; }
  body.is-mobile .attack-btn { width: 72px; height: 72px; right: calc(16px + env(safe-area-inset-right)); bottom: calc(64px + var(--deck-b)); }
  body.is-mobile .special-btn { right: calc(139px + env(safe-area-inset-right)); bottom: calc(71px + var(--deck-b)); }
  body.is-mobile .charge-btn { right: calc(81px + env(safe-area-inset-right)); bottom: calc(129px + var(--deck-b)); }
  body.is-mobile .dash-btn { right: calc(81px + env(safe-area-inset-right)); bottom: calc(13px + var(--deck-b)); }
  body.is-mobile .interact-btn { width: 44px; height: 44px; right: auto; left: calc(50% - 22px); bottom: var(--deck-row); }

  /* System buttons move from the crowded top-right into the deck's top row */
  body.is-mobile #btn-hud-menu,
  body.is-mobile #btn-quick-chat,
  body.is-mobile #btn-mobile-chat {
    position: fixed;
    top: auto;
    bottom: var(--deck-row);
    width: 44px;
    height: 44px;
    padding: 0;
    align-items: center;
    justify-content: center;
  }
  body.is-mobile #btn-hud-menu { display: flex; left: calc(16px + env(safe-area-inset-left)); }
  body.is-mobile #btn-quick-chat,
  body.is-mobile #btn-mobile-chat { left: calc(70px + env(safe-area-inset-left)); }
  body.is-mobile #btn-mobile-fullscreen {
    top: auto;
    bottom: var(--deck-row);
    right: calc(16px + env(safe-area-inset-right));
    min-height: 44px;
  }

  /* Things that sat at the bottom of the screen now sit at the bottom of the game screen */
  body.is-mobile #hud-tutorial-overlay { bottom: calc(var(--deck-h) + 10px) !important; max-width: 92vw; }
  body.is-mobile #revive-action-overlay { bottom: calc(var(--deck-h) + 16px); }
  body.is-mobile #spectator-ui { bottom: calc(var(--deck-h) + 12px); }
}
#touch-deck { display: none; }

/* Tutorial highlights (rings and bar tags) only point at HUD and touch controls, so hide them while
   a popup covers those controls; they come back when it closes. The tutorial itself is unchanged. */
body:has(.modal-backdrop:not(.hidden)) .tut-ring,
body:has(.modal-backdrop:not(.hidden)) .tut-label {
  visibility: hidden;
}

/* Landscape phones: Fullscreen sits below the HUD chip row (it used to cover the guest Save bar) */
@media (max-width: 950px) and (orientation: landscape) {
  body.is-mobile #btn-mobile-fullscreen {
    top: calc(max(8px, env(safe-area-inset-top)) + 52px);
  }

  /* The tutorial card fills the gap between the thumb stick (left 64 + 124px) and the action
     buttons (their leftmost edge is 266px from the right), so it never covers a control. */
  body.is-mobile #hud-tutorial-overlay {
    left: calc(max(64px, env(safe-area-inset-left) + 40px) + 132px) !important;
    right: calc(max(48px, env(safe-area-inset-right) + 24px) + 226px);
    transform: none !important;
    width: auto;
    max-width: none;
  }
}

/* Small landscape phones (iPhone SE size): the HUD chip row is wider than the screen, so it wraps
   onto two lines like in portrait, and Fullscreen moves under the hero panel where there is room. */
@media (max-width: 760px) and (orientation: landscape) {
  body.is-mobile .hud-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    align-self: flex-start;
    min-width: 0;
  }
  body.is-mobile #btn-mobile-fullscreen {
    top: calc(max(8px, env(safe-area-inset-top)) + 96px);
    right: auto;
    left: max(16px, env(safe-area-inset-left));
  }
  body.is-mobile #hud-tutorial-overlay { padding: var(--space-2) var(--space-3); }
  body.is-mobile #hud-tutorial-text { font-size: 12px; }
}

/* ===== User-selected Screen Orientation overrides (Settings -> Display -> Screen Orientation) ===== */
body.is-mobile[data-orientation="vertical"] {
  --deck-h: calc(clamp(250px, 31vh, 290px) + env(safe-area-inset-bottom));
  --deck-b: env(safe-area-inset-bottom);
  --deck-row: calc(var(--deck-h) - 54px);
}
body.is-mobile[data-orientation="vertical"] #game-canvas { height: calc(100% - var(--deck-h)); }
body.is-mobile[data-orientation="vertical"] #touch-deck {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--deck-h);
  z-index: var(--z-world);
  background: linear-gradient(180deg, var(--panel-top), var(--bg-deep));
  border-top: 2px solid var(--accent-gold);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.6), 0 -4px 12px rgba(0, 0, 0, 0.6);
}
body.is-mobile[data-orientation="vertical"] #virtual-joystick-base {
  left: calc(20px + env(safe-area-inset-left));
  bottom: calc(38px + var(--deck-b));
}
body.is-mobile[data-orientation="vertical"] .mobile-action-group {
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  height: var(--deck-h);
}
body.is-mobile[data-orientation="vertical"] .mobile-action-btn { width: 58px; height: 58px; }
body.is-mobile[data-orientation="vertical"] .attack-btn { width: 72px; height: 72px; right: calc(16px + env(safe-area-inset-right)); bottom: calc(64px + var(--deck-b)); }
body.is-mobile[data-orientation="vertical"] .special-btn { right: calc(139px + env(safe-area-inset-right)); bottom: calc(71px + var(--deck-b)); }
body.is-mobile[data-orientation="vertical"] .charge-btn { right: calc(81px + env(safe-area-inset-right)); bottom: calc(129px + var(--deck-b)); }
body.is-mobile[data-orientation="vertical"] .dash-btn { right: calc(81px + env(safe-area-inset-right)); bottom: calc(13px + var(--deck-b)); }
body.is-mobile[data-orientation="vertical"] .interact-btn { width: 44px; height: 44px; right: auto; left: calc(50% - 22px); bottom: var(--deck-row); }
body.is-mobile[data-orientation="vertical"] #btn-hud-menu,
body.is-mobile[data-orientation="vertical"] #btn-quick-chat,
body.is-mobile[data-orientation="vertical"] #btn-mobile-chat {
  position: fixed;
  top: auto;
  bottom: var(--deck-row);
  width: 44px;
  height: 44px;
  padding: 0;
  align-items: center;
  justify-content: center;
}
body.is-mobile[data-orientation="vertical"] #btn-hud-menu { display: flex; left: calc(16px + env(safe-area-inset-left)); }
body.is-mobile[data-orientation="vertical"] #btn-quick-chat,
body.is-mobile[data-orientation="vertical"] #btn-mobile-chat { left: calc(70px + env(safe-area-inset-left)); }
body.is-mobile[data-orientation="vertical"] #btn-mobile-fullscreen {
  top: auto;
  bottom: var(--deck-row);
  left: auto;
  right: calc(16px + env(safe-area-inset-right));
  min-height: 44px;
}
body.is-mobile[data-orientation="vertical"] #hud-tutorial-overlay {
  left: 50% !important;
  right: auto;
  transform: translateX(-50%) !important;
  bottom: calc(var(--deck-h) + 10px) !important;
  max-width: 92vw;
}
body.is-mobile[data-orientation="vertical"] #revive-action-overlay { bottom: calc(var(--deck-h) + 16px); }
body.is-mobile[data-orientation="vertical"] #spectator-ui { bottom: calc(var(--deck-h) + 12px); }

/* Forced horizontal on mobile: suppress portrait deck and restore wide floating controls */
body.is-mobile[data-orientation="horizontal"] #game-canvas { height: 100%; }
body.is-mobile[data-orientation="horizontal"] #touch-deck { display: none; }
body.is-mobile[data-orientation="horizontal"] #virtual-joystick-base {
  bottom: max(32px, calc(env(safe-area-inset-bottom) + 20px));
  left: max(64px, calc(env(safe-area-inset-left) + 40px));
}
body.is-mobile[data-orientation="horizontal"] .mobile-action-group {
  left: auto;
  right: max(48px, calc(env(safe-area-inset-right) + 24px));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  width: 220px;
  height: 170px;
}
body.is-mobile[data-orientation="horizontal"] .mobile-action-btn { width: 58px; height: 58px; }
body.is-mobile[data-orientation="horizontal"] .attack-btn { right: 0; bottom: 0; width: 80px; height: 80px; }
body.is-mobile[data-orientation="horizontal"] .dash-btn { right: 111px; bottom: 11px; }
body.is-mobile[data-orientation="horizontal"] .special-btn { right: 82px; bottom: 82px; }
body.is-mobile[data-orientation="horizontal"] .charge-btn { right: 11px; bottom: 111px; }
body.is-mobile[data-orientation="horizontal"] .interact-btn { left: auto; right: 172px; bottom: 73px; width: 46px; height: 46px; }
body.is-mobile[data-orientation="horizontal"] #btn-hud-menu,
body.is-mobile[data-orientation="horizontal"] #btn-quick-chat,
body.is-mobile[data-orientation="horizontal"] #btn-mobile-chat {
  position: relative;
  top: auto;
  bottom: auto;
  left: auto;
  width: auto;
  height: auto;
  padding: 2px 10px;
}
body.is-mobile[data-orientation="horizontal"] #btn-mobile-fullscreen {
  top: calc(max(8px, env(safe-area-inset-top)) + 52px);
  bottom: auto;
  left: auto;
  right: max(10px, env(safe-area-inset-right));
}
body.is-mobile[data-orientation="horizontal"] #hud-tutorial-overlay {
  bottom: 8px !important;
  left: calc(max(64px, env(safe-area-inset-left) + 40px) + 132px) !important;
  right: calc(max(48px, env(safe-area-inset-right) + 24px) + 226px);
  transform: none !important;
  width: auto;
  max-width: none;
}
body.is-mobile[data-orientation="horizontal"] #revive-action-overlay { bottom: 120px; }
body.is-mobile[data-orientation="horizontal"] #spectator-ui { bottom: 30px; }

/* Desktop vertical preference: keep full canvas coordinates, wrap HUD items gracefully if narrow */
body[data-orientation="vertical"]:not(.is-mobile) #hud {
  flex-wrap: wrap;
  column-gap: 6px;
}
body[data-orientation="vertical"]:not(.is-mobile) #hud > .hud-right {
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-self: flex-start;
}

/* Hero profile stat icons are 32px pixel icons (were emojis) */
.stat-icon-ui { width: 32px; }

/* ===== Party lobby level: level card, team votes, map marks (2026-11-15) ===== */
/* The map opens on top of the party lobby and the friends panel (invite: pick a level first) */
#campaign-modal {
  z-index: var(--z-modal-stacked);
}
.campaign-subtitle {
  margin: 0 0 var(--space-3);
}

.party-level {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-md);
  background: var(--bg-deep);
  text-align: left;
}
.party-level-thumb {
  position: relative;
  flex: none;
  width: 88px;
  height: 60px;
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background-image: url('assets/campaign_map_bg.jpg');
  background-repeat: no-repeat;
  overflow: hidden;
}
.party-level-thumb .campaign-node.mini {
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  border-width: 2px;
  font-size: 11px;
  cursor: default;
}
.party-level-thumb .campaign-node.mini.boss-node {
  width: 28px;
  height: 28px;
}
.party-level-thumb .campaign-node.mini:hover {
  transform: translate(-50%, -50%);
}
.party-level-thumb .campaign-node.mini .boss-badge {
  top: -9px;
  right: -9px;
}
.party-level-text {
  flex: 1;
  min-width: 0;
}
.party-level-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}
.party-level-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.04em;
  color: var(--accent-gold);
  text-shadow: 2px 2px 0 #000;
}
.party-level-boss {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--danger);
}
.party-level-boss.is-none {
  color: var(--text-muted);
}
.party-level-btn {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  background: var(--panel-top);
  color: var(--accent-gold-bright);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow 0.15s ease;
}
.party-level-btn:hover {
  box-shadow: 0 0 12px var(--accent-gold-glow);
}
.party-level-btn:active {
  transform: translate(1px, 1px);
}
.party-level-btn.is-vote {
  border-color: var(--accent-blue);
  color: var(--accent-blue-light);
}
.party-level-btn.is-vote:hover {
  box-shadow: 0 0 12px var(--accent-blue-glow);
}

.party-votes {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 2px dashed var(--accent-blue);
  border-radius: var(--radius-md);
  background: var(--bg-deep);
  text-align: left;
  font-size: 13px;
}
.party-votes-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-weight: 700;
  color: var(--accent-blue-light);
}
.party-vote-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
}
.party-vote-who {
  flex: 1;
  min-width: 0;
  color: var(--text-secondary);
}
.party-vote-who strong {
  color: var(--text-primary);
}
.party-vote-use {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-sm);
  background: var(--accent-gold);
  color: var(--bg-deep);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.party-vote-use:hover {
  background: var(--accent-gold-bright);
}
.party-vote-use:active {
  transform: translate(1px, 1px);
}

/* Player rows: the host's crown and each teammate's vote */
.party-host-crown {
  margin-left: calc(-1 * var(--space-1));
}
.party-slot-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.party-vote-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 700;
  color: var(--accent-blue-light);
  font-variant-numeric: tabular-nums;
}

/* Map marks while the map is open from the lobby: NOW = current level, blue ring = your vote */
.campaign-node.is-current {
  box-shadow: 0 0 0 4px var(--accent-gold-bright), 0 0 18px var(--accent-gold-glow);
  cursor: default;
}
.campaign-node.is-current:hover {
  transform: translate(-50%, -50%);
}
.campaign-node.is-my-vote {
  box-shadow: 0 0 0 4px var(--accent-blue-light), 0 0 18px var(--accent-blue-glow);
}
.campaign-node .node-tag,
.campaign-node .node-votes {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-weight: 700;
  pointer-events: none;
}
.campaign-node .node-tag {
  top: -26px;
  padding: 0 var(--space-1);
  background: var(--accent-gold-bright);
  color: var(--bg-deep);
  font-size: 10px;
  letter-spacing: 0.06em;
}
.campaign-node .node-votes {
  bottom: -20px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 0 var(--space-1);
  border: 2px solid var(--accent-blue);
  background: var(--bg-deep);
  color: var(--accent-blue-light);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Phones: the Change / Suggest button gets its own row so the level text has room */
@media (max-width: 600px) {
  .party-level {
    flex-wrap: wrap;
  }
  .party-level-btn {
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* ===== Campaign map as a swipe map on phones (2026-11-15) =====
   Same query as the tour card: narrow windows and short (landscape phone) windows.
   The art keeps its real 1376x768 shape at a comfortable height, wider than the screen,
   inside a frame the player swipes sideways. Circles stay 36px / 48px. */
@media (max-width: 600px), (max-height: 520px) {
  #campaign-map-container {
    /* fixed, not vh: shorter makes the 36/48px circles overlap (landscape phones scroll the card instead) */
    --map-h: 300px;
    height: auto;
    /* room for level 10's NOW tag and skull above; the rest of the badges stay inside the art */
    padding: var(--space-3) var(--space-3) var(--space-1);
    background: var(--bg-deep);
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
    margin: 0 auto var(--space-2);
    /* hug the map: a landscape phone shows it whole, a portrait phone gets a swipe frame */
    width: fit-content;
    max-width: 100%;
  }
  .campaign-map-art {
    position: relative;
    inset: auto;
    height: var(--map-h);
    width: calc(var(--map-h) * 1376 / 768);
    background-size: 100% 100%;
  }
  .campaign-map-hint:not([hidden]) {
    display: block;
    margin: 0 0 var(--space-3);
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
  }
}

/* A party invite popup must stay readable and tappable over the village tour card:
   push the (top-pinned) tour card below it while it is showing. */
@media (max-width: 900px), (max-height: 520px) {
  body:has(#party-invite-toast:not([hidden])) .tour-card {
    top: calc(env(safe-area-inset-top, 0px) + 96px);
  }
  /* the arrow would sit on top of the toast text; the card still names the building */
  body:has(#party-invite-toast:not([hidden])) .tour-arrow {
    visibility: hidden;
  }
}

/* --- Legal links & standalone Privacy Policy / Terms pages --- */
.auth-legal-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: 12px;
  color: var(--text-muted);
}
.auth-legal-links a {
  color: var(--text-muted);
  text-decoration: underline;
}
.auth-legal-links a:hover,
.auth-legal-links a:focus-visible {
  color: var(--accent-gold);
}

html:has(body.legal-page),
body.legal-page {
  overflow: auto;
  height: auto;
  min-height: 100%;
  font-family: var(--font-ui);
}
body.legal-page,
body.legal-page * {
  user-select: text;
}
.legal-shell {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: var(--space-5) var(--space-4);
}
.legal-card {
  width: 680px;
  max-width: 100%;
  text-align: left;
  border-radius: var(--radius-md);
}
.legal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--border-subtle);
}
.legal-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-gold);
  margin-bottom: var(--space-1);
}
.legal-header h1 {
  font-family: var(--font-ui);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}
.legal-updated {
  font-size: 13px;
  color: var(--text-muted);
}
.legal-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--space-4);
  text-decoration: none;
  white-space: nowrap;
}
.legal-section {
  margin-bottom: var(--space-4);
}
.legal-section h2 {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-gold);
  margin-bottom: var(--space-2);
}
.legal-section p,
.legal-section li {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.legal-section p + ul,
.legal-section ul + p {
  margin-top: var(--space-2);
}
.legal-section ul {
  padding-left: var(--space-5);
}
.legal-section li + li {
  margin-top: var(--space-1);
}
.legal-section code {
  background: var(--bg-deep);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-size: 13px;
  color: var(--text-primary);
}
.legal-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-top: var(--space-3);
  border-top: 2px solid var(--border-subtle);
  font-size: 13px;
  color: var(--text-muted);
}
.legal-section a,
.legal-footer a {
  color: var(--accent-gold);
  text-decoration: underline;
}
@media (max-width: 600px) {
  .legal-header {
    flex-direction: column;
  }
}

/* ==================== MOBILE QUICK CHAT (MLBB Style) ====================
   1. Passive click-through left feed (no solid box, max 3 lines, 5s fade-up)
   2. Slim input bar styled to match Dunra's pixel-medieval modals & deck
   3. Locks layout height when open so mobile soft keyboard never squashes/shifts game */

html:not(:fullscreen):has(body.mobile-chat-open) {
  height: var(--mobile-stable-h, 100%) !important;
  min-height: var(--mobile-stable-h, 100%) !important;
  max-height: var(--mobile-stable-h, 100%) !important;
  overflow: hidden !important;
}

html:fullscreen:has(body.mobile-chat-open) {
  overflow: hidden !important;
}

body.mobile-chat-open {
  height: var(--mobile-stable-h, 100%) !important;
  min-height: var(--mobile-stable-h, 100%) !important;
  max-height: var(--mobile-stable-h, 100%) !important;
  overflow: hidden !important;
}

.mobile-chat-feed {
  display: none;
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(max(32px, calc(env(safe-area-inset-bottom) + 20px)) + 134px);
  width: min(300px, 44vw);
  max-height: 68px;
  flex-direction: column;
  justify-content: flex-end;
  gap: var(--space-1);
  overflow: hidden;
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  z-index: var(--z-hud);
}

.mobile-chat-feed * {
  pointer-events: none;
  user-select: none;
}

body.is-mobile .mobile-chat-feed {
  display: flex;
}

@media (max-width: 950px) {
  .mobile-chat-feed {
    display: flex;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  body.is-mobile .mobile-chat-feed {
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(var(--deck-h) + 12px);
    width: min(312px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: 108px;
  }
}

body.is-mobile[data-orientation="vertical"] .mobile-chat-feed {
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(var(--deck-h) + 12px);
  width: min(312px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: 108px;
}

body.is-mobile[data-orientation="horizontal"] .mobile-chat-feed {
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(max(32px, calc(env(safe-area-inset-bottom) + 20px)) + 134px);
  width: min(300px, 44vw);
  max-height: 64px;
}

.mobile-chat-line {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: rgba(224, 214, 192, 0.88);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.96), 0 0 6px rgba(0, 0, 0, 0.78) !important;
  overflow-wrap: anywhere;
  animation: mobileChatSlideIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.mobile-chat-line.is-fading {
  opacity: 0;
  transform: translateY(-8px);
}

.mobile-chat-sender {
  font-weight: 700;
  color: rgba(212, 168, 64, 0.94);
}

.mobile-chat-sender.is-system {
  color: rgba(242, 193, 78, 0.94);
}

.mobile-chat-sender.is-dungeon {
  color: rgba(224, 87, 74, 0.94);
}

.mobile-chat-sender.is-village {
  color: rgba(110, 191, 106, 0.94);
}

@keyframes mobileChatSlideIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-height: 440px) and (orientation: landscape) {
  .mobile-chat-feed {
    max-height: 64px;
  }
  .mobile-chat-line {
    font-size: 11px;
    line-height: 1.25;
  }
}

.mobile-chat-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-panel);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) max(var(--space-3), env(safe-area-inset-right)) max(var(--space-2), env(safe-area-inset-bottom)) max(var(--space-3), env(safe-area-inset-left));
  background: linear-gradient(180deg, var(--panel-top), var(--bg-deep));
  border-top: 2px solid var(--accent-gold);
  border-bottom: 2px solid var(--border-subtle);
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.6), 0 -6px 20px rgba(0, 0, 0, 0.85);
}

.mobile-chat-bar.keyboard-visible {
  padding-bottom: var(--space-2);
}

.mobile-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  min-height: 44px;
  padding: var(--space-1) var(--space-3);
  background: var(--bg-deep);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.3;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

.mobile-chat-input::placeholder {
  color: var(--text-muted);
}

.mobile-chat-input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 8px var(--accent-gold-glow);
}

.mobile-chat-send-btn {
  flex: 0 0 auto;
  width: auto;
  min-width: 74px;
  min-height: 44px;
  padding: 0 var(--space-4);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
  touch-action: manipulation;
}


