/* ---- tierbuilder — standalone TierMaker-style builder for Bookd ---- */
:root {
  --bg: #0e0e10;
  --panel: #1a1a1d;
  --panel-2: #232327;
  --line: #303036;
  --ink: #f4f4f5;
  --ink-dim: #a1a1aa;
  --accent: #00e054;          /* bookd green (matches bookdfootball.com / logo) */
  --slot: #141417;
  --radius: 10px;
  --tile: 90px;               /* tile size === row height, so tiles fill the row */
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Archivo', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---------- nav bar (mirrors bookdfootball.com header) ---------- */
.topbar {
  position: sticky;
  top: 0;
  background: rgba(14, 14, 16, 0.92);
  backdrop-filter: blur(8px);
  z-index: 20;
}
/* inner row matches the board container width so the brand and store icons
   sit at the board's edges instead of the viewport edges. */
.topbar-inner {
  display: flex;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  line-height: 1;
}
.brand-mark {
  font: 800 22px 'Inter', sans-serif;
  letter-spacing: -0.5px;
  color: #00e054;          /* bookdfootball.com green */
}
.brand-tier {
  font: 800 22px 'Inter', sans-serif;
  letter-spacing: -0.5px;
  color: var(--ink);
}
.nav-stores {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 255, 255, 0.8);
}
.nav-stores-label {
  font: 700 12px 'Inter', sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nav-store-link {
  display: inline-flex;
  color: inherit;
  transition: color 0.15s;
}
.nav-store-link:hover { color: #fff; }
.nav-store-link svg { width: 20px; height: 20px; display: block; }

/* ---------- toolbar (toggle + export, under the nav) ---------- */
.toolbar {
  border-top: 1px solid var(--line);
  background: rgba(14, 14, 16, 0.6);
}
/* inner row matches the board's container width (.layout) so the toggle and
   button align with the left/right edges of the tier list. */
.toolbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
}
.mode-toggle {
  display: flex;
  gap: 6px;
  margin-right: auto;
}
.mode-chip {
  border: 0;
  background: var(--panel-2);
  color: var(--ink-dim);
  font: 600 14px 'Archivo', sans-serif;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.mode-chip.is-active { background: var(--accent); color: #06231a; }
.btn-export {
  border: 0;
  background: var(--accent);
  color: #06231a;
  font: 700 14px 'Archivo', sans-serif;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: filter 0.15s;
}
.btn-export:hover { filter: brightness(1.1); }
.btn-export:disabled { opacity: 0.5; cursor: default; }

/* ---------- layout ---------- */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 80px;
}

/* ---------- board ---------- */
.board {
  position: relative;
  background: #0a0a0c;
  border: 1px solid var(--line);
  overflow: hidden;
}
/* "bookd." watermark — only present in the exported image (added during capture) */
.export-watermark {
  position: absolute;
  top: 7px;
  right: 12px;
  z-index: 5;
  font: 800 20px 'Inter', sans-serif;
  letter-spacing: -0.5px;
  color: #00e054;
  text-shadow: 0 1px 4px rgba(0,0,0,0.85);
  pointer-events: none;
}
.row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #000;
  min-height: var(--tile);
}
.row:last-child { border-bottom: 0; }
.row-label {
  flex: 0 0 92px;
  min-width: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px;
  color: #1a1a1a;
  font: 600 15px 'Archivo', sans-serif;
  word-break: break-word;
  overflow: hidden;
}
.row-drop {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0;
  background: var(--slot);
  min-height: var(--tile);
  transition: background 0.12s;
}
.row-drop.drag-over { background: #20202a; outline: 2px dashed var(--accent); outline-offset: -4px; }
.row-controls {
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #050506;
  padding: 4px;
}
.row-gear, .row-arrow {
  border: 0;
  background: transparent;
  color: #d4d4d8;
  cursor: pointer;
  font-size: 22px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
}
.row-gear:hover, .row-arrow:hover { background: #26262c; }
.row-arrows { display: flex; flex-direction: column; }
.row-arrow { height: 24px; font-size: 15px; }

.add-tier {
  margin-top: 10px;
  width: 100%;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--ink-dim);
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font: 600 13px 'Archivo', sans-serif;
}
.add-tier:hover { color: var(--ink); border-color: var(--ink-dim); }

/* ---------- tiles (items) ---------- */
.tile {
  position: relative;
  width: var(--tile);
  height: var(--tile);
  background: #000;
  cursor: grab;
  user-select: none;
  flex: 0 0 auto;
  overflow: hidden;
}
.tile:active { cursor: grabbing; }
.tile.dragging { opacity: 0.4; }
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}
.tile .tile-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font: 600 8px 'Archivo', sans-serif;
  line-height: 1.05;
  color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,0.92), transparent);
  padding: 8px 3px 3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
/* match tile: team-colour gradient (set inline) + crest/score/date composite */
.tile.match-crests {
  display: flex;
  flex-direction: column;
  background: #15151a;          /* fallback; inline style sets the gradient */
}
.tile.match-crests::after {     /* legibility overlay, like the poster */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.4), rgba(0,0,0,0.05) 45%, rgba(0,0,0,0.78));
  pointer-events: none;
}
.tile.match-crests > * { position: relative; z-index: 1; }
.tile.match-crests .mc-top {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding-top: 3px;
}
.tile.match-crests .mc-top img {
  width: 28px; height: 28px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55));
}
.tile.match-crests .mc-score {
  font: 800 16px 'IBM Plex Mono', monospace;
  text-align: center;
  color: var(--accent);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.tile.match-crests .mc-date {
  font: 600 9.5px 'Archivo', sans-serif;
  text-align: center;
  color: rgba(255,255,255,0.85);
  padding-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

/* ---------- tray ---------- */
.tray-panel {
  margin-top: 22px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px 18px;
}
.tray-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tray-head h2 { margin: 0; font: 700 16px 'Archivo', sans-serif; }
.tray-hint { color: var(--ink-dim); font-size: 12px; }
.tray-controls { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.search-input {
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  font: 500 14px 'Archivo', sans-serif;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
.search-input:focus { border-color: var(--accent); }
/* recolour the native search "x" (clear) button to bookd green */
.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  height: 14px;
  width: 14px;
  cursor: pointer;
  background: center / contain no-repeat
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2300e054" stroke-width="3" stroke-linecap="round"><path d="M6 6 18 18M18 6 6 18"/></svg>');
}
.subtabs { display: flex; gap: 6px; }
.subtab {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-dim);
  font: 600 13px 'Archivo', sans-serif;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.subtab.is-active { background: var(--accent); color: #06231a; border-color: var(--accent); }
.matchup-inputs { display: flex; align-items: center; gap: 8px; }
.matchup-inputs .vs { color: var(--ink-dim); font-weight: 700; font-size: 13px; }
.matchup-inputs.hidden { display: none; }
.combo { position: relative; flex: 1; }
.combo .search-input { width: 100%; }
.combo-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: #1c1c20;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.55);
  z-index: 30;
  padding: 4px;
}
.combo-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.combo-opt:hover, .combo-opt.active { background: var(--panel-2); }
.combo-opt img { width: 22px; height: 22px; object-fit: contain; flex: 0 0 22px; }
.combo-opt .co-name { font: 600 14px 'Archivo', sans-serif; color: var(--ink); }
.combo-opt .co-sub { font: 500 11px 'Archivo', sans-serif; color: var(--ink-dim); margin-left: auto; }
.combo-empty { padding: 10px; color: var(--ink-dim); font-size: 13px; text-align: center; }

.tray-status { color: var(--ink-dim); font-size: 12px; min-height: 16px; margin: 10px 0 4px; }
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 92px;
  background: var(--slot);
  border-radius: 8px;
  padding: 8px;
  transition: background 0.12s;
}
.tray.drag-over { background: #20202a; outline: 2px dashed var(--accent); outline-offset: -4px; }
.tray .tile { border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  position: relative;
  background: #161618;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  padding: 26px 26px 24px;
  text-align: center;
}
.modal h3 { font: 700 18px 'Archivo', sans-serif; margin: 0 0 14px; }
.modal h3:nth-of-type(2) { margin-top: 22px; }
.modal-x {
  position: absolute;
  top: 14px; right: 16px;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}
.swatches { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.swatch {
  width: 40px; height: 40px;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
}
.swatch.is-selected { border-color: #fff; box-shadow: 0 0 0 2px #000 inset; }
.label-input {
  width: 100%;
  background: #fff;
  color: #111;
  border: 0;
  border-radius: 8px;
  padding: 14px;
  font: 500 16px 'Archivo', sans-serif;
  resize: vertical;
}
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}
.modal-btn {
  background: #e9e9ea;
  color: #1a1a1a;
  border: 0;
  border-radius: 8px;
  padding: 14px;
  font: 600 14px 'Archivo', sans-serif;
  cursor: pointer;
}
.modal-btn:hover { background: #fff; }
.modal-btn[data-act="delete"] { background: #f1c0c0; }
.modal-btn[data-act="delete"]:hover { background: #f6caca; }

/* ---------- export capture mode ---------- */
.board.capturing .row-controls { display: none; }

/* ---------- utils ---------- */
.hidden { display: none !important; }
.drag-ghost {
  position: fixed;
  top: 0; left: 0;
  width: var(--tile); height: var(--tile);
  pointer-events: none;
  z-index: 100;
  opacity: 0.9;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
}
.drag-ghost img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 640px) {
  :root { --tile: 62px; }       /* smaller tiles === shorter rows on mobile */
  .toolbar { gap: 10px; }
  .mode-toggle { margin-right: auto; }
  .btn-export { padding: 10px 14px; }
  .row-label { flex-basis: 64px; min-width: 64px; font-size: 13px; }
  .tile.match-crests .mc-top img { width: 22px; height: 22px; }
}
