/* ═══════════════════════════════════════════════════════════════════════════
   TOKENS
════════════════════════════════════════════════════════════════════════════ */

:root {
  --ink:    #111111;
  --muted:  #8a8a8a;
  --hair:   #d8d8d8;
  --faint:  #f0efed;
  --serif:  'Crimson Text', Georgia, serif;
  --sans:   'Source Sans 3', system-ui, sans-serif;
  --radius: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESET
════════════════════════════════════════════════════════════════════════════ */

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

html, body {
  font-family: var(--sans);
  color: var(--ink);
  background: #f2f1ee;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SCREEN 1 — BUILDER
════════════════════════════════════════════════════════════════════════════ */

#screen-builder {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */

.builder-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hair);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
}

.builder-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  color: var(--ink);
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
}

/* Buttons */

.btn-primary {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--ink);
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-primary:hover:not(:disabled) { background: #2a2a2a; }
.btn-primary:disabled { background: #bbb; cursor: not-allowed; }

.btn-ghost {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.btn-ghost:hover { border-color: #aaa; background: rgba(0,0,0,0.03); }

/* Main layout */

.builder-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

.builder-section { display: flex; flex-direction: column; gap: 16px; }

.section-heading {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: -10px;
}

/* Cover section */

.cover-section {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  align-items: start;
}

.image-upload {
  width: 180px;
  height: 140px;
  border: 1.5px dashed var(--hair);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color 0.12s, background 0.12s;
}
.image-upload:hover,
.image-upload.over { border-color: #999; background: var(--faint); }

.image-upload-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  pointer-events: none;
}
.upload-label { font-size: 13px; font-weight: 500; }
.upload-sub   { font-size: 11px; }

#cover-image-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px;
}

.image-upload.filled .image-upload-empty { display: none; }
.image-upload.filled { border-style: solid; border-color: var(--hair); }

.cover-text-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

textarea,
input[type="text"] {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 9px 12px;
  width: 100%;
  resize: vertical;
  transition: border-color 0.12s;
  line-height: 1.5;
}
textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: #999;
}
textarea::placeholder,
input[type="text"]::placeholder { color: #bbb; }

/* Slots grid */

.slots-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.panel-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.slot {
  min-height: 70px;
  background: #fff;
  border: 1.5px dashed var(--hair);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
  user-select: none;
}

.slot:hover:not(.filled),
.slot.over {
  border-color: #999;
  background: var(--faint);
}

.slot.filled {
  border-style: solid;
  border-color: var(--hair);
  cursor: default;
}

.slot.filled:hover {
  border-color: #ccc;
  background: #fff;
}

.slot.dragging { opacity: 0.45; }

.slot.error { border-color: #e05252; animation: shake 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

.slot-inner {
  padding: 14px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  min-height: 70px;
}

.slot-inner svg { flex-shrink: 0; }

.slot-grip {
  color: var(--hair);
  font-size: 16px;
  cursor: grab;
  flex-shrink: 0;
  line-height: 1;
}
.slot.dragging .slot-grip { cursor: grabbing; }

.slot-title {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--ink);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-remove {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, color 0.1s;
}
.slot-remove:hover { background: #f0efed; color: var(--ink); }

/* ═══════════════════════════════════════════════════════════════════════════
   SCREEN 2 — PREVIEW TOOLBAR
════════════════════════════════════════════════════════════════════════════ */

.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hair);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 56px;
  gap: 16px;
}

.preview-hint {
  font-size: 12px;
  color: var(--muted);
}

#preview-container {
  padding: 40px 0 80px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT LAYOUT — shared between preview and @media print
   Dimensions and type match the Claude Design output exactly.
════════════════════════════════════════════════════════════════════════════ */

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 56px;
  width: 11in;
  margin: 0 auto;
  transform-origin: top center;
}

.sheet-wrap { width: 11in; }

.caption {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a7a59d;
  margin: 0 0 12px 2px;
}

/* The printed sheet */

.sheet {
  position: relative;
  width: 11in;
  height: 8.5in;
  background: #fff;
  display: flex;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.13);
}

/* Fold guide (screen only) */
.sheet::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  border-left: 1px dashed #e2e1dc;
  pointer-events: none;
}

.panel {
  width: 5.5in;
  height: 8.5in;
  padding: 0.46in 0.5in;
  display: flex;
  flex-direction: column;
}
.panel.left  { padding-right: 0.6in; }
.panel.right { padding-left:  0.6in; }

/* Song column — content-driven spacing (see CLAUDE.md) */
.col {
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: space-between;
  gap: 0.14in;
}
.col .song { flex: 0 0 auto; }

/* Overflow warning */
.col.overflow {
  outline: 2px solid #e05252;
  outline-offset: 4px;
  border-radius: 2px;
}
.col.overflow::before {
  content: '⚠ Content may be clipped when printed';
  display: block;
  font-family: var(--sans);
  font-size: 9px;
  color: #e05252;
  margin-bottom: 6px;
}

/* Song */

.song {
  display: flex;
  flex-direction: column;
}

.song-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6pt;
  margin-bottom: 5pt;
}

.song-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 13pt;
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.song-toggle {
  font-family: var(--sans);
  font-size: 6pt;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 1px solid var(--hair);
  border-radius: 999px;
  padding: 1.5pt 6pt;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.6;
  transition: color 0.1s, border-color 0.1s;
}
.song-toggle:hover { color: var(--ink); border-color: #bbb; }
.song-toggle[data-compact="true"] { color: var(--ink); border-color: #bbb; }

.song-body {
  display: flex;
  flex-direction: column;
  gap: 4pt;
  outline: none;
  border-radius: 3px;
}

.song-body:hover {
  outline: 1.5px dashed var(--hair);
  outline-offset: 3px;
}

.song-body:focus {
  outline: 1.5px solid #ccc;
  outline-offset: 3px;
}

.stanza.chorus .lyrics { font-weight: 600; }

.lyrics {
  font-family: var(--serif);
  font-size: 9.2pt;
  line-height: 1.3;
  color: var(--ink);
}

/* Collapsed repeat — simple centered italic */
.repeat-label {
  font-family: var(--serif);
  font-style: italic;
  font-size: 8.5pt;
  color: var(--muted);
  text-align: center;
  padding: 1pt 0;
}

.attribution {
  font-family: var(--sans);
  font-size: 6.8pt;
  font-weight: 400;
  letter-spacing: 0.015em;
  color: #8f8d88;
  text-align: right;
  margin-top: 6pt;
}

/* Front cover */

.cover {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.cover-logo {
  flex: 0 0 66%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cover-logo img {
  width: 2.5in;
  height: 2.5in;
  object-fit: contain;
}

.cover-logo-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--hair);
  font-family: var(--sans);
  font-size: 10pt;
}

.cover-verse {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 0.32in;
}

.verse-text {
  font-family: var(--serif);
  font-style: italic;
  font-size: 11.5pt;
  line-height: 1.5;
  color: var(--ink);
  max-width: 3.4in;
  text-wrap: pretty;
}

.verse-ref {
  font-family: var(--sans);
  font-size: 7.5pt;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 11pt;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT MEDIA
════════════════════════════════════════════════════════════════════════════ */

@page { size: 11in 8.5in; margin: 0; }

@media print {
  html, body {
    background: #fff;
    margin: 0;
    padding: 0;
  }

  /* Hide every UI element — be explicit so sticky/fixed positioning can't bleed through */
  #screen-builder,
  .preview-toolbar,
  .no-print,
  .caption { display: none !important; }

  #screen-preview { display: block !important; }
  #preview-container { padding: 0; margin: 0; }

  .stack {
    gap: 0;
    width: 11in;
    margin: 0;
    /* zoom is cleared by beforeprint JS handler; belt-and-suspenders fallback */
    zoom: 1 !important;
    transform: none !important;
  }

  .sheet-wrap { width: 11in; }

  .sheet {
    box-shadow: none;
    page-break-after: always;
    break-after: page;
    position: relative; /* ensure no sticky bleed */
  }

  .sheet::after { display: none; }

  .sheet-wrap:last-child .sheet {
    page-break-after: auto;
    break-after: auto;
  }

  .col.overflow { outline: none; }
  .col.overflow::before { display: none; }

  .song-body:hover,
  .song-body:focus { outline: none; }
}
