/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/*
 * ── Design tokens ─────────────────────────────────────────────
 *
 *  Colors
 *  bg:                 #040714
 *  surface-1 (cards):  rgba(255,255,255,.03)
 *  surface-2 (hover):  rgba(255,255,255,.06)
 *  border-subtle:      rgba(255,255,255,.07)
 *  border:             rgba(255,255,255,.1)
 *  border-strong:      rgba(255,255,255,.22)
 *  blue accent:        #0063e5
 *  blue accent bright: #0080ff
 *  text primary:       #f9f9f9
 *  text secondary:     #cacaca
 *  text muted:         rgba(255,255,255,.55)
 *  header gradient:    in oklch 135deg, #B015B0 0%, #3D0080 50%, #040714 100%
 *
 *  Typography scale (rem)
 *  --text-xs: 0.75    --text-sm: 0.875   --text-base: 1
 *  --text-lg: 1.125   --text-xl: 1.25    --text-2xl: 1.5
 *  font stack: 'Avenir Next', -apple-system, BlinkMacSystemFont,
 *              'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif
 *
 *  Spacing scale (4px grid)
 *  --space-1: 4px   --space-2: 8px   --space-3: 12px   --space-4: 16px
 *  --space-6: 24px  --space-8: 32px
 *
 *  Radii
 *  --radius-sm: 6px   --radius: 10px   --radius-lg: 15px
 *
 *  Easing
 *  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1)  (spring/overshoot)
 *  --dur-fast: 120ms   --dur: 200ms
 */

:root {
  --bg: #040714;
  --surface-1: rgba(255,255,255,.03);
  --surface-2: rgba(255,255,255,.06);
  --border-subtle: rgba(255,255,255,.07);
  --border: rgba(255,255,255,.1);
  --border-strong: rgba(255,255,255,.22);
  --text-primary: #f9f9f9;
  --text-secondary: #cacaca;
  --text-muted: rgba(255,255,255,.55);
  --accent: #0063e5;
  --accent-bright: #0080ff;
  --font: 'Avenir Next', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --text-xs: 0.75rem; --text-sm: 0.875rem; --text-base: 1rem;
  --text-lg: 1.125rem; --text-xl: 1.25rem; --text-2xl: 1.5rem;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-6: 24px; --space-8: 32px;
  --radius-sm: 6px; --radius: 10px; --radius-lg: 15px;
  --ease-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 120ms; --dur: 200ms;
}

html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100%;
  color: var(--text-primary);
  display: flex; flex-direction: column;
}

/* ── Layout ────────────────────────────────────────────────── */
/*
 * GOTCHA: body { display:flex; flex-direction:column } + margin: 0 auto
 * on a child collapses its width — always pair with width: 100%.
 *
 * GOTCHA: External images (YouTube ggpht, Gravatar, etc.) may block loading
 * when the Referer header points to localhost or an unknown origin. Fix:
 * 1. Add <meta name="referrer" content="no-referrer"> in <head> (global)
 * 2. Or add referrerpolicy="no-referrer" on each <img> tag
 * Option 1 is simpler but affects all outbound requests (analytics, etc.).
 */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 30px;
  flex: 1;
}

/* ── Header ────────────────────────────────────────────────── */
.header-bar {
  background: linear-gradient(in oklch 135deg, #B015B0 0%, #3D0080 50%, #040714 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-6);
  height: 68px;
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
}

.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.header-logo-img {
  height: 36px; width: auto; flex-shrink: 0;
  filter: brightness(0) invert(1);
  transition: transform 0.3s var(--ease-snap);
  display: block;
}
.header-logo-img:hover { transform: scale(1.14) rotate(-9deg); }

.header-title-link { text-decoration: none; color: inherit; }
.header-logo h1 { font-size: 1.2em; font-weight: 600; color: var(--text-primary); letter-spacing: .5px; }
.header-subtitle { font-size: .82em; color: rgba(255,255,255,.72); font-weight: 500; margin-top: 3px; }

/* ── Nav & Auth ────────────────────────────────────────────── */
/*
 * THREE PATTERNS:
 *   A) No nav, no auth → margin-left: auto on .header-home
 *   B) Auth only       → margin-left: auto on .auth-toggle, margin-left: 8px on .header-home
 *   C) Nav + auth      → margin-left: auto on <nav>, margin-left: 5px on .header-home
 */
nav {
  display: flex;
  align-items: center;
  gap: 8px;
  /* margin-left: auto; -- uncomment for Pattern C */
}
.nav-link {
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background var(--dur), color var(--dur);
}
.nav-link:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.auth-toggle {
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  background: transparent;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  transition: background var(--dur), color var(--dur);
  display: flex;
  align-items: center;
  /* margin-left: auto; -- uncomment for Pattern B */
}
.auth-toggle:hover {
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.auth-toggle svg {
  width: 22px;
  height: 22px;
}

.header-home {
  display: flex; align-items: center;
  margin-left: auto;  /* Pattern A — move to nav or auth-toggle for B/C */
  padding: 5px;
  color: rgba(255,255,255,0.9); text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur); flex-shrink: 0;
}
.header-home:hover { color: #fff; background: rgba(255,255,255,0.12); }
.header-home svg { width: 34px; height: 34px; display: block; }

/* ── Auth panel (collapsible) ──────────────────────────────── */
.auth-panel {
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border-subtle);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}
.auth-panel.open {
  max-height: 300px;
}
.auth-panel-inner {
  padding: 20px;
  max-width: 400px;
  margin: 0 auto;
}
.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.auth-tab {
  flex: 1;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur);
}
.auth-tab.active {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.auth-form input {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: var(--text-sm);
}
.auth-submit {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur);
}
.auth-submit:hover {
  background: var(--accent-bright);
}
#authUser {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.auth-username {
  color: var(--text-primary);
  font-weight: 600;
}
.auth-logout {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur);
}
.auth-logout:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.auth-divider {
  height: 1px;
  background: var(--border-subtle);
}

/* ── Card ──────────────────────────────────────────────────── */
/*
 * GOTCHA: backdrop-filter creates a stacking context — dropdowns inside
 * a card can be clipped by a later card's stacking context. Fix by adding
 * position: relative; z-index: 10 to the card that owns the open dropdown.
 */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px;
  margin-bottom: 20px;
  backdrop-filter: blur(10px);
  transition: transform var(--dur) ease-out, box-shadow var(--dur) ease-out;
  animation: fadeIn 0.3s ease-out both;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.25);
}

/* ── Button press feedback ────────────────────────────────────── */
button:active, .btn:active {
  transform: scale(0.97);
  transition-duration: var(--dur-fast);
}

/* ── Entrance animation ───────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Skeleton loading ─────────────────────────────────────────── */
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--surface-1) 25%, var(--surface-2) 50%, var(--surface-1) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: #1a1730; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 10px 16px;
  font-size: 0.84rem; color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.55);
  pointer-events: none;
  transform: translateY(8px); opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ── Footer ────────────────────────────────────────────────── */
.info-footer {
  text-align: center; padding: 20px var(--space-6) 28px;
  color: var(--text-muted); font-size: .78em; line-height: 1.8;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}
.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--dur);
}
.footer-link:hover,
.footer-link:focus-visible {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* ── Focus styles ──────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent-bright);
  outline-offset: 2px;
}

/* ── Skip link ─────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent-bright);
  color: #000;
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--dur);
}
.skip-link:focus { top: 0; }

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-bar { padding: 0 var(--space-4); }
  .container { padding: var(--space-4); }

  .item-card {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
  }

  .item-left-col,
  .item-right-col {
    flex-wrap: wrap;
  }

  .drag-indicator {
    font-size: 16px;
  }

  .item-text {
    font-size: 1rem;
  }

  .rank-up,
  .rank-down {
    font-size: 0.8125rem;
    padding: 4px 8px;
  }
}

/* ── Stack Rank Custom Styles ──────────────────────────────── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.list-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  min-width: 200px;
}

.list-title:focus {
  background: var(--surface-2);
}

.toolbar-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: all var(--dur);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-bright);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-1);
  color: var(--text-primary);
}

.btn-small {
  padding: 6px 12px;
  font-size: var(--text-xs);
}

.url-display {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

.url-display-content {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

#shareUrl {
  flex: 1;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: monospace;
  font-size: var(--text-sm);
}

/* Item List */
.item-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 200px;
}

.item-card {
  background: var(--surface-1);
  border: 3px solid white;
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  cursor: grab;
  transition: all var(--dur);
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: center;
  min-height: 80px;
  height: 80px;
}

.item-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0,0,0,0.35);
  border-width: 3px;
}

.item-card:active {
  cursor: grabbing;
}

.item-card.dragging {
  opacity: 0.6;
  transform: rotate(1deg) scale(1.02);
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.item-left-col {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.item-center-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}

.item-text {
  font-size: 1.125rem;
  font-weight: 600;
  color: white;
  line-height: 1.4;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.item-right-col {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.item-priority {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.5);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.rank-up,
.rank-down {
  font-size: 0.875rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  backdrop-filter: blur(6px);
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.rank-up {
  background: rgba(34, 197, 94, 0.5);
  color: white;
}

.rank-down {
  background: rgba(239, 68, 68, 0.5);
  color: white;
}

.tag {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.item-notes {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.4;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-item-btn,
.delete-item-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.3);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: all var(--dur);
  opacity: 0;
}

.item-card:hover .edit-item-btn,
.item-card:hover .delete-item-btn {
  opacity: 1;
}

.edit-item-btn:hover,
.delete-item-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.8);
  transform: translateY(-2px);
}

.edit-item-btn:active,
.delete-item-btn:active {
  transform: translateY(0);
}

/* Drag handle is now replaced with drag-indicator in the new layout */

/* Empty State */
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
  background: var(--surface-1);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
}

.empty-state-content {
  text-align: center;
  color: var(--text-muted);
}

.empty-state-content h3 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-2);
}

.empty-state-content p {
  margin-bottom: var(--space-4);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal.open {
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
}

.modal-header h3 {
  font-size: var(--text-xl);
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-2);
  font-weight: 600;
  color: var(--text-primary);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

.color-option {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--dur);
}

.color-option.active {
  border-color: var(--text-primary);
  transform: scale(1.1);
}

.color-option:hover {
  transform: scale(1.05);
}

.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-4);
}

/* Template Modal */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.template-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  cursor: pointer;
  transition: all var(--dur);
  text-align: center;
}

.template-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.template-card h4 {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: var(--space-1);
  color: var(--text-primary);
}

.template-card p {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.hidden {
  display: none !important;
}
