:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --ink: #10130f;
  --muted: #666b61;
  --line: #d8d8d0;
  --spotify: #1ed760;
  --heat: 255, 37, 112;
  --radius: 18px;
  --shadow: 0 8px 32px rgba(16,19,15,.08);
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(24, 114, 255, .35); outline-offset: 2px; }
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(18px, env(safe-area-inset-right)) 14px max(18px, env(safe-area-inset-left));
  background: rgba(244,242,236,.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(16,19,15,.08);
}
.topbar h1 { margin: 0; font-size: clamp(20px, 4vw, 28px); line-height: 1.05; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-weight: 800; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.top-actions { display: flex; gap: 8px; align-items: center; }
main { width: min(1120px, 100%); margin: 0 auto; padding: 18px; }
.setup-card, .controls-card, .legend-card, .schedule-card {
  background: var(--panel);
  border: 1px solid rgba(16,19,15,.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.setup-card { display: grid; grid-template-columns: 1fr auto; gap: 22px; padding: 22px; margin-bottom: 14px; }
.setup-copy h2 { margin: 8px 0 8px; max-width: 700px; font-size: clamp(24px, 5vw, 40px); line-height: 1.02; letter-spacing: -.03em; }
.setup-copy p { color: var(--muted); margin: 0; max-width: 720px; line-height: 1.5; }
.setup-actions { display: flex; flex-direction: column; justify-content: center; gap: 10px; min-width: 190px; }
.pill { display: inline-flex; padding: 6px 9px; border-radius: 999px; background: #efeee8; font-weight: 800; font-size: 12px; }
.status { grid-column: 1 / -1; margin: 0; min-height: 1.2em; font-size: 14px; color: var(--muted); }
.setup-card.compact { display: block; padding: 11px 14px; }
.setup-card.compact .setup-copy, .setup-card.compact .setup-actions { display: none; }
.setup-card.compact .status { min-height: 0; }
.status.error { color: #a51e2a; font-weight: 700; }
.spotify-button, .secondary, .download-button, .icon-button {
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  font-weight: 800;
}
.spotify-button { padding: 0 16px; background: var(--spotify); color: #08140d; }
.secondary { padding: 0 14px; background: #ecebe5; color: var(--ink); }
.secondary:hover { background: #e1e0d9; }
.icon-button { width: 44px; min-width: 44px; padding: 0; background: #ecebe5; color: var(--ink); font-size: 22px; }
.danger { color: #a51e2a; }
.controls-card { display: flex; justify-content: space-between; gap: 14px; padding: 10px; margin-bottom: 12px; }
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: #efeee8; }
.segmented button { border: 0; border-radius: 9px; padding: 9px 13px; background: transparent; color: var(--muted); font-weight: 800; }
.segmented button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(16,19,15,.08); }
.legend-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 14px; margin-bottom: 14px; }
.legend-scale { display: grid; grid-template-columns: repeat(7, auto); gap: 5px; align-items: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.heat-chip { width: 19px; height: 19px; border-radius: 5px; background: rgb(var(--heat)); border: 1.5px solid rgba(16,19,15,.88); }
.h1 { opacity: .36; }.h2 { opacity: .50; }.h3 { opacity: .65; }.h4 { opacity: .82; }.h5 { opacity: .98; }
.schedule-area { display: grid; gap: 18px; }
.schedule-card { overflow: hidden; }
.schedule-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 14px; border-bottom: 1px solid rgba(16,19,15,.08); }
.schedule-card-head h2 { margin: 0; font-size: 19px; }
.schedule-kicker { margin: 0 0 2px; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.schedule-shell { position: relative; width: 100%; background: #ddd; overflow: hidden; }
.schedule-image { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.overlay-layer { position: absolute; inset: 0; }
.artist-overlay {
  position: absolute;
  border: 2px solid rgba(16,19,15,.94);
  padding: 0;
  border-radius: 2px;
  background: rgba(var(--heat), var(--alpha));
  mix-blend-mode: multiply;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
  transition: transform .12s ease, filter .12s ease;
  touch-action: manipulation;
}
.artist-overlay:hover { transform: scale(1.015); filter: saturate(1.2); z-index: 2; }
.artist-overlay:focus-visible { outline: 3px solid #fff; outline-offset: -4px; z-index: 3; }
.artist-overlay::after {
  content: attr(data-count);
  position: absolute;
  right: 3px;
  top: 3px;
  display: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(16,19,15,.88);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  line-height: 18px;
  text-align: center;
  mix-blend-mode: normal;
}
.artist-overlay:hover::after, .artist-overlay:focus-visible::after { display: block; }
footer { width: min(1120px, 100%); margin: 0 auto; padding: 6px 18px 38px; color: var(--muted); font-size: 12px; }
.donation-dialog {
  width: min(650px, calc(100vw - 24px));
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 24px;
  box-shadow: 0 28px 100px rgba(0,0,0,.34);
  color: var(--ink);
}
.donation-dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(6px); }
.donation-content { padding: clamp(22px, 5vw, 36px); }
.donation-content h2 { margin: 7px 0 20px; font-size: clamp(28px, 6vw, 42px); line-height: 1.02; letter-spacing: -.035em; }
.donation-links { display: grid; gap: 9px; }
.donation-link {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid #d7d7cf;
  border-radius: 12px;
  background: #f4f3ee;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.25;
  text-decoration: none;
}
.donation-link:hover { background: #eae9e2; border-color: #bdbdb4; }
.donation-continue {
  width: 100%;
  min-height: 54px;
  margin-top: 18px;
  padding: 12px 16px;
  border: 0;
  border-radius: 13px;
  background: #10130f;
  color: #fff;
  font-weight: 900;
}
.donation-note { margin: 9px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

dialog { border: 0; border-radius: 22px; box-shadow: 0 24px 90px rgba(0,0,0,.28); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.48); backdrop-filter: blur(4px); }
.artist-dialog, .settings-dialog { width: min(620px, calc(100vw - 22px)); max-height: min(82vh, 760px); padding: 0; overflow: auto; }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 18px 12px; background: rgba(255,255,255,.94); backdrop-filter: blur(12px); border-bottom: 1px solid #ecece7; }
.dialog-head h2 { margin: 0; font-size: 26px; }
.artist-count { margin: 18px 18px 10px; font-weight: 800; }
.song-list { padding: 0 18px 22px; display: grid; gap: 7px; }
.song-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border-radius: 11px; background: #f4f3ee; }
.song-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-row a { flex: none; color: #166c38; font-size: 12px; font-weight: 900; text-decoration: none; }
.settings-section { padding: 18px; border-bottom: 1px solid #ecece7; }
.settings-section:last-child { border-bottom: 0; }
.settings-section h3 { margin: 0 0 7px; }
.settings-section > p { margin: 0 0 12px; color: var(--muted); line-height: 1.45; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-top: 1px solid #efefe9; }
.toggle-row span { display: grid; gap: 2px; }
.toggle-row small { color: var(--muted); line-height: 1.25; }
.toggle-row input { width: 22px; height: 22px; accent-color: #111; }
.field-label { display: block; margin: 11px 0 6px; font-weight: 800; font-size: 13px; }
.text-input { width: 100%; min-height: 45px; padding: 10px 12px; border-radius: 10px; border: 1px solid #cfcfc7; background: #fff; }
.help { color: var(--muted); font-size: 12px; line-height: 1.45; }
code { padding: 2px 5px; border-radius: 5px; background: #f1f0eb; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.hidden { display: none !important; }

@media (max-width: 700px) {
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  #syncButton { display: none; }
  main { padding: 10px; }
  .setup-card { grid-template-columns: 1fr; gap: 15px; padding: 17px; }
  .setup-actions { min-width: 0; }
  .controls-card { display: grid; gap: 8px; padding: 8px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 10px 6px; }
  .legend-card { align-items: center; flex-direction: column; gap: 7px; }
  .legend-scale { width: 100%; justify-content: space-between; grid-template-columns: repeat(7, auto); }
  .schedule-card { border-radius: 14px; }
  .schedule-card-head { padding: 10px; }
  .download-button { min-height: 40px; font-size: 12px; }
  .artist-overlay::after { display: none !important; }
  .donation-dialog { width: calc(100vw - 16px); border-radius: 20px; }
  .donation-content { padding: 20px 16px 16px; }
  .donation-link { min-height: 50px; padding: 11px 12px; }
  .artist-dialog, .settings-dialog {
    width: 100vw;
    max-width: none;
    max-height: 86vh;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
  }
}

.import-button {
  border: 1px solid #111;
  border-radius: 12px;
  min-height: 44px;
  padding: 0 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}
.import-button:hover { background: #f5f4ef; }
.import-dialog {
  width: min(720px, calc(100vw - 22px));
  max-height: min(88vh, 820px);
  padding: 0;
  overflow: auto;
}
.import-body { padding: 6px 18px 20px; }
.import-step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 12px;
  padding: 18px 0;
  border-bottom: 1px solid #ecece7;
}
.import-step h3 { margin: 0 0 5px; font-size: 18px; }
.import-step p { margin: 0 0 12px; color: var(--muted); line-height: 1.45; }
.import-step-main { min-width: 0; }
.step-number {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #10130f;
  color: white;
  font-weight: 900;
}
.exportify-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 11px;
  background: #10130f;
  color: #fff;
  font-weight: 900;
  text-decoration: none;
}
.drop-zone {
  min-height: 132px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 18px;
  border: 2px dashed #9c9c92;
  border-radius: 14px;
  background: #f6f5f0;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease, transform .12s ease;
}
.drop-zone:hover, .drop-zone.dragging {
  border-color: #10130f;
  background: #efeee8;
  transform: translateY(-1px);
}
.drop-zone strong { font-size: 17px; }
.drop-zone span { color: var(--muted); font-size: 13px; }
.drop-zone input { display: none; }
.privacy-note { margin: 9px 0 0 !important; font-size: 12px; }
.import-result {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #eef8ef;
  border: 1px solid #cfe7d2;
  color: #183d21;
  font-size: 14px;
  line-height: 1.4;
}
.import-result.visible { display: block; }
.import-result.error { background: #fff0f1; border-color: #efc6ca; color: #84202b; }
.import-actions { display: flex; gap: 8px; margin-top: 14px; }
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #efeee8;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

@media (max-width: 700px) {
  .import-dialog {
    width: 100vw;
    max-width: none;
    max-height: 90vh;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
  }
  .import-body { padding: 4px 16px 20px; }
  .import-step { grid-template-columns: 30px 1fr; gap: 10px; }
  .step-number { width: 28px; height: 28px; font-size: 13px; }
  .drop-zone { min-height: 120px; }
}

/* Exportify accuracy + import feedback */
.export-steps {
  margin: 0 0 14px 18px;
  padding: 0;
  color: var(--ink);
  line-height: 1.45;
}
.export-steps li { margin: 7px 0; padding-left: 3px; }
.import-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 13px 14px;
  border: 1px solid #cfded2;
  border-radius: 12px;
  background: #f0f8f1;
}
.import-progress[hidden] { display: none; }
.import-progress > div { min-width: 0; display: grid; gap: 2px; }
.import-progress strong { font-size: 14px; }
.import-progress span:not(.spinner) { color: var(--muted); font-size: 12px; line-height: 1.35; }
.spinner {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 3px solid rgba(16,19,15,.16);
  border-top-color: #10130f;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.drop-zone.busy {
  opacity: .58;
  cursor: wait;
  transform: none;
  pointer-events: none;
}
button:disabled { cursor: default; opacity: .55; }

/* Show exactly where an imported match came from so suspect songs are easy to audit. */
.song-text { min-width: 0; display: grid; gap: 3px; }
.song-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-source { color: var(--muted); font-size: 11px; line-height: 1.25; white-space: normal; }
.song-row > a { flex: none; }

/* Private direct-Spotify gate. This is a convenience gate, not real security. */
.private-spotify-section { background: #faf9f5; }
.direct-spotify-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid #e5e4dd; }
.password-dialog {
  width: min(440px, calc(100vw - 22px));
  padding: 0;
  overflow: hidden;
}
.password-body { padding: 18px; }
.password-error { min-height: 18px; margin: 7px 0; color: #a51e2a; font-size: 13px; font-weight: 700; }
.password-submit { width: 100%; margin-top: 4px; }

@media (max-width: 700px) {
  .password-dialog {
    width: calc(100vw - 20px);
    max-width: none;
    margin: auto;
    border-radius: 18px;
  }
  .export-steps { margin-left: 16px; }
}

/* V4 mobile polish + visual Exportify guide */
.creator-credit { font-weight: 600; color: var(--muted); }
.quick-import-intro { padding: 8px 0 2px; }
.quick-import-intro p { margin: 0; color: var(--muted); font-weight: 700; }
.visual-import-steps { display: grid; gap: 16px; }
.visual-step {
  padding: 14px;
  border: 1px solid #e4e3dc;
  border-radius: 16px;
  background: #faf9f5;
}
.visual-step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.visual-step-head h3 { margin: 0; font-size: 18px; line-height: 1.2; }
.import-guide-image {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid #d8d8d0;
  background: #202227;
  margin-bottom: 10px;
}
.visual-step .exportify-link { width: 100%; }
.visual-step .drop-zone { margin-top: 0; background: #fff; }
.private-spotify-section > p { display: none; }

@media (max-width: 700px) {
  .topbar h1 { font-size: 18px; line-height: 1.15; }
  .creator-credit { display: block; margin-top: 3px; font-size: 13px; }
  .controls-card { width: 100%; padding: 7px; }
  #weekendSelector, #daySelector { display: grid; width: 100%; }
  #weekendSelector { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #daySelector { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #weekendSelector button, #daySelector button { width: 100%; min-width: 0; }
  .visual-step { padding: 10px; }
  .visual-step-head h3 { font-size: 16px; }
  .import-guide-image { max-height: 285px; }
  .download-button { min-width: 104px; }
}

/* V5 deployment + mobile save polish */
.schedule-tip {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}
.step-caption {
  margin: 2px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.upload-caption { margin: 8px 2px 10px; text-align: center; }
.compact-step { padding-bottom: 14px; }
.image-save-dialog {
  width: min(620px, calc(100vw - 20px));
  max-height: 90vh;
  padding: 0;
  overflow: auto;
}
.image-save-body { padding: 14px; }
.image-save-body p { margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.image-save-body img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid #d8d8d0;
  -webkit-touch-callout: default;
  user-select: auto;
}
@media (max-width: 700px) {
  .schedule-tip { padding: 0 2px; white-space: normal; text-align: center; }
  .image-save-dialog {
    width: 100vw;
    max-width: none;
    max-height: 92vh;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
  }
}


/* V7 legend label polish */
.relative-legend { grid-template-columns: auto repeat(5, 19px) auto; }
.relative-legend > span:first-child,
.relative-legend > span:last-child { font-weight: 700; }
@media (max-width: 700px) {
  .legend-scale.relative-legend {
    display: grid;
    grid-template-columns: auto repeat(5, 1fr) auto;
    gap: 4px;
    font-size: 10px;
    white-space: normal;
    align-items: center;
  }
  .legend-scale.relative-legend .heat-chip { width: 100%; max-width: 19px; justify-self: center; }
  .relative-legend > span:first-child { text-align: left; line-height: 1.05; }
  .relative-legend > span:last-child { text-align: right; line-height: 1.05; }
  .schedule-tip { font-size: 14px; line-height: 1.35; }
}
