/* ============================================================
   Components: buttons, panels, cards, forms, modals, toasts,
   badges, tabs, tables. Depends on base.css tokens.
   ============================================================ */

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none !important;
  user-select: none;
  transition: transform 0.16s var(--ease-spring), box-shadow 0.2s ease,
              background-color 0.16s ease, border-color 0.16s ease, filter 0.16s ease;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled, .btn.is-disabled {
  pointer-events: none;
  filter: saturate(0.35) brightness(0.75);
}

.btn-primary {
  background: var(--grad-primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(232, 99, 10, 0.3);
}
.btn-primary:hover { box-shadow: var(--glow-orange), 0 8px 22px rgba(232, 99, 10, 0.35); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-ghost:hover { background: var(--panel-hover); border-color: var(--orange); }

.btn-danger {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 14px rgba(226, 59, 13, 0.3);
}
.btn-danger:hover { box-shadow: 0 0 20px rgba(226, 59, 13, 0.4); }

.btn-sm { min-height: 34px; padding: 5px 14px; font-size: 0.84rem; }
.btn-lg { min-height: 54px; padding: 14px 32px; font-size: 1.05rem; }
.btn-block { width: 100%; }

/* Loading state: spinner replaces the label. */
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: btn-spin 0.7s linear infinite;
}
.btn-ghost.is-loading::after { border-color: var(--line-strong); border-top-color: var(--orange); }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---- Panels ---- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.panel-link {
  display: block;
  color: inherit;
  text-decoration: none !important;
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s ease,
              border-color 0.2s ease, background-color 0.2s ease;
}
.panel-link:hover {
  transform: translateY(-3px);
  border-color: var(--orange);
  background: var(--panel-hover);
  box-shadow: var(--shadow-lift);
}

/* ---- Card tiles (5:7 game cards) ---- */
.card-tile {
  position: relative;
  aspect-ratio: 5 / 7;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.18s var(--ease-spring), box-shadow 0.2s ease, border-color 0.2s ease;
}
.card-tile img { width: 100%; height: 100%; object-fit: cover; }
.card-tile:hover {
  transform: scale(1.045);
  border-color: var(--orange-hot);
  box-shadow: var(--glow-orange), var(--shadow-lift);
  z-index: 2;
}
.card-tile .card-tile-name {
  position: absolute;
  inset: auto 0 0 0;
  padding: 18px 8px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
}
.card-tile.is-skeleton { pointer-events: none; }
.card-tile.is-skeleton::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.08) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

/* ---- Forms ---- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-elev);
  color: var(--text);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.textarea { min-height: 110px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232, 99, 10, 0.22);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input[type='checkbox'] { width: 18px; height: 18px; accent-color: var(--orange); }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid var(--line-strong);
  color: var(--muted);
}
.badge-live { color: #fff; background: var(--red); border-color: var(--red); }
.badge-live::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}
.badge-open { color: var(--green); border-color: rgba(74, 222, 128, 0.5); }
.badge-gold { color: var(--gold); border-color: rgba(242, 178, 62, 0.5); }
.badge-color { color: var(--text); }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Card colour.
   A deck may hold only one colour, so colour needs to be readable at a glance
   wherever cards are listed. The dot is always accompanied by the colour's NAME
   or a title attribute — colour alone is not a label anyone can rely on. */
.color-dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  /* A ring rather than a border, so the dot's own size stays constant and it
     reads against both the panel and the card art it sits on. */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 255, 255, 0.22);
}
.color-dot.is-colorless {
  background: transparent;
  box-shadow: 0 0 0 1px var(--line-strong);
}

.role-chip {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--orange-hot);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---- Alerts ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  margin-bottom: 16px;
  font-size: 0.94rem;
}
.alert-error { border-color: rgba(226, 59, 13, 0.6); background: rgba(226, 59, 13, 0.12); }
.alert-success { border-color: rgba(74, 222, 128, 0.5); background: rgba(74, 222, 128, 0.1); }
.alert-info { border-color: rgba(96, 165, 250, 0.5); background: rgba(96, 165, 250, 0.1); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 6, 8, 0.6);
  backdrop-filter: blur(6px);
  animation: fade-in 0.18s ease;
}
.modal {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow-lift);
  animation: modal-up 0.24s var(--ease-spring);
}
.modal-wide { width: min(760px, 100%); }
.modal h3 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-up { from { opacity: 0; transform: translateY(22px) scale(0.97); } }

/* ---- Toasts ---- */
.toast-stack {
  position: fixed;
  right: 16px; bottom: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--blue);
  box-shadow: var(--shadow-lift);
  font-size: 0.92rem;
  animation: toast-in 0.28s var(--ease-spring);
}
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }
.toast.is-leaving { opacity: 0; transform: translateX(20px); transition: all 0.25s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 10px 18px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--orange-hot); border-bottom-color: var(--orange); }

/* ---- Tables ---- */
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 2px solid var(--line-strong);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table tbody tr { transition: background-color 0.12s ease; }
.table tbody tr:hover { background: var(--panel-hover); }

/* ---- Empty state (leaf watermark) ---- */
.empty-state {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
/* Masked, not a background image: as a mask the leaf takes --leaf and so stays
   visible on both themes, where the fixed-orange uzumaki did not. */
.empty-state::before {
  content: '';
  display: block;
  width: 64px; height: 64px;
  margin: 0 auto 14px;
  background: var(--leaf);
  opacity: 0.42;
  -webkit-mask: var(--leaf-mark) no-repeat center / contain;
          mask: var(--leaf-mark) no-repeat center / contain;
}

/* Action buttons that sit on a card tile / deck row.
   Deliberately ALWAYS visible: an earlier version faded them in on hover, which
   made the only way to read a card effectively invisible. Clicking the card
   itself opens it; these buttons are the mutating actions. */
.card-tile { position: relative; }
.tile-btn {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 26px; height: 26px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.72); color: #fff;
  font-family: var(--font-display); font-size: 1rem; line-height: 1;
  cursor: pointer; transition: transform .12s ease, background .12s ease;
}
.tile-btn:hover { transform: scale(1.15); background: var(--accent); border-color: var(--accent); }
.tile-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-btn-add { background: rgba(226, 59, 13, 0.9); border-color: rgba(255, 255, 255, 0.7); }

.deck-entry { position: relative; padding-right: 34px; cursor: pointer; }
.deck-entry .tile-btn { top: 50%; margin-top: -13px; right: 6px; width: 24px; height: 24px; }

/* A card tile is clickable to read the card — make that obvious. */
.card-tile { cursor: pointer; }
.card-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
