@font-face {
  font-family: "Jheri Curls";
  src: url("assets/fonts/Jheri-Curls.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --page: #2b201b;
  --night: #1f1713;
  --cream: #efe3cf;
  --ink: #3a2a22;
  --blue: #3586d1;
  --blue-deep: #0d2a45;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; min-height: 100dvh; }

html {
  overscroll-behavior: none;
  background-color: #221914;
  background-image: radial-gradient(120% 90% at 50% 40%, #33261f 0%, var(--page) 55%, #221914 100%);
  min-height: 100%;
  min-height: 100dvh;
}

body {
  background: radial-gradient(120% 90% at 50% 40%, #33261f 0%, var(--page) 55%, #221914 100%);
  color: var(--cream);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  min-height: 100svh;
  height: 100dvh;
  display: grid;
  /* Equal bands above and below the app, so the stage stays vertically centered.
     The title row cannot shrink away, and a short window starts at the top instead of clipping. */
  grid-template-rows: minmax(4.4rem, 1fr) auto minmax(0, 1fr);
  justify-items: center;
  align-items: center;
  align-content: safe center;
  -webkit-font-smoothing: antialiased;
}

.site-title {
  grid-row: 1;
  align-self: center;
  justify-self: center;
  width: min(92vw, 520px);
  min-width: 0;
  margin: 0;
  padding: 0 12px 0.15em;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  pointer-events: none;
}

.site-title span {
  font-family: "Jheri Curls", "Segoe Script", "Brush Script MT", cursive;
  font-size: clamp(1.55rem, 3.3vw, 2.25rem);
  font-weight: 400;
  line-height: 1.7;
  letter-spacing: 0.01em;
  text-align: center;
  color: var(--cream);
  white-space: nowrap;
  display: inline-block;
}

body.mte-dragging {
  touch-action: none;
}

.stage {
  grid-row: 2;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  /* 312px is the title, menu, and hint. Keeping them inside the window
     avoids a scrollbar that vanishes while dragging. */
  width: min(92vw, calc((100svh - 312px) * 0.75), 520px);
  min-width: 240px;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.frame {
  --wire-tint: none;
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.collage-host {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  touch-action: none;
}

.collage {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
  background: var(--night);
  touch-action: none;
  box-shadow:
    0 28px 70px -22px rgba(0, 0, 0, 0.62),
    0 10px 28px -14px rgba(0, 0, 0, 0.38);
  container-type: inline-size;
  isolation: isolate;
}

/* ---------- top half: photo ---------- */
.photo {
  position: absolute;
  inset: 0 0 50% 0;
  background: #e9ddca;
  overflow: hidden;
}

.photo-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
  animation: fadeIn 0.5s ease;
  pointer-events: none;
}

.photo-pan {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
  cursor: grab;
}
.photo-pan.pan-x { cursor: ew-resize; }
.photo-pan.pan-y { cursor: ns-resize; }
.photo-pan.dragging { cursor: grabbing; }

.empty {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 5cqw;
  margin: 0;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.55), transparent 55%),
    repeating-linear-gradient(115deg, rgba(120, 80, 50, 0.035) 0 2px, transparent 2px 7px),
    #eadfcc;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.empty-inner {
  height: 100%;
  border: 2px dashed rgba(90, 60, 45, 0.35);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.4cqw;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.empty:hover .empty-inner,
.empty:focus-visible .empty-inner,
.photo.dragover .empty-inner {
  border-color: rgba(214, 50, 40, 0.7);
  background: rgba(255, 255, 255, 0.35);
}

.empty:focus-visible { outline: none; }

.empty-icon {
  width: 11cqw;
  height: 11cqw;
  color: #c9382d;
  margin-bottom: 1cqw;
  transition: transform 0.25s;
}
.empty:hover .empty-icon { transform: translateY(-2px) rotate(-4deg); }

.empty-title { font-weight: 700; font-size: clamp(14px, 4.6cqw, 22px); letter-spacing: -0.01em; }
.empty-sub { font-size: clamp(11px, 3cqw, 14px); opacity: 0.65; }

.replace {
  position: absolute;
  z-index: 2;
  top: 2.4cqw;
  right: 2.4cqw;
  border: 0;
  border-radius: 999px;
  padding: 0.5em 0.9em;
  font-family: inherit;
  font-weight: 600;
  font-size: clamp(10px, 2.6cqw, 12px);
  line-height: 1;
  color: #fff;
  background: rgba(30, 20, 16, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.photo:hover .replace, .replace:focus-visible { opacity: 1; }
@media (hover: none) { .replace { opacity: 0.85; } }

.drop-hint {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(13px, 4cqw, 18px);
  color: #fff;
  background: rgba(201, 56, 45, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.photo.dragover .drop-hint { opacity: 1; }

/* ---------- bottom half: night sky ---------- */
.night {
  position: absolute;
  inset: 50% 0 0 0;
  background-color: var(--night);
  background-image:
    radial-gradient(90% 70% at 50% 0%, rgba(255, 220, 170, 0.04), transparent 70%);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  overflow: hidden;
}

.night[data-bg="brown-polka"] {
  background-image: url('assets/backgrounds/brown-polka.jpg');
}

.night[data-bg="blue-sparkle-swirl"] {
  background-image: url('assets/backgrounds/blue-sparkle-swirl.png');
}

.night[data-bg="lightblue-navy-polka"] {
  background-image: url('assets/backgrounds/lightblue-navy-polka.jpg');
}

.night[data-bg="dark-teal-polka"] {
  background-image: url('assets/backgrounds/dark-teal-polka.png');
}

.night[data-bg] .sparkle {
  display: none;
}

.sparkle {
  position: absolute;
  width: var(--s);
  height: var(--s);
  color: #e8d6a8;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: twinkle var(--d) ease-in-out var(--delay) infinite;
}
.sparkle svg { display: block; width: 100%; height: 100%; }

@keyframes twinkle {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 0.45; }
}

/* ---------- rope + earbuds ---------- */
.rope {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.28)) var(--wire-tint, none);
}

.bud {
  position: absolute;
  left: 0;
  top: 0;
  width: 5.25cqw;
  height: auto;
  z-index: 4;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  will-change: transform;
  filter: drop-shadow(0 1.5px 1px rgba(0, 0, 0, 0.35)) var(--wire-tint);
  transition: filter 0.2s, scale 0.15s;
  -webkit-user-drag: none;
}
.bud.dragging { cursor: grabbing; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4)) var(--wire-tint); }
.bud.pinned { filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.45)) drop-shadow(0 0 3px rgba(255, 255, 255, 0.35)) var(--wire-tint); }
.buds-actions {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.bud-act {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  border-radius: 999px;
  padding: 7px 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  color: rgba(239, 227, 207, 0.82);
  background: rgba(255, 240, 220, 0.06);
  border: 1px solid rgba(255, 240, 220, 0.12);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.bud-act:hover { color: var(--cream); background: rgba(255, 240, 220, 0.1); }
.bud-act[aria-pressed="true"] {
  color: var(--ink);
  background: var(--cream);
  border-color: transparent;
}
.bud-act-reset { color: rgba(255, 196, 188, 0.95); }

/* ---------- music player ---------- */
.player {
  --player-light: #3e90da;
  --player-mid: var(--blue);
  --player-dark: #2f79bf;
  --player-ink: var(--blue-deep);
  --player-accent: #7cc0ff;
  position: absolute;
  left: 0;
  top: 0;
  width: 31cqw;
  aspect-ratio: 1;
  z-index: 3;
  padding: 2.6cqw;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(160deg, var(--player-light), var(--player-mid) 60%, var(--player-dark));
  color: var(--player-ink);
  --player-label-shadow: 0 1px 0 rgba(255, 255, 255, 0.22), 0 1px 3px rgba(0, 0, 0, 0.28);
  border-radius: 1.2cqw;
  box-shadow: 0 1.5cqw 3cqw -1cqw rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  cursor: grab;
  touch-action: none;
  will-change: transform;
  transition: box-shadow 0.2s, scale 0.15s;
}
.player.dragging { cursor: grabbing; scale: 1.03; box-shadow: 0 3cqw 5cqw -1cqw rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.16); }

.player-top { display: flex; align-items: center; gap: 1.4cqw; }
.art {
  width: 6cqw;
  height: 6cqw;
  border-radius: 0.8cqw;
  background: var(--player-ink);
  color: var(--player-accent);
  display: grid;
  place-items: center;
  flex: none;
}
.art svg { width: 70%; height: 70%; }
.now {
  font-size: 2.1cqw;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.92;
  text-shadow: var(--player-label-shadow);
}

.song {
  flex: 0 0 auto;
  min-height: 11.5cqw;
  max-height: 11.5cqw;
  overflow: hidden;
  position: relative;
}
.track-edit {
  display: block;
  width: 100%;
  border: 0;
  padding: 0.1cqw 0.35cqw;
  margin: 0;
  box-sizing: border-box;
  background: transparent;
  color: var(--player-ink);
  font-family: inherit;
  text-shadow: var(--player-label-shadow);
  cursor: text;
  border-radius: 0.35cqw;
  transition: background 0.15s, box-shadow 0.15s;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.track-edit::placeholder {
  color: var(--player-ink);
  opacity: 0.78;
}
.track-edit:placeholder-shown {
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.3);
}
.track-edit:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.title-edit {
  font-size: 3.7cqw;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.artist-edit {
  font-size: 2.7cqw;
  font-weight: 600;
  opacity: 0.88;
  margin-top: 0.5cqw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-edit.has-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}

.player-bottom { display: flex; align-items: center; gap: 1.6cqw; }
.play {
  width: 6.2cqw;
  height: 6.2cqw;
  min-width: 18px;
  min-height: 18px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--player-ink);
  color: #fff;
  cursor: pointer;
  flex: none;
  transition: transform 0.15s;
}
.play:hover { transform: scale(1.08); }
.play svg { width: 55%; height: 55%; grid-area: 1 / 1; }
.play .i-pause { display: none; }
.player.playing .i-play { display: none; }
.player.playing .i-pause { display: block; }

.bar { flex: 1; height: 0.7cqw; min-height: 2px; border-radius: 99px; background: color-mix(in srgb, var(--player-ink) 28%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: var(--player-ink); border-radius: inherit; }

/* ---------- control tray ---------- */
.tray {
  width: 100%;
  padding: 10px 12px 12px;
  border-radius: 16px;
  background: rgba(255, 240, 220, 0.05);
  border: 1px solid rgba(255, 240, 220, 0.1);
}

.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tray-tabs {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  min-width: 0;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
}

.tray {
  container-type: inline-size;
}

.tray-tab {
  border: 0;
  border-radius: 999px;
  flex: 1 1 auto;
  white-space: nowrap;
  padding: 7px 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
  color: rgba(239, 227, 207, 0.65);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.tray-tab:hover { color: var(--cream); }
.tray-tab[aria-selected="true"] {
  background: var(--cream);
  color: var(--ink);
}

.tray-tab-short { display: none; }

@container (max-width: 440px) {
  .tray-tab-short { display: inline; }
  .tray-tab-long { display: none; }
  .tray-tab { padding: 6px 4px; font-size: 11px; }
  .tray-export { font-size: 10px; padding: 6px 8px; }
}

.tray-reset,
.tray-export {
  flex: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 11px;
  font-family: inherit;
  font-weight: 600;
  font-size: 11px;
  line-height: 1;
  color: rgba(239, 227, 207, 0.8);
  background: rgba(255, 240, 220, 0.06);
  border: 1px solid rgba(255, 240, 220, 0.12);
  cursor: pointer;
  white-space: nowrap;
}
.tray-reset:hover,
.tray-export:hover:not(:disabled) { color: var(--cream); background: rgba(255, 240, 220, 0.1); }
.tray-export:disabled { opacity: 0.55; cursor: wait; }

.tray-panel[hidden] { display: none; }

.pick-row {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 4px;
  -webkit-overflow-scrolling: touch;
}
.pick-row::-webkit-scrollbar { display: none; }

.pick {
  flex: none;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
}
.pick-ring {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px transparent;
  transition: box-shadow 0.2s, transform 0.15s;
}
.pick:hover .pick-ring { transform: scale(1.05); }
.pick[aria-checked="true"] .pick-ring {
  box-shadow: 0 0 0 2px var(--cream), 0 0 0 4px rgba(255, 138, 122, 0.35);
}
.pick:focus-visible { outline: none; }
.pick:focus-visible .pick-ring { box-shadow: 0 0 0 2px #ff8a7a, 0 0 0 4px rgba(255, 138, 122, 0.25); }

.pick .swatch,
.pick .dot {
  width: 28px;
  height: 28px;
}

.pick-bud .pick-ring {
  background: rgba(255, 240, 220, 0.08);
}
.pick-bud img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.tray-tab:focus-visible,
.tray-reset:focus-visible,
.tray-export:focus-visible,
.bud-act:focus-visible,
.track-edit:focus-visible,
.play:focus-visible,
.replace:focus-visible { outline: 2px solid #ff8a7a; outline-offset: 2px; }

.hint { margin: 0; font-size: 12px; opacity: 0.45; text-align: center; }

.swatch {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex: none;
  border: 1px solid rgba(255, 240, 220, 0.22);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch-brown-polka { background-image: url('assets/backgrounds/brown-polka.jpg'); }
.swatch-blue-sparkle-swirl { background-image: url('assets/backgrounds/blue-sparkle-swirl.png'); }
.swatch-lightblue-navy-polka { background-image: url('assets/backgrounds/lightblue-navy-polka.jpg'); }
.swatch-dark-teal-polka { background-image: url('assets/backgrounds/dark-teal-polka.png'); }

.dot {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex: none;
  border: 1px solid rgba(255, 240, 220, 0.25);
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.12);
}

.dot-coral { background: linear-gradient(145deg, #ea7a6c, #c94538); }
.dot-mint { background: linear-gradient(145deg, #5ec9a8, #359678); }
.dot-sky { background: linear-gradient(145deg, #3e90da, #2f79bf); }
.dot-grape { background: linear-gradient(145deg, #9b7ad9, #6b4dad); }
.dot-ivory {
  background: linear-gradient(145deg, #f6f1e7, #e3d6c4);
  border-color: rgba(74, 60, 50, 0.35);
}

.seg-aspect {
  justify-content: space-evenly;
  width: 100%;
  gap: 16px;
  padding: 4px 8px 2px;
}

.pick-aspect {
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 120px;
}
.pick-ring-aspect {
  width: 56px;
  height: 56px;
  border-radius: 12px;
}
.pick-aspect[aria-checked="true"] .pick-ring {
  box-shadow: 0 0 0 2px var(--cream);
}
.pick-aspect:hover .pick-ring { transform: none; }
.aspect-thumb {
  display: block;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #e9ddca 0 48%, var(--night) 48% 100%);
  border: 1px solid rgba(255, 240, 220, 0.28);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.aspect-34 { width: 30px; height: 40px; }
.aspect-916 { width: 23px; height: 40px; }
.pick-cap {
  font-size: 9px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  color: rgba(239, 227, 207, 0.72);
  max-width: 82px;
}
.pick-aspect[aria-checked="true"] .pick-cap { color: var(--cream); }

.track-edit:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.45);
  outline-offset: 1px;
}

@media (pointer: coarse) {
  .bud { width: 7.25cqw; }
}

/* Phone: fill the visible screen, pin the menu to the bottom, and
   center the collage in the space between the title and that menu. */
@media (max-width: 820px) {
  html, body {
    min-height: 100dvh;
  }

  body {
    grid-template-rows: auto minmax(0, 1fr);
    align-content: stretch;
  }

  .site-title {
    align-self: center;
    height: auto;
    max-height: none;
    container-type: normal;
    overflow: visible;
    padding: max(8px, env(safe-area-inset-top)) 12px 0;
  }

  .site-title span {
    font-size: clamp(1.7rem, 7.4vw, 2.15rem);
    line-height: 2;
    display: inline-block;
  }

  .stage {
    height: 100%;
    min-height: 0;
    width: min(92vw, calc((100dvh - 210px) * 0.75), 520px);
    padding: 6px 16px max(8px, env(safe-area-inset-bottom));
    justify-content: flex-start;
  }

  .frame {
    margin-top: auto;
    margin-bottom: auto;
    min-height: 0;
  }
}

@media (max-width: 420px) {
  .tray { padding: 8px 10px 10px; }
  .tray-tab { padding: 6px 4px; font-size: 10px; line-height: 1.15; }
  .tray-tab-short { display: inline; }
  .tray-tab-long { display: none; }
  .tray-reset,
  .tray-export { font-size: 10px; padding: 6px 8px; }
  .pick-ring { width: 32px; height: 32px; }
  .pick .swatch, .pick .dot { width: 24px; height: 24px; }
  .pick-bud img { width: 18px; height: 18px; }
  .pick-row { gap: 8px; }
  .bud-act { font-size: 9px; padding: 6px 6px; }
  .pick-cap { font-size: 10px; max-width: none; }
  .pick-ring-aspect { width: 52px; height: 52px; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .sparkle { animation: none; }
}

body.playground .playground-banner {
  margin: 0;
  padding: 6px 12px;
  text-align: center;
  font: 12px/1.4 system-ui, sans-serif;
  background: #2a1f18;
  color: #e9ddca;
  border-bottom: 1px solid rgba(233, 221, 202, 0.15);
}

body.playground .playground-banner a {
  color: #ffc4bc;
}
