@font-face {
  font-family: 'SpotifyMixUI';
  src: url('assets/fonts/SpotifyMixUI-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SpotifyMixUI';
  src: url('assets/fonts/SpotifyMixUI-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SpotifyMixUITitle';
  src: url('assets/fonts/SpotifyMixUITitle-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SpotifyMixUITitle';
  src: url('assets/fonts/SpotifyMixUITitle-Extrabold.woff2') format('woff2');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-app: #0d0d0d;
  --bg-panel: #161616;
  --bg-card-ui: #1f1f1f;
  --border: #2c2c2c;
  --text-ui: #f3f3f3;
  --text-muted: #9e9e9e;
  --accent: #1ed760;
  --accent-hover: #2ce46e;
  --card-text: #FCA19E;
  --swirl-hue: 0deg;
  --swirl-sat: 100%;
  --text-scale: 1;
  --stage-scale: 0.4;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text-ui);
  font-family: 'SpotifyMixUI', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.brand svg,
.brand .brand-logo {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: block;
}

.brand h1 {
  margin: 0;
  font-family: 'SpotifyMixUITitle', sans-serif;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-body::-webkit-scrollbar {
  width: 6px;
}
.sidebar-body::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

.section-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Segmented format toggle */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-app);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  gap: 4px;
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.segmented button.active {
  background: #282828;
  color: #fff;
}

/* Dropzone */
.dropzone {
  border: 1.5px dashed #3b3b3b;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  background: #121212;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: #172019;
}

.dropzone p {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.dropzone small {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.slider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-row.full {
  grid-column: 1 / -1;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Inputs */
.field-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ranked-input {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 6px;
}

.ranked-input span {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
}

input[type="text"] {
  width: 100%;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: #fff;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

input[type="text"]:focus {
  border-color: var(--accent);
}

.two-col-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Color swatches */
.color-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, border-color 0.12s;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.active {
  border-color: #fff;
}

.color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 8px;
}

.color-picker-wrap input[type="color"] {
  border: none;
  background: none;
  width: 22px;
  height: 22px;
  padding: 0;
  cursor: pointer;
}

.color-picker-wrap code {
  font-size: 12px;
  color: var(--text-ui);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #141414;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  font-family: 'SpotifyMixUITitle', sans-serif;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

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

.btn-primary:active {
  transform: scale(0.99);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.btn-row.two-up {
  grid-template-columns: 1fr 1fr;
}

.btn-ghost {
  background: #222;
  color: var(--text-ui);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-ghost:hover {
  background: #2d2d2d;
}

.btn-mini {
  background: #222;
  color: var(--text-ui);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-mini:hover {
  background: #2d2d2d;
  border-color: #444;
}

.btn-icon {
  padding: 7px 10px;
  line-height: 1;
  flex-shrink: 0;
}

/* Presets controls */
.preset-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.preset-row select {
  flex: 1;
  min-width: 0;
  background: #111;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: #fff;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.preset-row select:focus {
  border-color: var(--accent);
}

.preset-save-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

/* Modal */
.modal {
  padding: 0;
  border: 1px solid #353535;
  border-radius: 14px;
  background: #181818;
  color: var(--text-ui);
  width: min(480px, calc(100vw - 32px));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-family: 'SpotifyMixUITitle', sans-serif;
  font-size: 16px;
  font-weight: 800;
}

.modal-desc {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.modal-card textarea {
  width: 100%;
  background: #101010;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #fff;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
  outline: none;
}

.modal-card textarea:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Preview Area */
.preview-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, #1d1d1d 0%, #0b0b0b 75%);
  overflow: hidden;
  padding: 56px 24px 24px;
}

.preview-toolbar {
  position: absolute;
  top: 14px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  pointer-events: none;
}

.preview-toolbar > * {
  pointer-events: auto;
}

.hint-pill {
  background: rgba(24, 24, 24, 0.88);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
  backdrop-filter: blur(8px);
}

.stage-outer {
  position: relative;
  display: block;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.stage-scaler {
  transform-origin: top left;
  position: absolute;
  top: 0;
  left: 0;
}

/* =========================================================
   THE ACTUAL 1080x1920 / 1080x1080 SPOTIFY WRAPPED CARD
   Pixel-matched to source/metrics.json
   ========================================================= */
.wrapped-card {
  position: relative;
  width: 1080px;
  height: 1920px;
  overflow: hidden;
  background: #1F1F1F;
  color: var(--card-text);
  font-family: 'SpotifyMixUI', sans-serif;
  user-select: none;
}

.wrapped-card.square {
  width: 1080px;
  height: 1080px;
}

.card-plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: hue-rotate(var(--swirl-hue)) saturate(var(--swirl-sat));
  pointer-events: none;
}

/* Cover art square */
.card-cover-frame {
  position: absolute;
  left: 162px;
  top: 106px;
  width: 756px;
  height: 756px;
  overflow: hidden;
  background: #111;
}

.wrapped-card.square .card-cover-frame {
  left: 284px;
  top: 54px;
  width: 514px;
  height: 514px;
}

.card-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform-origin: center center;
}

/* Editable elements highlight subtly on hover in editor, never in export */
.wrapped-card [contenteditable="true"] {
  outline: none;
  border-radius: 4px;
  transition: background 0.12s;
  user-select: text;
  cursor: text;
}

.wrapped-card [contenteditable="true"]:hover {
  background: rgba(255, 255, 255, 0.07);
}

.wrapped-card [contenteditable="true"]:focus {
  background: rgba(255, 255, 255, 0.13);
}

.wrapped-card.exporting [contenteditable="true"] {
  background: transparent !important;
}

/* ---- STORY LAYOUT (1080x1920) ---- */
.card-col {
  position: absolute;
  top: 1083px;
}

.card-col-artists {
  left: 81px;
  width: 446px;
}

.card-col-songs {
  left: 565px;
  width: 392px;
}

.card-heading {
  margin: 0 0 26px 0;
  font-family: 'SpotifyMixUI', sans-serif;
  font-weight: 400;
  font-size: calc(30.5px * var(--text-scale));
  line-height: calc(35px * var(--text-scale));
  letter-spacing: 0;
  white-space: nowrap;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.card-list li {
  display: flex;
  align-items: baseline;
  height: calc(55px * var(--text-scale));
  font-family: 'SpotifyMixUI', sans-serif;
  font-weight: 700;
  font-size: calc(39.5px * var(--text-scale));
  line-height: calc(55px * var(--text-scale));
  letter-spacing: -0.01em;
}

.card-list .rank {
  flex: 0 0 calc(37px * var(--text-scale));
  display: inline-block;
}

.card-list .item-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stats row (Story only) */
.card-stat {
  position: absolute;
  top: 1503px;
}

.card-stat-minutes {
  left: 81px;
  width: 446px;
}

.card-stat-genre {
  left: 565px;
  width: 446px;
}

.card-stat .card-heading {
  margin-bottom: 22px;
}

.card-stat-value {
  font-family: 'SpotifyMixUITitle', sans-serif;
  font-weight: 800;
  font-size: calc(74px * var(--text-scale));
  line-height: calc(80px * var(--text-scale));
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer (Story) */
.card-footer-logo {
  position: absolute;
  left: 68px;
  top: 1783px;
  width: 104px;
  height: 104px;
  fill: currentColor;
}

.card-footer-url {
  position: absolute;
  right: 66px;
  top: 1810px;
  font-family: 'SpotifyMixUITitle', sans-serif;
  font-weight: 700;
  font-size: calc(50px * var(--text-scale));
  line-height: calc(56px * var(--text-scale));
  letter-spacing: -0.01em;
  text-align: right;
  white-space: nowrap;
}

/* Square top-right logo (hidden in story) */
.card-square-logo {
  display: none;
  position: absolute;
  left: 995px;
  top: 25px;
  width: 59px;
  height: 59px;
  fill: currentColor;
}

/* ---- SQUARE LAYOUT OVERRIDES (1080x1080) ---- */
.wrapped-card.square .card-col {
  top: 622px;
}

.wrapped-card.square .card-col-artists {
  left: 109px;
  width: 432px;
}

.wrapped-card.square .card-col-songs {
  left: 565px;
  width: 436px;
}

.wrapped-card.square .card-heading {
  font-size: calc(44px * var(--text-scale));
  line-height: calc(48px * var(--text-scale));
  margin-bottom: 28px;
  letter-spacing: 0;
}

.wrapped-card.square .card-list li {
  height: calc(64px * var(--text-scale));
  font-size: calc(46.5px * var(--text-scale));
  line-height: calc(64px * var(--text-scale));
  letter-spacing: -0.01em;
}

.wrapped-card.square .card-list .rank {
  flex: 0 0 calc(44px * var(--text-scale));
}

.wrapped-card.square .card-stat,
.wrapped-card.square .card-footer-logo,
.wrapped-card.square .card-footer-url {
  display: none;
}

.wrapped-card.square .card-square-logo {
  display: block;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #222;
  color: #fff;
  border: 1px solid #3a3a3a;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive mobile / narrow viewport */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  .sidebar {
    height: auto;
    order: 2;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .preview-pane {
    order: 1;
    min-height: 70vh;
    padding: 58px 16px 20px;
  }
}
