/* ============================================================
   ABI Guide — Weapon Builder (builder.html)
   Reuses global tokens + components from style.css
============================================================ */

/* Ensure [hidden] always wins over component display rules */
[hidden] { display: none !important; }

/* --- App-shell: full-height left rail + main content --- */
.builder-page {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - var(--nav-h));
}
.bx-rail {
  flex: 0 0 260px;
  background: var(--surface-el);
  border-right: 1px solid var(--border);
}
.bx-rail__inner {
  position: sticky;
  top: var(--nav-h);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
}
.builder-page.is-create .bx-rail { display: none; }

.builder-main {
  flex: 1;
  min-width: 0;
  padding-block: var(--sp-10) var(--sp-24);
}
.builder-main__inner {
  max-width: 1400px;
  padding-inline: clamp(1.5rem, 4vw, 3rem);
}

/* --- Tabs ---------------------------------- */
.bx-tabs {
  display: flex;
  gap: var(--sp-2);
  margin: var(--sp-6) 0 var(--sp-8);
  border-bottom: 1px solid var(--border);
}
.bx-tab {
  position: relative;
  font-family: var(--font-hd);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  padding: 0.6rem 1.1rem 0.75rem;
  transition: color 0.15s;
}
.bx-tab::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--amber);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s var(--ease-out);
}
.bx-tab:hover { color: var(--ink); }
.bx-tab.is-active { color: var(--amber); }
.bx-tab.is-active::after { transform: scaleX(1); }

.bx-panel { animation: bx-fade 0.35s var(--ease-out); }
.bx-panel[hidden] { display: none; }
@keyframes bx-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* --- Weapon search (top of rail) ----------- */
.bx-search { position: relative; }
.bx-search__icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--ink-faint);
  pointer-events: none;
}
.bx-search input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--r);
  padding: 0.5rem 0.7rem 0.5rem 2.1rem;
  transition: border-color 0.15s;
}
.bx-search input::placeholder { color: var(--ink-faint); }
.bx-search input:focus { outline: none; border-color: var(--amber); }
.bx-search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: var(--z-drop);
  background: var(--surface-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--r-md);
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 10px 30px oklch(0 0 0 / 0.5);
}
.bx-search__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.bx-search__item:last-child { border-bottom: none; }
.bx-search__item:hover { background: var(--amber-bg); }
.bx-search__name {
  font-family: var(--font-hd);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--amber);
}
.bx-search__type {
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.bx-search__empty {
  padding: 0.6rem 0.7rem;
  font-size: 0.82rem;
  color: var(--ink-faint);
}

/* --- Filter rail contents ------------------ */
.bx-filters__hd {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.bx-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.bx-field__label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
}

/* Weapon checkbox list (unrolls under the type selector) */
.bx-weaponlist {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-bright) transparent;
}
.bx-weaponlist .checkrow { padding: 0.28rem 0; }
.bx-weaponlist .checkrow__text { color: var(--amber); }
.bx-weaponlist .checkrow:hover .checkrow__text,
.bx-weaponlist .checkrow input:checked ~ .checkrow__text { color: var(--amber-bright); }
.bx-weaponlist::-webkit-scrollbar { width: 8px; }
.bx-weaponlist::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 4px; }

/* --- Cards grid ---------------------------- */
.bx-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--sp-5);
}
.bx-status {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9rem;
  padding: var(--sp-8) 0;
}
.bx-loadmore-wrap { display: flex; justify-content: center; padding: var(--sp-6) 0 0; }

/* --- Build card ---------------------------- */
.bx-card {
  display: flex;
  flex-direction: column;
  background: var(--surface-el);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s var(--ease-out);
}
.bx-card:hover { border-color: oklch(0.68 0.155 68 / 0.40); transform: translateY(-2px); }

/* Screenshot — the hero of the card */
.bx-card__shot {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--surface-raised);
  overflow: hidden;
}
.bx-card__shot-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.bx-card__shot::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, oklch(0.06 0.01 252 / 0.92) 0%, transparent 45%);
  pointer-events: none;
}
/* Placeholder when no screenshot */
.bx-card__shot-ph {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-family: var(--font-hd);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: oklch(0.68 0.155 68 / 0.20);
  text-transform: uppercase;
}
.bx-card__shot.is-empty {
  background:
    repeating-linear-gradient(-45deg, transparent 0 10px, oklch(0.68 0.155 68 / 0.03) 10px 11px),
    var(--surface-raised);
}
.bx-card__shot.is-empty .bx-card__shot-ph { display: flex; }
.bx-card__type-badge {
  position: absolute;
  top: var(--sp-3);
  left: var(--sp-3);
  z-index: 1;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  background: oklch(0.06 0.01 252 / 0.7);
  border: 1px solid var(--border-bright);
  border-radius: var(--r);
  padding: 2px 7px;
  backdrop-filter: blur(4px);
}
.bx-card__shot-foot {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
}
.bx-card__weapon {
  font-family: var(--font-hd);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.bx-card__price {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--amber-bright);
  background: oklch(0.06 0.01 252 / 0.72);
  border: 1px solid oklch(0.68 0.155 68 / 0.28);
  border-radius: var(--r);
  padding: 2px 8px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.bx-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  flex: 1;
}

/* Stats — compact pills, no bars */
.bx-card__stats2 {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.bx-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 2px 7px;
}
.bx-pill em {
  font-style: normal;
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.bx-pill--vel { border-color: oklch(0.68 0.155 68 / 0.30); }
.bx-pill--vel { color: var(--amber-bright); }
.bx-pill--vel i { font-style: normal; font-size: 0.56rem; color: var(--ink-faint); margin-left: 2px; }

/* Build code */
.bx-code {
  display: flex;
  align-items: stretch;
  gap: var(--sp-2);
}
.bx-code__val {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 0.4rem 0.6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}
.bx-code__copy {
  flex-shrink: 0;
  font-family: var(--font-hd);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid oklch(0.68 0.155 68 / 0.30);
  border-radius: var(--r);
  padding: 0 0.75rem;
  transition: background 0.15s, color 0.15s;
}
.bx-code__copy:hover { background: var(--amber); color: oklch(0.12 0.014 252); }

.bx-card__note {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.bx-card__foot {
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.bx-card__meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bx-card__author {
  font-family: var(--font-hd);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bx-card__date {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-faint);
}

/* Vote */
.bx-vote {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 4px;
}
.bx-vote__btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.7rem;
  color: var(--ink-muted);
  transition: color 0.15s, background 0.15s;
}
.bx-vote__btn--up:hover:not(:disabled)   { color: var(--amber-bright); background: var(--amber-bg); }
.bx-vote__btn--down:hover:not(:disabled) { color: var(--red); background: var(--red-bg); }
.bx-vote__btn:disabled { opacity: 0.45; cursor: not-allowed; }
.bx-vote.is-voted { opacity: 0.75; }
.bx-vote__score {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink);
  min-width: 1.5ch;
  text-align: center;
}

/* --- Create form --------------------------- */
.bx-form {
  max-width: 720px;
  background: var(--surface-el);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-6);
}
.bx-form__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-5);
}
.bx-form__field { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.bx-form__field--full { grid-column: 1 / -1; }
.bx-form__label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink);
}
.bx-form__label .req { color: var(--amber); }
.bx-hint { color: var(--ink-faint); text-transform: none; letter-spacing: 0; }

.bx-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--r);
  padding: 0.55rem 0.7rem;
  transition: border-color 0.15s;
}
.bx-input::placeholder { color: var(--ink-faint); }
.bx-input:focus { outline: none; border-color: var(--amber); }
.bx-textarea { resize: vertical; min-height: 64px; line-height: 1.5; }

/* Screenshot upload field */
.bx-file {
  position: relative;
  display: block;
  border: 1px dashed var(--border-bright);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}
.bx-file:hover { border-color: var(--amber-dim); background: var(--amber-bg); }
.bx-file.has-image { border-style: solid; border-color: var(--border-bright); }
.bx-file__prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-6) var(--sp-4);
  color: var(--ink-muted);
  font-family: var(--font-hd);
  font-size: 0.9rem;
}
.bx-file__prompt svg { width: 26px; height: 26px; color: var(--amber); }
.bx-file__preview {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
}

/* Cropper (reframe the weapon screenshot) */
.bx-cropper {
  margin-top: var(--sp-3);
  border: 1px solid var(--border-bright);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg);
}
.bx-cropper__stage { max-height: 360px; }
.bx-cropper__stage img { display: block; max-width: 100%; }
.bx-cropper__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border);
}
.bx-cropper__hint {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--ink-faint);
}

/* --- Share a build: form + live preview --- */
.bx-create-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--sp-8);
  align-items: start;
}
.bx-create-layout .bx-form { max-width: none; }
.bx-preview {
  position: sticky;
  top: calc(var(--nav-h) + var(--sp-4));
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.bx-preview__label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--amber);
}
.bx-card--preview { cursor: default; }
.bx-card--preview:hover { transform: none; border-color: var(--border); }
.bx-preview__shot-inner {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}
.bx-preview__shot-inner img { display: block; }

@media (max-width: 900px) {
  .bx-create-layout { grid-template-columns: 1fr; }
  .bx-preview { position: static; order: -1; }
}

/* Stats input block */
.bx-stats-inputs { border: none; padding: 0; margin: 0; }
.bx-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-3);
}
.bx-stat-in { display: flex; flex-direction: column; gap: 4px; }
.bx-stat-in > span {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.bx-stat-in > span em { color: var(--ink-faint); font-style: normal; }
.bx-stat-in input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--r);
  padding: 0.4rem 0.5rem;
  transition: border-color 0.15s;
}
.bx-stat-in input:focus { outline: none; border-color: var(--amber); }
.bx-stat-in--vel > span { color: var(--amber-dim); }

.bx-counter {
  align-self: flex-end;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-faint);
}

.bx-form__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  margin-top: var(--sp-6);
  flex-wrap: wrap;
}
.bx-form__msg { font-size: 0.85rem; color: var(--ink-muted); }
.bx-form__msg.is-error { color: var(--red); }
.bx-form__msg.is-ok { color: var(--green-bright); }

/* --- Toast --------------------------------- */
.bx-toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translate(-50%, 12px);
  z-index: var(--z-toast);
  font-family: var(--font-hd);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--border-bright);
  border-radius: var(--r-md);
  padding: 0.65rem 1.1rem;
  box-shadow: 0 8px 30px oklch(0 0 0 / 0.5);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s var(--ease-out);
}
.bx-toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* --- Responsive ---------------------------- */
@media (max-width: 860px) {
  .builder-page { flex-direction: column; }
  .bx-rail { flex: none; border-right: none; border-bottom: 1px solid var(--border); }
  .bx-rail__inner {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    padding: var(--sp-4) clamp(1.5rem, 5vw, 3rem);
  }
  .bx-rail__inner .bx-filters__hd { flex-basis: 100%; padding-bottom: 0; border-bottom: none; }
  .bx-rail__inner .bx-field { flex: 1; min-width: 160px; }
}
@media (max-width: 760px) {
  .bx-form__grid { grid-template-columns: 1fr; }
  .bx-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .bx-grid { grid-template-columns: 1fr; }
}
