:root {
  --bg: #000000;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.4);
  --border: rgba(255, 255, 255, 0.05);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --accent: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.12);
  --accent-border: rgba(167, 139, 250, 0.35);
  --accent-glow: rgba(167, 139, 250, 0.18);
  --accent-2: #c4b5fd;
  --danger: #ef4444;
  --focus: rgba(167, 139, 250, 0.5);
  --radius: 4px;
  --radius-sm: 4px;
  --trans: 150ms ease;
}

body.theme-dark {
  --bg: #000000;
  --surface: rgba(255, 255, 255, 0.03);
  --surface-2: rgba(255, 255, 255, 0.06);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.4);
  --border: rgba(255, 255, 255, 0.05);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --accent: #a78bfa;
  --accent-soft: rgba(167, 139, 250, 0.12);
  --accent-border: rgba(167, 139, 250, 0.35);
  --accent-glow: rgba(167, 139, 250, 0.18);
  --accent-2: #c4b5fd;
  --danger: #ef4444;
  --focus: rgba(167, 139, 250, 0.5);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Helvetica Neue",
    sans-serif;
  transition: background var(--trans), color var(--trans);
}

/* Background flash when saving (purely visual, behind the UI). */
body::before {
  content: "";
  position: fixed;
  top: var(--flash-top, 0px);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  background: rgba(167, 139, 250, 0.12);
}

@keyframes bgFlash {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 0.75;
  }
  100% {
    opacity: 0;
  }
}

body.is-flashing::before {
  opacity: 1;
  animation: bgFlash 900ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  body.is-flashing::before {
    animation: none;
    opacity: 0.25;
  }
}

button,
input,
textarea {
  font: inherit;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  /* Match the tracking rows' glass color/transparency */
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background var(--trans), border-color var(--trans);
}

.navbar__inner {
  padding: 12px 24px;
  /* Title is absolutely positioned, so we keep a stable height */
  min-height: 44px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.navbar__title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  color: var(--text);
}

.navbar__right {
  margin-left: auto;
}

.page {
  position: relative;
  z-index: 2;
  max-width: 1200px;
  margin: 40px auto 56px;
  padding: 0 24px;
}

.header-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding: 0 4px;
}

.header-action__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
}

.btn--sleek {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 4px;
  transition: all var(--trans);
}

.btn--sleek:hover {
  background: var(--surface-2);
  border-color: var(--muted);
  transform: none;
}

body.theme-dark .btn--sleek {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
}

body.theme-dark .btn--sleek:hover {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #ffffff;
}

@keyframes saveBreath {
  0% {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
  }
  50% {
    background: var(--accent-soft);
    border-color: var(--accent-border);
  }
  100% {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.1);
  }
}

#saveBtn.is-dirty {
  animation: saveBreath 1.9s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  #saveBtn.is-dirty {
    animation: none;
  }
}

/* Dark-mode starfield (canvas) */
.star-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--trans);
}

body.theme-dark .star-canvas {
  opacity: 1;
}

/* Main List */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 16px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--trans);
  user-select: none;
}

.btn:hover {
  background: var(--surface);
  border-color: var(--muted);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.btn:disabled:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  color: #0d0d14;
  border-color: transparent;
}

.btn--primary:hover {
  background: var(--accent-2);
  border-color: transparent;
}

body.theme-dark .btn--primary {
  background: var(--accent);
  color: #0d0d14;
}

body.theme-dark .btn--primary:hover {
  background: var(--accent-2);
}

.theme-toggle {
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  display: none; /* Dark-only UI: remove light-mode toggle entirely */
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.theme-toggle__icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
}

.theme-toggle__icon--moon {
  display: none;
}

body.theme-dark .theme-toggle__icon--sun {
  display: none;
}

body.theme-dark .theme-toggle__icon--moon {
  display: inline;
  fill: currentColor;
  stroke: none;
}

body.theme-dark .theme-toggle {
  color: #ffffff;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty {
  padding: 32px 18px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
}

body.theme-dark .empty {
  background: rgba(255, 255, 255, 0.02);
}

/* Player row (label) */
.row {
  position: relative;
}

.row__bar {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: all var(--trans);
  position: relative;
  z-index: 2; /* keep the main bar above the sliding sheet */
}

.row__bar:hover {
  background: var(--surface-2);
  border-color: var(--accent-border);
}

.row.is-drag-source .row__bar {
  opacity: 0.35;
}

.row.is-expanded .row__bar {
  border-color: var(--border);
  border-left: 2px solid var(--accent);
}

.row.is-expanded .details {
  border-color: var(--border);
  border-left: 2px solid var(--accent);
}

.rank {
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 14px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: all var(--trans);
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

body.theme-dark .icon-btn {
  color: rgba(255, 255, 255, 0.6);
}

body.theme-dark .icon-btn:hover {
  color: #ffffff;
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.name {
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expand-btn {
  position: relative;
}

.expand-btn .chev {
  display: inline-block;
  transition: transform var(--trans);
}

.row.is-expanded .expand-btn .chev {
  transform: rotate(180deg);
}

/* Slide-out sheet */
.details {
  margin: -4px 0 0; /* tuck slightly under the bar */
  border-radius: 0 0 4px 4px;
  border: 1px solid var(--border);
  border-top: 0;
  background: var(--surface);
  overflow: hidden;
  position: relative;
  z-index: 1; /* sheet sits behind the bar */
  width: 100%;
  padding: 12px 16px;
  max-height: 0;
  will-change: max-height, transform, opacity;
  opacity: 0;
  transform: translateY(-10px);
  transition: max-height 260ms ease, opacity 220ms ease, transform 260ms ease, border-color var(--trans),
    background var(--trans);
}

.row.is-expanded .details {
  opacity: 1;
  transform: translateY(0);
}

.reason {
  width: 100%;
  min-height: 48px;
  resize: none;
  overflow: hidden;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
}

.reason:focus {
  box-shadow: none;
  outline: none;
}

.reason::placeholder {
  color: var(--muted);
  font-style: italic;
}

.placeholder {
  border-radius: 4px;
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.02);
}

body.theme-dark .placeholder {
  background: rgba(255, 255, 255, 0.05);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10000;
}

.modal {
  width: min(520px, 100%);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--accent-border);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-border);
  padding: 24px;
  z-index: 10001;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal__title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.modal__desc {
  margin: 8px 0 12px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
}

.field__label {
  font-size: 12px;
  color: var(--muted);
}

.field__input {
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  font-size: 14px;
  transition: all var(--trans);
}

.field__input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

body.theme-dark .field__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field__error {
  min-height: 16px;
  font-size: 12px;
  color: var(--danger);
}

.field__input::placeholder {
  color: var(--muted);
}

.modal__actions {
  display: flex;
  justify-content: end;
  gap: 10px;
  margin-top: 14px;
}

/* Delete button (always lavender) */
.delete-btn {
  color: var(--accent) !important;
  flex-shrink: 0;
}

.delete-btn:hover {
  color: var(--accent-2) !important;
  background: var(--accent-soft) !important;
}

/* Danger button variant */
.btn--danger {
  background: var(--danger);
  color: #fff;
  border: none;
}

.btn--danger:hover {
  background: #dc2626;
}

/* Compact confirm modal */
.modal--confirm {
  width: min(360px, 100%);
}

/* Drag ghost (follows pointer) */
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  pointer-events: none;
  z-index: 9999;
  transform: translate3d(0, 0, 0);
}

.drag-ghost .row__bar {
  box-shadow: var(--shadow-sm);
}

/* Vignette overlay — darkens screen edges so the list pops */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.65) 100%);
}

/* --------------------------------
   Login Screen
   -------------------------------- */

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-border);
  padding: 32px 28px 28px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
}

.login-card__title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
  margin-bottom: 6px;
  color: var(--text);
}

.login-card__subtitle {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.login-card__error {
  display: block;
  min-height: 18px;
  margin-top: 10px;
  font-size: 13px;
}

.login-card__btn {
  margin-top: 18px;
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
}

/* --------------------------------
   Reduced-motion
   -------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
