/* ─── Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
}

a { color: #f0c040; }

/* ─── Nav ──────────────────────────────────────────── */
nav {
  background: #16213e;
  padding: 0.75rem 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  border-bottom: 1px solid #0f3460;
}
nav a {
  color: #e0e0e0;
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.95rem;
}
nav a:hover { background: #0f3460; color: #f0c040; }

/* ─── Main ─────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  color: #f0c040;
  margin-bottom: 1rem;
}

/* ─── Hub cards ────────────────────────────────────── */
.hub-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.hub-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 1.25rem;
  text-decoration: none;
  color: #e0e0e0;
  transition: border-color 0.2s, transform 0.15s;
}
.hub-card:hover {
  border-color: #f0c040;
  transform: translateY(-2px);
}
.hub-card h3 { margin: 0 0 0.5rem; color: #f0c040; }
.hub-card p { margin: 0; font-size: 0.9rem; color: #8888aa; }

/* ─── Forms ────────────────────────────────────────── */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.form-row .form-group {
  flex: 1;
  min-width: 140px;
}

input, select, button {
  background: #0f3460;
  border: 1px solid #1a3a6a;
  color: #e0e0e0;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.95rem;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: #f0c040;
}
button {
  background: #f0c040;
  color: #1a1a2e;
  font-weight: bold;
  cursor: pointer;
  border: none;
  padding: 0.6rem 1.5rem;
  width: auto;
  transition: background 0.2s;
}
button:hover { background: #ffd866; }

fieldset {
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 1.5rem;
}
legend {
  color: #f0c040;
  font-weight: bold;
  padding: 0 0.5rem;
}

/* ─── Tables ───────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
th, td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid #0f3460;
}
th {
  background: #16213e;
  color: #f0c040;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tr:hover { background: #16213e; }

/* ─── Next Bear card (single prominent card) ─────────── */
.next-bear-card {
  margin-top: 1.5rem;
  border-radius: 12px;
  overflow: hidden;
  background: #16213e;
  border: 1px solid #0f3460;
}

/* ─── Banner: date + countdown ───────────────────────── */
.bear-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2rem 2.5rem;
  background: linear-gradient(135deg, #16213e 0%, #1e3050 100%);
  border-bottom: 3px solid #f0c040;
}
.bear-date-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.bear-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.bear-date {
  font-size: 2.4rem;
  font-weight: 700;
  color: #f0c040;
}
.bear-countdown {
  font-size: 2.2rem;
  font-weight: 700;
  color: #e0e0e0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.countdown-label {
  font-size: 1rem;
  font-weight: 400;
  color: #888;
}
.countdown-live {
  color: #e63946;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ─── Times bar (divider between traps) ──────────────── */
.bear-times-bar {
  display: flex;
  border-top: 1px solid #0f3460;
  border-bottom: 1px solid #0f3460;
}
.bear-trap-time {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem;
}
.trap2-accent { background: rgba(100, 160, 240, 0.06); }
.trap-num {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.trap1-accent .trap-num { color: #f0a060; }
.trap2-accent .trap-num { color: #80b8f0; }
.trap-clock {
  font-size: 1.2rem;
  font-weight: 600;
  color: #ccc;
  font-variant-numeric: tabular-nums;
}

/* ─── Rosters: stacked vertically ────────────────────── */
.bear-rosters {
  display: flex;
  flex-direction: column;
}



.trap-roster { overflow-x: auto; }
.trap-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid;
}
.trap-roster.trap-1 .trap-header { border-color: rgba(240, 128, 64, 0.3); }
.trap-roster.trap-2 .trap-header { border-color: rgba(100, 160, 240, 0.3); }

.trap-label {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.trap-roster.trap-1 .trap-label { color: #f0a060; }
.trap-roster.trap-2 .trap-label { color: #80b8f0; }

.trap-header .trap-time {
  font-size: 0.75rem;
  color: #666;
}
.trap-header .trap-count {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: #52b788;
  background: rgba(82, 183, 136, 0.1);
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  min-width: 1.5em;
  text-align: center;
}
.trap-empty {
  font-size: 0.85rem;
  color: #444;
  margin: 0.4rem 0;
  font-style: italic;
}

/* ─── Trap roster table ──────────────────────────────── */
.trap-table {
  width: 100%;
  font-size: 0.9rem;
  border-collapse: collapse;
  table-layout: fixed;
}
.trap-table th {
  text-align: left;
  padding: 0.3rem 0.4rem;
  font-size: 0.72rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #0f3460;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trap-table th:first-child { width: auto; }
.trap-table th:nth-child(2) { width: 28%; }
.trap-table th:nth-child(3) { width: 14%; }
.trap-table th:nth-child(4) { width: 22%; }
.trap-table th:nth-child(5) { width: 115px; }
.trap-table td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trap-row:hover { background: #1e2d4a; }
.trap-row.rally-lead { background: rgba(240, 192, 64, 0.06); }

.troops-col { font-variant-numeric: tabular-nums; }
.formation { color: #555; font-size: 0.75rem; }
.hero-lv { color: #666; font-size: 0.75rem; }
.hero-col { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.march-col { font-variant-numeric: tabular-nums; }

.wave-col { overflow: visible; }

.rally-badge {
  color: #f0c040;
  font-size: 0.75rem;
  vertical-align: super;
}

/* ─── Admin controls ─────────────────────────────────── */
.admin-controls {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}
.wave-select {
  padding: 0.12rem 0.25rem;
  font-size: 0.7rem;
  background: #1a1a2e;
  color: #ccc;
  border: 1px solid #0f3460;
  border-radius: 3px;
  width: 70px;
}
.rl-toggle {
  padding: 0.12rem 0.4rem;
  font-size: 0.65rem;
  background: #1a1a2e;
  color: #ccc;
  border: 1px solid #0f3460;
  border-radius: 3px;
  cursor: pointer;
  font-weight: 600;
}
.rl-toggle.active {
  background: #f0c040;
  color: #1a1a2e;
  border-color: #f0c040;
}

/* ─── Signup row ─────────────────────────────────────── */
.bear-signup {
  border-top: 1px solid #0f3460;
  padding: 0.85rem 1.25rem;
  background: #121a2e;
}
.signup-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.signup-row select,
.signup-row input {
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
}
.signup-row button {
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.btn-remove {
  background: transparent !important;
  color: #e63946 !important;
  border: 1px solid #e63946 !important;
  padding: 0.5rem 1rem !important;
  font-size: 0.85rem !important;
}
.btn-remove:hover {
  background: rgba(230, 57, 70, 0.1) !important;
}
/* ─── Feedback ───────────────────────────────────────── */
#feedback { margin-top: 1rem; }
.feedback-success {
  padding: 0.75rem;
  background: #1b4332;
  border: 1px solid #52b788;
  border-radius: 4px;
  color: #95d5b2;
}
.feedback-error {
  padding: 0.75rem;
  background: #4a1515;
  border: 1px solid #e63946;
  border-radius: 4px;
  color: #ffb3b3;
}

/* ─── Profile card ──────────────────────────────────── */
.profile-card {
  margin-top: 1.5rem;
  border-radius: 12px;
  overflow: hidden;
  background: #16213e;
  border: 1px solid #0f3460;
}
.profile-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  background: linear-gradient(135deg, #16213e 0%, #1e3050 100%);
  border-bottom: 3px solid #f0c040;
  gap: 1.5rem;
}
.profile-title-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}
.profile-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.profile-username input {
  font-size: 1.8rem;
  font-weight: 700;
  color: #f0c040;
  background: transparent;
  border: none;
  padding: 0;
  width: auto;
  min-width: 200px;
}
.profile-username input:focus { outline: none; }
.username-form {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}
.username-form input {
  width: 180px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}
.username-form button {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.profile-body {
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.profile-section {
  background: #1a1a2e;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  border-left: 3px solid #0f3460;
}
.section-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: #f0c040;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
}
.section-hint {
  font-size: 0.8rem;
  color: #666;
  margin: 0 0 0.75rem 0;
}

.profile-save {
  border-top: 1px solid #0f3460;
  padding: 0.85rem 1.5rem;
  background: #121a2e;
  display: flex;
  justify-content: flex-end;
}
.profile-save button {
  padding: 0.6rem 2rem;
  font-size: 0.95rem;
}
.allocator-ratio { padding: 0.5rem 0.75rem; font-size: 0.8rem; color: #8888aa; text-transform: uppercase; letter-spacing: 0.03em; }
.alloc-col { font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.nav-right { margin-left: auto !important; }
.fieldset-hint { font-size: 0.85rem; opacity: 0.7; margin: 0 0 0.5rem 0; }

/* ─── Allocator per-leader table ─────────────────────── */
.alloc-info {
  max-width: 720px;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: rgba(240, 192, 64, 0.06);
  border-left: 3px solid rgba(240, 192, 64, 0.3);
  font-size: 0.82rem;
  color: #aaaacc;
  line-height: 1.5;
}
.alloc-info strong { color: #d4c080; }
.alloc-info em { color: #c0c0d0; }

.alloc-capacity {
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  border-radius: 4px;
}
.alloc-capacity-ok { background: rgba(80, 200, 120, 0.12); color: #80c880; }
.alloc-capacity-warn { background: rgba(200, 180, 80, 0.12); color: #c8b850; }
.alloc-capacity-tight { background: rgba(220, 80, 80, 0.12); color: #d08080; }

.alloc-table { min-width: 0; }
.alloc-table th { white-space: nowrap; font-size: 0.7rem; padding: 0.25rem 0.3rem; }
.alloc-table td { padding: 0.25rem 0.3rem; font-size: 0.82rem; }
.alloc-table th:first-child,
.alloc-table th:nth-child(2),
.alloc-table th:nth-child(3),
.alloc-table th:nth-child(4),
.alloc-table th:nth-child(5) { width: auto; }

.alloc-leader-col {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  white-space: nowrap;
}
.alloc-leader-col .alloc-k { font-size: 0.63rem; color: #8888aa; display: block; }
.alloc-leader-col .alloc-cap { font-size: 0.6rem; color: #666688; display: block; }
.alloc-leader-col .alloc-dmg { font-size: 0.72rem; color: #f0c040; display: block; }

/* ─── Homepage ─────────────────────────────────────── */
.homepage {
  text-align: center;
}

.homepage-hero {
  position: relative;
  display: inline-block;
}

.homepage-title {
  font-size: clamp(3.5rem, 10vw, 7rem);
  color: #f0c040;
  text-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
  letter-spacing: 0.05em;
  margin-bottom: 0;
}

.homepage-subtitle {
  font-size: 1.2rem;
  color: #8888aa;
  margin-bottom: 2rem;
}

/* ─── Splash text (Minecraft-style) ────────────────── */
.splash-text {
  position: absolute;
  top: 0.5rem;
  right: -1rem;
  color: #ffff55;
  font-size: 0.95rem;
  font-weight: bold;
  transform: rotate(-18deg);
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(255, 255, 85, 0.5);
  opacity: 0;
  animation: splashIn 0.6s ease-out forwards,
             splashFloat 2s 0.6s ease-in-out infinite;
}

@keyframes splashIn {
  0%   { opacity: 0; transform: rotate(-18deg) scale(0.3); }
  70%  { opacity: 1; transform: rotate(-18deg) scale(1.15); }
  100% { opacity: 1; transform: rotate(-18deg) scale(1); }
}

@keyframes splashFloat {
  0%, 100% { transform: rotate(-18deg) translateY(0); }
  50%      { transform: rotate(-18deg) translateY(-3px); }
}

/* ─── Joke admin table ─────────────────────────────── */
.joke-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}
.joke-table th, .joke-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #0f3460;
  font-size: 0.9rem;
}
.joke-table th {
  color: #8888aa;
  font-size: 0.8rem;
  text-transform: uppercase;
}
.btn-delete {
  background: none;
  border: 1px solid #cc3333;
  color: #cc3333;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-delete:hover {
  background: #cc3333;
  color: #fff;
}

/* ═══════════════════════════════════════════════════════
   Mobile & Polish
   ═══════════════════════════════════════════════════════ */

/* ─── Global polish ─────────────────────────────────── */
html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: rgba(240, 192, 64, 0.15);
}

::selection {
  background: rgba(240, 192, 64, 0.25);
  color: #fff;
}

/* Dark scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #1a1a2e; }
::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #1a4a80; }

/* ─── Touch-friendly tap targets ────────────────────── */
nav a,
.hub-card,
button,
.btn-delete,
.btn-remove,
.rl-toggle {
  min-height: 44px;
  display: flex;
  align-items: center;
}
button, .btn-delete, .btn-remove { justify-content: center; }
nav a { min-height: 36px; }

/* ─── Mobile: 640px and below ───────────────────────── */
@media (max-width: 640px) {
  /* Safe area */
  body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  /* Tighter main */
  main {
    padding: 1rem 0.75rem;
  }

  /* Nav: horizontal scroll with hidden bar */
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }
  nav::-webkit-scrollbar { display: none; }
  nav a {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.85rem;
    padding: 0.35rem 0.6rem;
  }

  /* Full-width hub cards */
  .hub-cards {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
  }

  /* Stack form rows */
  .form-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  .form-row .form-group {
    min-width: 0;
  }

  /* Full-width buttons */
  button { width: 100%; }

  /* Stack banner vertically */
  .bear-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 1.25rem 1rem;
  }
  .bear-date { font-size: 1.8rem; }
  .bear-countdown {
    font-size: 1.6rem;
    text-align: left;
  }
  .countdown-label { font-size: 0.9rem; }

  /* Stack times bar */
  .bear-times-bar {
    flex-direction: column;
  }

  /* Scrollable trap tables */
  .trap-roster {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .trap-table {
    table-layout: auto;
    min-width: 520px;
    font-size: 0.82rem;
  }
  .trap-table th { font-size: 0.68rem; padding: 0.25rem 0.3rem; }
  .trap-table td { padding: 0.25rem 0.3rem; font-size: 0.78rem; }
  .trap-table th:nth-child(2) { width: auto; }
  .trap-table th:nth-child(3) { width: auto; }
  .trap-table th:nth-child(4) { width: auto; }
  .trap-table th:nth-child(5) { width: auto; min-width: 100px; }

  /* Stack signup row */
  .signup-row {
    flex-direction: column;
    align-items: stretch;
  }
  .signup-row select,
  .signup-row input { width: 100%; }
  .bear-signup { padding: 0.75rem 0.75rem; }

  /* Stack profile banner */
  .profile-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 1rem;
    gap: 0.75rem;
  }
  .profile-username input {
    font-size: 1.4rem;
    min-width: 0;
    width: 100%;
  }
  .username-form {
    width: 100%;
  }
  .username-form input {
    flex: 1;
    width: auto;
  }
  .profile-section { padding: 0.75rem 0.75rem; }
  .profile-body { padding: 0.25rem; gap: 0.25rem; }
  .profile-save { padding: 0.6rem 0.75rem; }

  /* Homepage */
  .homepage-title { font-size: clamp(2.2rem, 14vw, 4rem); }
  .homepage-subtitle { font-size: 1rem; margin-bottom: 1.25rem; }
  .splash-text {
    font-size: 0.8rem;
    right: -0.5rem;
    top: 0.25rem;
  }

  /* Allocator */
  .alloc-info { font-size: 0.78rem; padding: 0.6rem 0.75rem; }
  .alloc-table { min-width: 600px; }
  .alloc-table th { font-size: 0.65rem; }
  .alloc-table td { font-size: 0.76rem; }

  /* Chunkier tap targets on mobile */
  input, select {
    padding: 0.6rem 0.75rem;
  }
  .wave-select {
    padding: 0.2rem 0.3rem;
    font-size: 0.75rem;
  }
  .rl-toggle {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
  }
}
