:root {
  --bg: #0e0e10;
  --fg: #f5f3ee;
  --muted: #8a8780;
  --accent: #d9b48f;
  --error-bg: #3a1f20;
  --error-fg: #f5b6b6;
  --serif: ui-serif, "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  place-items: center;
  padding: 2rem;
}

main {
  width: 100%;
  display: grid;
  place-items: center;
}

.hero {
  text-align: center;
  max-width: 32rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.hero.hidden { display: none; }

h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3rem, 12vw, 6rem);
  letter-spacing: -0.04em;
  line-height: 1;
}

h1.small-title {
  font-size: clamp(1.5rem, 5vw, 2rem);
  color: var(--fg);
}

.tag {
  font-size: 1.125rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.muted {
  font-size: 0.875rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.muted.small {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  margin-top: 0.5rem;
}

.btn-primary {
  font-family: var(--sans);
  font-size: 1rem;
  background: var(--fg);
  color: var(--bg);
  border: none;
  padding: 0.9rem 2rem;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 80ms ease, opacity 200ms ease;
}

.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); opacity: 0.9; }

.btn-link {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.875rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 4px;
  transition: text-decoration-color 200ms ease;
}

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

.actions {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
}

.library-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 0;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: progress;
}

/* ---- Library grid screen ---- */

.grid-screen {
  width: 100%;
  max-width: 84rem;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 8rem;
}

.grid-screen.hidden { display: none; }

.grid-header {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.grid-title {
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--fg);
  margin: 0;
}

.grid-stats {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-left: auto;
}

.grid-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-input,
.select {
  background: rgba(255,255,255,0.04);
  color: var(--fg);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 0.875rem;
  outline: none;
}

.search-input { flex: 1 1 18rem; }
.search-input::placeholder { color: var(--muted); }

.search-input:focus,
.select:focus {
  border-color: var(--accent);
}

/* Orb grid */
.orbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  gap: 1rem;
}

.orb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 120ms ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  text-align: center;
  overflow: hidden;
  background: var(--card, #16161a);
  border: 1px solid rgba(255,255,255,0.06);
}

.orb:hover {
  transform: scale(1.04);
}

.orb.selected {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  transform: scale(1.06);
}

.orb.selected.slot-a::after {
  content: 'A';
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.7rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.orb.selected.slot-b::after {
  content: 'B';
  position: absolute;
  top: 0.4rem;
  left: 0.4rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.7rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.orb-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  z-index: 0;
  /* set by JS via inline background */
  opacity: 0.85;
}

.orb-name,
.orb-artist,
.orb-meta {
  position: relative;
  z-index: 1;
  font-size: 0.7rem;
  line-height: 1.15;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.orb-name {
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.orb-artist {
  font-size: 0.65rem;
  opacity: 0.85;
}

.orb-meta {
  margin-top: 0.25rem;
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

/* Selection bar fixed at bottom */
.selection-bar {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22,22,26,0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: calc(100vw - 2rem);
  z-index: 10;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.selection-bar.hidden { display: none; }

.selection-slot {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 8rem;
}

.slot-label {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.slot-track {
  font-size: 0.8rem;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12rem;
}

.selection-arrow {
  color: var(--muted);
  font-size: 1.25rem;
}

.selection-meta {
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ---- Stitch creator ---- */

.stitch-screen {
  width: 100%;
  max-width: 56rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.stitch-screen.hidden { display: none; }

.stitch-header {
  display: flex;
  align-items: baseline;
  gap: 1.5rem;
}

.stitch-score {
  margin-left: auto;
  color: var(--accent);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.stitch-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.5rem;
}

.track-card {
  background: var(--card, #16161a);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 4rem 1fr;
  align-items: center;
  gap: 1rem;
}

.track-orb {
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: var(--muted);
}

.track-name {
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.2;
  color: var(--fg);
  margin-bottom: 0.15rem;
}

.track-artist {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.track-tech {
  font-size: 0.75rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.stitch-arrow {
  font-size: 1.5rem;
  color: var(--muted);
}

.variants-title {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-top: 0.5rem;
}

.variants {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem;
}

.variant {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 1rem;
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease;
}

.variant:hover { transform: translateY(-1px); }

.variant.selected {
  border-color: var(--accent);
  background: rgba(217,180,143,0.08);
}

.variant-label {
  font-family: var(--serif);
  font-size: 1rem;
  margin-bottom: 0.4rem;
  color: var(--fg);
}

.variant-type {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 0.6rem;
}

.variant-desc {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  margin-bottom: 0.6rem;
}

.variant-times {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", monospace;
}

.stitch-actions {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

.saved-card {
  background: rgba(217,180,143,0.08);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
}

.saved-card.hidden { display: none; }

.link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 4px;
  word-break: break-all;
}

.view-detail {
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.view-detail-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.view-detail-row .label {
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.view-detail-row .value {
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", monospace;
}

.error {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error-bg);
  color: var(--error-fg);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.875rem;
  max-width: min(90vw, 28rem);
}

.error.hidden { display: none; }

.hidden { display: none !important; }
