/* ===== Reset / base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}
input, select, button { font: inherit; }
button { cursor: pointer; }

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.topbar-title {
  font-size: 1.1rem; font-weight: 700;
  color: #e94560;
  margin-right: auto;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-sep {
  width: 1px; height: 20px;
  background: #0f3460;
  margin: 0 4px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 6px; border: 1px solid transparent;
  font-size: 0.875rem; font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: #e94560; color: #fff; border-color: #e94560; }
.btn-primary:hover { background: #c73652; }
.btn-ghost { background: transparent; color: #e0e0e0; border-color: #0f3460; }
.btn-ghost:hover { background: #0f3460; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-close {
  background: none; border: none; color: #999;
  font-size: 1.4rem; line-height: 1; padding: 4px 8px;
}
.btn-close:hover { color: #e94560; }

.cart-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #e94560; color: #fff; font-size: 0.75rem; font-weight: 700;
}

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5);
}

/* ===== Drawers ===== */
.drawer {
  position: fixed; top: 0; bottom: 0; z-index: 300;
  width: min(340px, 90vw);
  background: #16213e;
  border: 1px solid #0f3460;
  display: flex; flex-direction: column;
  transform: translateX(-110%);
  transition: transform .25s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-left { left: 0; }
.drawer-right { right: 0; transform: translateX(110%); }
.drawer-right.open { transform: translateX(0); }

.drawer-inner {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; height: 100%; overflow-y: auto;
}
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 8px; border-bottom: 1px solid #0f3460;
}
.drawer-header h2 { font-size: 1rem; color: #e94560; }

/* ===== Filters ===== */
.filter-label {
  display: flex; justify-content: space-between;
  font-size: 0.8rem; font-weight: 600; color: #aaa;
  text-transform: uppercase; letter-spacing: .05em;
  margin-top: 4px;
}
.filter-input {
  width: 100%; padding: 7px 10px; border-radius: 5px;
  border: 1px solid #0f3460; background: #0d1b2a; color: #e0e0e0;
  font-size: 0.9rem;
}
.filter-input:focus { outline: 2px solid #e94560; border-color: #e94560; }
.filter-group {
  border: 1px solid #0f3460; border-radius: 6px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 5px;
}
.filter-group legend {
  font-size: 0.75rem; font-weight: 600; color: #aaa;
  text-transform: uppercase; letter-spacing: .05em; padding: 0 4px;
}
.filter-group label {
  display: flex; align-items: center; gap: 8px; font-size: 0.9rem; cursor: pointer;
}
.filter-checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.range-row { display: flex; gap: 8px; }
.range-row input[type=range] { flex: 1; accent-color: #e94560; }
.range-readout { color: #e94560; font-weight: 600; font-size: 0.8rem; }
.filter-footer { margin-top: auto; padding-top: 8px; border-top: 1px solid #0f3460; }

/* ===== Cart ===== */
.cart-items { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.cart-empty { color: #666; font-size: 0.9rem; text-align: center; margin-top: 20px; }
.cart-item {
  display: flex; align-items: center; gap: 8px;
  background: #0d1b2a; border: 1px solid #0f3460; border-radius: 6px;
  padding: 8px 10px;
}
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-item-meta { font-size: 0.78rem; color: #aaa; }
.cart-qty {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; border-radius: 11px;
  background: #0f3460; color: #e0e0e0; font-size: 0.78rem; font-weight: 700;
}
.cart-remove {
  background: none; border: none; color: #666; font-size: 1.1rem; padding: 0 4px;
}
.cart-remove:hover { color: #e94560; }
.cart-footer {
  border-top: 1px solid #0f3460; padding-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.cart-total { font-size: 0.9rem; color: #aaa; text-align: right; }
.cart-total strong { color: #e94560; }

/* ===== Main / results ===== */
.main {
  padding: 16px;
  max-width: 1400px; margin: 0 auto;
}
.results-header {
  font-size: 0.85rem; color: #aaa;
  margin-bottom: 12px;
}

/* ===== Results grid ===== */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

/* ===== Unit tile ===== */
.unit-tile {
  background: #16213e; border: 1px solid #0f3460; border-radius: 8px;
  padding: 12px; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s;
}
.unit-tile:hover { border-color: #e94560; }
.unit-tile.in-cart { border-color: #4caf50; }

/* tile-name is defined below with the info-button layout */
.tile-meta {
  display: flex; gap: 6px; flex-wrap: wrap;
  font-size: 0.78rem;
}
.tag {
  padding: 2px 7px; border-radius: 10px; font-size: 0.75rem;
  font-weight: 500; white-space: nowrap;
}
.tag-type { background: #0f3460; color: #a0c4ff; }
.tag-tech-is { background: #1a3a2a; color: #80c9a0; }
.tag-tech-clan { background: #3a1a1a; color: #c98080; }
.tag-era { background: #2a2a0f; color: #c9b880; }

.tile-stats {
  display: flex; gap: 12px; font-size: 0.82rem; color: #bbb;
  border-top: 1px solid #0f3460; padding-top: 6px; margin-top: 2px;
}
.tile-stat { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tile-stat-val { font-weight: 700; color: #e0e0e0; }
.tile-stat-lbl { font-size: 0.68rem; color: #666; text-transform: uppercase; letter-spacing: .05em; }

.tile-points {
  font-size: 0.82rem; color: #aaa;
}
.tile-points strong { color: #e94560; }

.tile-footer { margin-top: auto; }
.btn-add {
  width: 100%; padding: 6px; border-radius: 5px;
  border: 1px solid #0f3460; background: transparent; color: #e0e0e0;
  font-size: 0.83rem; display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s;
}
.btn-add:hover { background: #0f3460; }
.btn-add.added { border-color: #4caf50; color: #4caf50; }

/* ===== Load more ===== */
.load-more-wrap { text-align: center; margin-top: 20px; }

/* ===== Rule tooltip ===== */
.rule-tooltip {
  position: fixed; z-index: 500;
  max-width: 280px; padding: 10px 14px;
  background: #0d1b2a; border: 1px solid #e94560; border-radius: 7px;
  font-size: 0.85rem; color: #e0e0e0;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  pointer-events: none;
}
.rule-tooltip-name { font-weight: 700; color: #e94560; margin-bottom: 4px; }
.rule-tooltip-li { font-style: italic; color: #aaa; }

/* ===== Skeleton loader ===== */
.skeleton {
  background: linear-gradient(90deg, #16213e 25%, #1e2d4e 50%, #16213e 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===== Tile name row with info button ===== */
.tile-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.95rem; font-weight: 700; color: #e0e0e0;
  min-width: 0;
}
.tile-name-text {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-info {
  flex-shrink: 0;
  background: none; border: none; padding: 0;
  color: #4a8fc4; font-size: 1rem; line-height: 1;
  cursor: pointer; opacity: 0.7;
  transition: opacity .15s, color .15s;
}
.btn-info:hover { opacity: 1; color: #7ec8e3; }

/* ===== Unit card modal ===== */
body.modal-open { overflow: hidden; }

.card-modal-backdrop[hidden],
.card-modal[hidden] { display: none !important; }

.card-modal-backdrop {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.7);
}
.card-modal {
  position: fixed; z-index: 401;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(880px, 95vw);
  max-height: 90vh;
  background: #0d1b2a;
  border: 1px solid #0f3460;
  border-radius: 10px;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.7);
  overflow: hidden;
}
.card-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #0f3460;
  background: #16213e;
  flex-shrink: 0;
}
.card-modal-title {
  font-size: 0.95rem; font-weight: 700; color: #e94560;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-modal-body {
  overflow-y: auto; padding: 16px;
  flex: 1;
}
.card-modal-frame {
  width: 100%; height: 100%; min-height: 70vh;
  border: 0; background: #fff; display: block;
}
.card-modal-loading {
  color: #666; font-size: 0.9rem; text-align: center; padding: 40px 0;
}
.card-modal-error {
  color: #e94560; font-size: 0.85rem; padding: 20px 0;
}

/* ===== Info modal (Rules / How to Play / Disclaimer) ===== */
.info-modal { width: min(820px, 95vw); max-height: 90vh; }
.info-modal-body { padding: 20px 28px; color: #d8d8e8; line-height: 1.55; }
.info-modal-body .info-page-title {
  font-size: 1.5rem; color: #e94560; margin-bottom: 16px;
  border-bottom: 1px solid #0f3460; padding-bottom: 8px;
}
.info-modal-body h1,
.info-modal-body h2,
.info-modal-body h3,
.info-modal-body h4 {
  color: #f5b14a; margin: 18px 0 8px;
}
.info-modal-body h2 { font-size: 1.2rem; }
.info-modal-body h3 { font-size: 1.05rem; color: #7ec8e3; }
.info-modal-body h4 { font-size: 0.95rem; color: #b9c6d4; }
.info-modal-body p { margin: 8px 0; }
.info-modal-body ul,
.info-modal-body ol { margin: 8px 0 8px 22px; }
.info-modal-body li { margin: 4px 0; }
.info-modal-body strong { color: #f0e6d2; }
.info-modal-body a { color: #7ec8e3; }
.info-modal-body code {
  background: #0f1c2e; padding: 1px 5px; border-radius: 3px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.85em;
}
.info-modal-body hr {
  border: 0; border-top: 1px solid #0f3460; margin: 16px 0;
}
