:root {
  --cobalt: #0a2aa8;
  --ink: #171717;
  --card: #16161a;
  --white: #ffffff;
  --muted: rgba(255, 255, 255, 0.66);
  --line: rgba(255, 255, 255, 0.16);
  --silver: linear-gradient(180deg, #ffffff 0%, #dfe2e8 42%, #9aa0ab 54%, #eef0f3 100%);
  --radius: 22px;
  --shadow: 0 22px 50px rgba(0, 0, 30, 0.32);
  font-family: Prompt, 'Noto Sans Thai', 'Leelawadee UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--white);
  background: var(--cobalt) radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, 0.1), transparent 60%) no-repeat;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.topbar { display: flex; justify-content: center; padding: 22px 16px 6px; }
.wordmark { display: inline-flex; align-items: baseline; gap: 0.5em; text-decoration: none; }
.wm-main {
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.2em;
  background: var(--silver);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.wm-sub { font-size: 15px; color: var(--muted); letter-spacing: 0.06em; }

main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 8px 16px 32px; }
.view { animation: rise 0.35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- เวที (ปก + แผ่น) ---------- */
.stage { position: relative; width: 100%; aspect-ratio: 1; container-type: inline-size; }
.stage canvas { position: absolute; display: block; height: auto; }
.stage-disc { animation: spin 3.6s linear infinite; animation-play-state: paused; }
.stage.spinning .stage-disc { animation-play-state: running; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .stage-disc { animation: none; } }

.stage-title, .stage-foot {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  transform: translateY(-50%);
  white-space: nowrap;
  pointer-events: none;
}
.stage-title {
  top: calc(140 / 1080 * 100%);
  font-weight: 700;
  font-size: calc(40 / 1080 * 100cqw);
  letter-spacing: 0.18em;
  padding-left: 0.18em;
  background: var(--silver);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stage-foot {
  top: calc(972 / 1080 * 100%);
  font-weight: 500;
  font-size: calc(18 / 1080 * 100cqw);
  letter-spacing: 0.3em;
  padding-left: 0.3em;
  color: rgba(255, 255, 255, 0.7);
}

/* ---------- ปุ่ม ---------- */
.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  border-radius: 999px;
  padding: 12px 26px;
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: #fff; color: var(--cobalt); }
.btn-ghost { background: transparent; color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.7); }
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
.btn.small { min-height: 44px; padding: 8px 18px; font-size: 14px; }
.link-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 4px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: #fff; }

/* ---------- หน้าแรก ---------- */
.home { display: grid; justify-items: center; gap: 8px; text-align: center; }
.home-stage { width: min(560px, 100%); }
.home-copy { max-width: 460px; }
.home-copy h1 { font-size: clamp(24px, 5vw, 32px); font-weight: 600; margin: 0 0 8px; }
.home-copy p { color: var(--muted); margin: 0 0 22px; line-height: 1.6; }
.home-copy .btn { min-width: 220px; }

.home-description { color: var(--muted); margin: 0 0 22px; line-height: 1.6; font-size: 15px; max-width: 320px; }

/* ---------- ขั้นตอน ---------- */
.stepper { list-style: none; display: flex; justify-content: center; align-items: center; gap: 8px; margin: 6px 0 4px; padding: 0; }
.stepper li {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  color: rgba(255, 255, 255, 0.75);
}
.stepper .sep { width: 18px; height: 1.5px; background: rgba(255, 255, 255, 0.3); border: 0; border-radius: 0; }
.stepper .done { background: rgba(255, 255, 255, 0.18); border-color: transparent; color: #fff; }
.stepper .current { background: #fff; border-color: #fff; color: var(--cobalt); }

.step-title { text-align: center; font-size: clamp(20px, 4vw, 24px); font-weight: 600; margin: 12px 0 20px; }
.eyebrow { text-align: center; color: var(--muted); margin: 6px 0 16px; font-size: 15px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; align-items: center; }
@media (min-width: 880px) {
  .workspace { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 40px; }
}
.visual { width: 100%; max-width: 560px; margin: 0 auto; }
.panels { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; width: 100%; max-width: 460px; margin: 0 auto; }

.cropper {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
  touch-action: none;
}
.cropper canvas { width: 100%; height: 100%; display: block; cursor: grab; }
.dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  transition: background-color 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: #fff; background: rgba(255, 255, 255, 0.05); }
.dropzone strong { color: #fff; font-size: 18px; font-weight: 600; }

.panel { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.panel-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 10px;
}
.panel-label .value { font-weight: 400; color: rgba(255, 255, 255, 0.5); }
.panel > * + .panel-label, .panel > * + div > .panel-label, #bandRow + .panel-label { margin-top: 20px; }
.hint { font-size: 13px; color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
.error { color: #ffb8c4; font-size: 13px; margin: 8px 0 0; }
.error:empty { display: none; }

.zoom-row { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 18px; }
.zoom-row input { flex: 1; accent-color: #fff; }
[data-panel='cover'] .btn { margin-top: 14px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  transition: transform 0.15s;
}
.swatch:hover { transform: scale(1.06); }
.swatch[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: 14px;
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.chip .dot { width: 18px; height: 18px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25); }
.chip[aria-pressed='true'] { background: #fff; border-color: #fff; color: var(--ink); font-weight: 600; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); }
.segmented button {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 0;
  border-radius: 999px;
  padding: 10px;
  min-height: 42px;
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.segmented button[aria-checked='true'] { background: #fff; color: var(--cobalt); font-weight: 600; }

textarea, input[type='url'], .linkbox input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.5;
}
textarea { resize: none; }
textarea:focus, input:focus { outline: none; border-color: #fff; }
::placeholder { color: rgba(255, 255, 255, 0.4); }

.song-form { display: flex; gap: 8px; }
.song-form input { min-width: 0; }
.songs { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.songs:empty { display: none; }
.song, .song-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  text-align: left;
}
.song-btn { border: 0; font: inherit; cursor: pointer; }
.song-btn:hover { background: rgba(255, 255, 255, 0.12); }
.song-btn.playing { background: rgba(255, 255, 255, 0.2); }
.song img, .song-btn img { width: 64px; height: 36px; object-fit: cover; border-radius: 6px; flex: none; background: #000; }
.song .meta, .song-btn .meta { min-width: 0; flex: 1; }
.song .t, .song-btn .t { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .a, .song-btn .a { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song .x {
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.song .x:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.nav { display: flex; justify-content: center; gap: 12px; margin-top: 28px; }
.nav .btn { min-width: 140px; }

/* ---------- หน้าสุดท้าย ---------- */
.final-actions { display: grid; gap: 12px; }
.final-actions .panel-label { margin: 0; }
.final-actions .hint { margin: 0; }
.share-block { display: grid; gap: 10px; margin-top: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.linkbox { display: flex; gap: 8px; }
.linkbox input { min-width: 0; font-size: 14px; }
.final-secondary { display: flex; justify-content: space-between; }

/* ---------- หน้าผู้รับ ---------- */
.letter #letterText { margin: 0; font-size: 20px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.screen { aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000; }
.screen iframe, .screen #yt { width: 100%; height: 100%; display: block; border: 0; }
.now { text-align: center; font-weight: 600; margin: 16px 0 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.now-sub { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }

.wheel {
  position: relative;
  width: min(220px, 72%);
  aspect-ratio: 1;
  margin: 18px auto 6px;
  border-radius: 50%;
  background: #fff;
  color: var(--cobalt);
}
.wheel-top, .wheel-bottom { position: absolute; left: 0; right: 0; text-align: center; font-weight: 700; font-size: 15px; }
.wheel-top { top: 9%; }
.wheel-bottom { bottom: 9%; }
.wheel-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--cobalt);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.wheel-btn:disabled { opacity: 0.3; cursor: default; }
.wheel-prev { left: 5%; }
.wheel-next { right: 5%; }
.wheel-center {
  position: absolute;
  inset: 31%;
  border: 0;
  border-radius: 50%;
  background: var(--cobalt);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s;
}
.wheel-center:hover { transform: scale(1.04); }
.wheel-center:focus-visible, .wheel-btn:focus-visible { outline-color: var(--cobalt); }
.tracklist { margin-top: 14px; }

.missing { text-align: center; display: grid; justify-items: center; gap: 8px; padding-top: 60px; }
.missing p { color: var(--muted); margin: 0 0 16px; }

.foot { text-align: center; color: rgba(255, 255, 255, 0.5); font-size: 12px; padding: 16px 16px 24px; }
