:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e5e5;
  --text: #1a1a1a;
  --muted: #737373;
  --hover: #f5f5f5;
  --focus: #171717;
  --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.logo {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  cursor: pointer;
  width: fit-content;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

.nav-tab {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.2rem 0;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.is-active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--text);
}

.library-picker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.library-picker-label {
  font-size: 0.8125rem;
  color: var(--muted);
}

.library-select {
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.library-select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.view {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

.intro {
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
}

.muted {
  color: var(--muted);
}

.optional {
  font-weight: 400;
  color: var(--muted);
}

.album-list-home {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.tier-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.tier-heading {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.album-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.album-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem 1rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: start;
}

.album-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.btn-link {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover {
  color: var(--text);
}

.btn-link:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.album-row:last-child {
  border-bottom: none;
}

.album-main {
  min-width: 0;
}

.album-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.album-artist {
  margin: 0.125rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.album-genre {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.album-score {
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.album-meta {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  color: var(--muted);
}

.album-meta p {
  margin: 0.35rem 0 0;
}

.album-songs {
  margin: 0.35rem 0 0;
  padding-left: 1rem;
}

.empty-tier {
  margin: 0;
  padding: 1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.panel {
  padding-top: 2rem;
}

.panel-title {
  margin: 0 0 1.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.edit-context {
  margin: 0 0 0.5rem;
  font-size: 0.9375rem;
  color: var(--text);
}

.edit-note {
  margin: 0 0 1.25rem;
  font-size: 0.8125rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.field input[type="text"],
.field textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.field textarea {
  resize: vertical;
  min-height: 88px;
}

.tier-fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

.tier-options {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.tier-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9375rem;
  background: var(--surface);
}

.tier-option:hover {
  background: var(--hover);
}

.tier-option input {
  accent-color: var(--focus);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: var(--text);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

.btn-primary:hover {
  opacity: 0.92;
}

.btn-ghost {
  border-color: var(--border);
  background: var(--surface);
}

.btn-ghost:hover {
  background: var(--hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:disabled:hover {
  opacity: 0.45;
}

.versus-hint {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
}

.versus-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 520px) {
  .versus-cards {
    grid-template-columns: 1fr;
  }
}

.versus-card {
  text-align: left;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font: inherit;
  color: inherit;
  min-height: 5.5rem;
}

.versus-card:hover {
  background: var(--hover);
}

.versus-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.versus-title {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
}

.versus-artist {
  display: block;
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.versus-progress {
  margin: 1rem 0 0;
  font-size: 0.8125rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.5rem 0.9rem;
  background: var(--text);
  color: var(--surface);
  font-size: 0.8125rem;
  border-radius: 6px;
  max-width: min(90vw, 360px);
  text-align: center;
  z-index: 20;
}

.reorder-intro {
  margin: 0 0 1.25rem;
  font-size: 0.875rem;
}

.reorder-tiers {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.reorder-tier-title {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.reorder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.reorder-item {
  padding: 0.65rem 0.9rem;
  font-size: 0.9375rem;
  border-bottom: 1px solid var(--border);
  cursor: grab;
  user-select: none;
}

.reorder-item:last-child {
  border-bottom: none;
}

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

.reorder-item.reorder-dragging {
  opacity: 0.55;
}

.reorder-tier-empty {
  margin: 0;
  font-size: 0.875rem;
  padding: 0.25rem 0;
}

.stats-section {
  margin-bottom: 2rem;
}

.stats-section:last-of-type {
  margin-bottom: 0;
}

.stats-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}

.stats-heading {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stats-min2 {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.stats-min2 input {
  accent-color: var(--focus);
}

.stats-note {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
}

.stats-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: auto;
}

.stats-filtered-empty {
  margin: 0;
  padding: 1rem 0.85rem;
  font-size: 0.875rem;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.stats-table th,
.stats-table td {
  padding: 0.55rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.stats-table .stats-num {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  width: 1%;
}

[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.modal-card {
  position: relative;
  width: min(100%, 24rem);
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.auth-hint {
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.auth-error {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  color: #b91c1c;
}

.album-row .btn-link[hidden] {
  display: none !important;
}
