* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Arial, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, #1e1030 0%, #0d1020 40%, #060810 100%);
  color: #e8edf5;
  min-height: 100vh;
  /* Safe areas for iOS notch and Android cutout */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

h1, h2, h3 {
  font-family: 'Cinzel', serif;
  margin-top: 0;
}

h3, p {
  margin-top: 0;
}

h1 { margin-bottom: 4px; }
h2 { margin-bottom: 10px; }
h3 { margin-bottom: 6px; font-size: 15px; letter-spacing: 0.4px; }

.hidden {
  display: none !important;
}

/* ── App shell ── */
.app {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 16px 14px;
  /* Extra bottom padding accounts for nav + home bar */
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
}

.create-profile {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.profile-create-card {
  max-width: 430px;
  width: 100%;
}

/* ── Inputs ── */
.profile-create-card input,
.chat-input-row input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(5, 8, 18, 0.9);
  color: white;
  border-radius: 12px;
  padding: 13px;
  font-size: 16px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.profile-create-card input:focus,
.chat-input-row input:focus {
  outline: none;
  border-color: rgba(250, 204, 21, 0.4);
}

/* ── Starter stat selector ── */
.starter-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(8, 12, 24, 0.85);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.starter-stat div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.starter-stat button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.error-text {
  color: #f87171;
  margin-bottom: 0;
  font-size: 14px;
}

/* ── Mini Chat ── */
.mini-chat {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  padding: 6px 14px 4px;
  z-index: 50;
  cursor: pointer;
  pointer-events: auto;
}

.mini-chat-msg {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.65);
  padding: 1px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.95);
  line-height: 1.5;
}

.mini-chat-msg strong {
  color: #facc15;
}

.topbar p,
.muted {
  color: #6b7a99;
  font-size: 13px;
}

/* ── Cards ── */
.card,
.modal {
  background: rgba(10, 15, 28, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* ── Action / combat log card ── */
.action-card {
  position: sticky;
  top: 10px;
  z-index: 20;
  backdrop-filter: blur(16px);
  background: rgba(6, 10, 22, 0.96);
  border-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(99,102,241,0.1);
}

.action-card h2 {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #4b5473;
  margin-bottom: 8px;
}

#lastAction {
  background: rgba(5, 8, 18, 0.7);
  border-left: 3px solid #6366f1;
  padding: 11px 14px;
  border-radius: 10px;
  line-height: 1.65;
  font-size: 14px;
  color: #c8d4f0;
  min-height: 40px;
}

/* ── Hero card ── */
.hero-card {
  background: linear-gradient(145deg, rgba(18, 12, 36, 0.99) 0%, rgba(8, 12, 26, 0.99) 100%);
  border-color: rgba(250, 204, 21, 0.2);
  box-shadow: 0 6px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(250,204,21,0.06);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hero-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.hero-avatar {
  font-size: 44px;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 8px rgba(0,0,0,0.7));
}

.hero-info h2 {
  font-size: 22px;
  color: #facc15;
  margin-bottom: 3px;
  letter-spacing: 0.6px;
  text-shadow: 0 0 14px rgba(250,204,21,0.25);
}

.hero-info .muted {
  font-size: 12px;
}

/* ── Quick stats pills ── */
.quick-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 13px;
}

.quick-stats span {
  background: rgba(8, 12, 26, 0.9);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

/* ── Hero HP/XP bars ── */
.hero-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.bar-label {
  font-size: 10px;
  font-weight: 800;
  color: #4b5473;
  width: 20px;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.bar-track {
  flex: 1;
  height: 10px;
  background: rgba(5, 8, 18, 0.9);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.04);
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease, background 0.35s ease;
}

#hpFill {
  background: linear-gradient(90deg, #16a34a, #22c55e);
  width: 100%;
}

.xp-fill {
  background: linear-gradient(90deg, #4f46e5, #818cf8);
  width: 0%;
}

.stat-footer {
  font-size: 12px;
  color: #4b5473;
  margin: 0;
}

/* ── Deprecated single-bar styles (boss HP bars in modals) ── */
.xp-bar,
.hp-bar {
  width: 100%;
  height: 8px;
  background: rgba(5,8,18,0.9);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}

.hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #dc2626, #f97316);
}

/* ── Buttons ── */
button {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
}

button:hover {
  filter: brightness(1.18);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

button.active {
  background: linear-gradient(135deg, #15803d, #16a34a);
  box-shadow: 0 0 12px rgba(22, 163, 74, 0.3);
}

.secondary {
  background: rgba(30, 42, 72, 0.9);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-danger {
  background: linear-gradient(135deg, #991b1b, #b91c1c);
}

/* ── Auto button grid ── */
.auto-grid,
.boss-actions,
.profile-actions,
.chat-input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.chat-input-row {
  grid-template-columns: 1fr 90px;
  margin-top: 10px;
}

/* ── Section dividers ── */
.section-label {
  font-family: 'Cinzel', serif;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #3b4466;
  margin: 18px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255,255,255,0.07), transparent);
}

/* ── Leaderboard ── */
#leaderboard,
#bossList,
#shopList {
  display: grid;
  gap: 8px;
}

.leaderboard-row {
  background: rgba(8, 12, 22, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: 14px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.lb-top {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
}

.lb-stats {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: #8a9bbf;
  padding-left: 4px;
}

.lb-stats span { font-weight: 600; }

.lb-hpbar {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
}

.leaderboard-row:hover {
  border-color: rgba(255,255,255,0.12);
}

.leaderboard-row.you {
  background: linear-gradient(90deg, rgba(10, 28, 18, 0.95), rgba(8, 12, 22, 0.95));
  border-color: rgba(34, 197, 94, 0.3);
}

.rank {
  font-size: 18px;
  font-weight: 900;
  font-family: 'Cinzel', serif;
  text-align: center;
}

.rank.rank-1 { color: #facc15; text-shadow: 0 0 10px rgba(250,204,21,0.4); }
.rank.rank-2 { color: #94a3b8; text-shadow: 0 0 8px rgba(148,163,184,0.3); }
.rank.rank-3 { color: #c2773a; text-shadow: 0 0 8px rgba(194,119,58,0.3); }
.rank.rank-other { color: #3b4466; }

.name {
  font-weight: 700;
  font-size: 14px;
  color: #e2e8f0;
}

.mini-stats {
  color: #4b5a7a;
  font-size: 12px;
  margin-top: 3px;
}

/* ── Boss cards ── */
.boss-card {
  background: linear-gradient(145deg, rgba(22, 6, 6, 0.97), rgba(10, 12, 24, 0.97));
  border: 1px solid rgba(220, 38, 38, 0.18);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,50,50,0.04);
}

.boss-card:hover {
  border-color: rgba(220, 38, 38, 0.35);
}

.boss-card h3 {
  color: #fca5a5;
  font-size: 15px;
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}

/* ── Shop cards ── */
.shop-card {
  background: linear-gradient(145deg, rgba(8, 14, 32, 0.97), rgba(10, 16, 36, 0.97));
  border: 1px solid rgba(99, 130, 255, 0.12);
  border-radius: 14px;
  padding: 14px;
  transition: border-color 0.2s;
}

.shop-card:hover {
  border-color: rgba(99, 130, 255, 0.22);
}

.leaderboard-info {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── Requirement text ── */
.requirement-ok {
  color: #22c55e;
  font-weight: 700;
  font-size: 13px;
}

.requirement-bad {
  color: #f87171;
  font-weight: 700;
  font-size: 13px;
}

/* ── Badge ── */
.badge {
  background: rgba(22, 38, 80, 0.9);
  border: 1px solid rgba(59, 90, 180, 0.4);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #93c5fd;
}

/* ── Card header ── */
.card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.card-header h2 {
  margin: 0;
}

/* ── Overlays ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal {
  width: min(680px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  border-radius: 22px 22px 0 0;
  border-bottom: none;
  padding: 20px 18px 36px;
  animation: slideUp 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0.6; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal h2 {
  font-size: 18px;
  letter-spacing: 1px;
  color: #facc15;
  margin-bottom: 16px;
  padding-right: 40px;
}

.close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: rgba(30, 42, 72, 0.9);
  font-size: 22px;
  line-height: 1;
  color: #8a9bbf;
  border: 1px solid rgba(255,255,255,0.08);
}

/* ── Bottom navigation ── */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* Extend behind home bar on iPhone X+ */
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(72px + env(safe-area-inset-bottom));
  background: rgba(4, 6, 14, 0.98);
  backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: stretch;
  z-index: 60;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 4px;
  color: #3b4466;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
  touch-action: manipulation;
  letter-spacing: 0.3px;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.03);
  color: #8a9bbf;
  filter: none;
}

.nav-tab:active {
  background: rgba(255, 255, 255, 0.06);
  transform: none;
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
  display: block;
}

.nav-label {
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.nav-badge {
  position: absolute;
  top: 5px;
  right: calc(50% - 20px);
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(4, 6, 14, 0.98);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

/* ── Profile grid ── */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.profile-grid div {
  background: rgba(5, 8, 18, 0.9);
  border: 1px solid rgba(255,255,255,0.06);
  padding: 12px 10px;
  border-radius: 12px;
  text-align: center;
}

.profile-grid span {
  display: block;
  color: #4b5a7a;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
}

.profile-grid strong {
  font-size: 19px;
}

.damage-list p {
  margin: 5px 0;
  color: #93c5fd;
  font-size: 13px;
}

/* ── Chat ── */
#chatMessages {
  display: grid;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.chat-message {
  background: rgba(5, 8, 18, 0.8);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 10px 12px;
}

.chat-name {
  color: #93c5fd;
  font-weight: 700;
  font-size: 13px;
}

/* ── Tutorial ── */
.tutorial-card {
  text-align: center;
}

.tutorial-card h2 {
  font-size: 22px;
  margin-bottom: 14px;
}

.tutorial-card p {
  line-height: 1.75;
  color: #b0bcd4;
}

.tutorial-buttons {
  margin-top: 22px;
}

.tutorial-buttons button {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  letter-spacing: 0.5px;
}

/* ── Pulse animation (boss auto active) ── */
@keyframes bossPulse {
  0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  70%  { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* ── Mobile ── */
@media (max-width: 720px) {
  .card-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }

  .auto-grid,
  .boss-actions,
  .profile-actions,
  .chat-input-row {
    grid-template-columns: 1fr;
  }

  .lb-top {
    grid-template-columns: 40px 1fr auto;
  }
}
