/* ========================================
   Ukulele Chords — Pen Plotter Aesthetic
   ======================================== */

:root {
  --ink: #1a1a1a;
  --paper: #fefefe;
  --ghost: #d4d4d4;
  --whisper: #f5f5f5;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;
  --grid-gap: 2rem;
  --page-margin: clamp(1.5rem, 5vw, 4rem);
}

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

body {
  font-family: var(--font-mono);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- Header ---- */

header {
  padding: var(--page-margin) var(--page-margin) 0;
}

.header-content {
  padding: 2.5rem 0 1.5rem;
}

h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(3rem, 8vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.title-accent {
  font-style: italic;
}

.subtitle {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ghost);
}

.header-rule {
  height: 1px;
  background: var(--ink);
  width: 100%;
}

/* ---- Filters ---- */

.filters {
  display: flex;
  gap: 0.25rem;
  padding: 1.25rem 0;
  flex-wrap: wrap;
}

.filter-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.45rem 1rem;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

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

.filter-btn.active {
  background: var(--ink);
  color: var(--paper);
}

/* ---- Song Builder ---- */

#song-builder {
  padding: 0 var(--page-margin);
}

.song-builder-inner {
  padding: 1.25rem 0;
}

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

.song-title-input {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 400;
  border: none;
  border-bottom: 1px solid var(--ghost);
  background: transparent;
  color: var(--ink);
  padding: 0.1em 0;
  min-width: 0;
  flex: 1;
  outline: none;
  transition: border-color 0.2s;
}

.song-title-input:focus {
  border-bottom-color: var(--ink);
}

.song-title-input::placeholder {
  color: var(--ghost);
}

.song-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
}

.song-clear-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.45rem 1rem;
  border: 1px solid var(--ghost);
  background: transparent;
  color: var(--ghost);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.song-clear-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.song-chords {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding: 4px 4px 0.5rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.song-chords::-webkit-scrollbar {
  height: 4px;
}

.song-chords::-webkit-scrollbar-track {
  background: var(--whisper);
}

.song-chords::-webkit-scrollbar-thumb {
  background: var(--ghost);
  border-radius: 2px;
}

.song-chord-item {
  position: relative;
  flex-shrink: 0;
  max-width: 140px;
  width: 140px;
  animation: songChordIn 0.3s ease both;
}

.song-chord-item .chord-svg {
  max-width: 140px;
}

.song-chord-remove {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  border: 1px solid var(--ghost);
  background: var(--paper);
  color: var(--ghost);
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  border-radius: 50%;
  transition: color 0.2s, border-color 0.2s;
  padding: 0;
  font-family: var(--font-mono);
}

.song-chord-remove:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.chord-tooltip {
  position: fixed;
  z-index: 50;
  width: 220px;
  padding: 0.5rem 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.chord-tooltip.visible {
  opacity: 1;
}

@keyframes songChordIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.song-empty {
  font-size: 0.75rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--ghost);
  padding: 1rem 0;
}

/* ---- Active Chord Stamp ---- */

.chord-card.active-chord,
.song-chord-item.active-chord {
  border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  border-radius: 0;
}

.song-chord-item.active-chord {
  position: relative;
}

.active-chord-indicator {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--whisper);
  padding: 0.3rem 0.6rem;
  border-radius: 3px;
  display: none;
}

.active-chord-indicator.visible {
  display: inline-block;
}

/* ---- Lyrics Section ---- */

.lyrics-section {
  margin-top: 1.5rem;
}

.lyrics-header {
  margin-bottom: 0.75rem;
  min-height: 1.5rem;
}

.lyrics-input {
  width: 100%;
  min-height: 100px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 0.75rem;
  border: 1px solid var(--ghost);
  background: transparent;
  color: var(--ink);
  resize: vertical;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.2s;
}

.lyrics-input:focus {
  border-color: var(--ink);
}

.lyrics-input::placeholder {
  color: var(--ghost);
}

.lyrics-display {
  margin-top: 1rem;
  line-height: 2.8;
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.lyrics-display:empty {
  display: none;
}

.lyrics-word {
  display: inline-block;
  position: relative;
  padding-top: 1.4em;
  margin-right: 0.4em;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 2px;
}

.lyrics-word:hover {
  background: var(--whisper);
}

.lyrics-word-chord {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.lyrics-line-break {
  display: block;
  height: 0.5em;
}

/* ---- Main Grid ---- */

main {
  padding: var(--grid-gap) var(--page-margin);
}

#chord-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: var(--grid-gap);
  padding: 4px;
  transition: opacity 0.15s ease;
}

#chord-grid.fading {
  opacity: 0;
}

/* ---- Chord Card ---- */

.chord-card {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0.5rem;
  animation: cardIn 0.3s ease both;
  cursor: pointer;
  border-radius: 4px;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.chord-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.chord-card:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chord-card:nth-child(1)  { animation-delay: 0.00s; }
.chord-card:nth-child(2)  { animation-delay: 0.03s; }
.chord-card:nth-child(3)  { animation-delay: 0.06s; }
.chord-card:nth-child(4)  { animation-delay: 0.09s; }
.chord-card:nth-child(5)  { animation-delay: 0.12s; }
.chord-card:nth-child(6)  { animation-delay: 0.15s; }
.chord-card:nth-child(7)  { animation-delay: 0.18s; }
.chord-card:nth-child(8)  { animation-delay: 0.21s; }
.chord-card:nth-child(9)  { animation-delay: 0.24s; }
.chord-card:nth-child(10) { animation-delay: 0.27s; }
.chord-card:nth-child(11) { animation-delay: 0.30s; }
.chord-card:nth-child(12) { animation-delay: 0.33s; }
.chord-card:nth-child(13) { animation-delay: 0.36s; }
.chord-card:nth-child(14) { animation-delay: 0.39s; }
.chord-card:nth-child(15) { animation-delay: 0.42s; }
.chord-card:nth-child(16) { animation-delay: 0.45s; }
.chord-card:nth-child(17) { animation-delay: 0.48s; }
.chord-card:nth-child(18) { animation-delay: 0.51s; }
.chord-card:nth-child(19) { animation-delay: 0.54s; }
.chord-card:nth-child(20) { animation-delay: 0.57s; }

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- SVG ---- */

.chord-svg {
  width: 100%;
  height: auto;
  max-width: 120px;
  display: block;
}

/* ---- Footer ---- */

footer {
  padding: 2rem var(--page-margin) 3rem;
  text-align: center;
}

footer p {
  margin-top: 1.5rem;
  font-size: 0.65rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ghost);
}

/* ---- Sus Button on Chord Cards ---- */

.chord-card {
  position: relative;
}

.chord-sus-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 400;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.35rem;
  border: 1px solid var(--ghost);
  background: var(--paper);
  color: var(--ghost);
  cursor: pointer;
  border-radius: 2px;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
  opacity: 0;
  pointer-events: none;
}

.chord-card:hover .chord-sus-btn {
  opacity: 1;
  pointer-events: auto;
}

.chord-sus-btn:hover {
  color: var(--ink);
  border-color: var(--ink);
}

/* ---- Variant Popup ---- */

.variant-popup-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99;
}

.variant-popup {
  position: fixed;
  z-index: 100;
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 0.75rem;
  box-shadow: 4px 4px 0 var(--ink);
  animation: popupIn 0.15s ease both;
}

.variant-popup-content {
  display: flex;
  gap: 0.25rem;
}

.variant-popup-card {
  padding: 0.5rem;
  width: 100px;
}

.variant-popup-card .chord-svg {
  max-width: 90px;
}

@keyframes popupIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---- Save Button ---- */

.song-save-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.45rem 1rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, opacity 0.2s;
}

.song-save-btn:hover {
  background: transparent;
  color: var(--ink);
}

.song-save-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---- Present Mode ---- */

.song-present-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.45rem 1rem;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.song-present-btn:hover {
  background: var(--ink);
  color: var(--paper);
}

body.present-mode header,
body.present-mode #song-builder,
body.present-mode main,
body.present-mode footer {
  display: none;
}

body.present-mode .present-view {
  min-height: 100vh;
  padding: clamp(2rem, 6vw, 5rem) var(--page-margin);
  display: flex;
  flex-direction: column;
}

.present-inner {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.present-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 2rem;
  text-align: center;
}

.present-lyrics {
  line-height: 2;
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  flex: 1;
}

.present-lyrics .lyrics-word {
  cursor: default;
  padding-top: 1.2em;
}

.present-lyrics .lyrics-word:hover {
  background: transparent;
}

.present-lyrics .lyrics-word-chord {
  font-size: 0.75rem;
  font-weight: 500;
}

.present-chords {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--ink);
}

.present-chords .chord-svg {
  max-width: 100px;
  width: 100px;
}

.present-exit-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--ghost);
  background: transparent;
  color: var(--ghost);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  align-self: center;
  margin-top: 2.5rem;
}

.present-exit-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* ---- Print ---- */

@media print {
  body {
    background: white;
    color: black;
  }

  header, footer, .filters {
    display: none;
  }

  #song-builder {
    padding: 0;
  }

  .song-clear-btn,
  .song-save-btn {
    display: none;
  }

  .song-chord-remove {
    display: none;
  }

  .song-chords {
    overflow-x: visible;
    flex-wrap: wrap;
  }

  .song-chord-item {
    animation: none;
  }

  .song-chord-item.active-chord {
    box-shadow: none;
    border: none;
  }

  .song-title-input {
    border-bottom: none;
  }

  .active-chord-indicator {
    display: none !important;
  }

  .lyrics-input {
    display: none;
  }

  .lyrics-display {
    margin-top: 0.5rem;
  }

  .lyrics-word {
    cursor: default;
  }

  .lyrics-word:hover {
    background: transparent;
  }

  main {
    padding: 0;
  }

  #chord-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
  }

  .chord-card {
    break-inside: avoid;
    animation: none;
  }

  .chord-card.active-chord {
    box-shadow: none;
    border: none;
  }

  .chord-svg {
    color: black;
  }

  /* Present mode print */
  .present-exit-btn {
    display: none;
  }

  .present-view {
    min-height: auto;
    padding: 0;
  }

  .present-chords .chord-svg {
    color: black;
  }
}
