:root {
  --bg: #ffffff;
  --accent: #c81e3a;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #fff;
  color: #171717;
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  background: #fff;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.5s ease;
}

.view.active {
  position: relative;
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.view-inner {
  width: 100%;
  max-width: 720px;
  padding: 40px 20px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 32px;
  color: #767676;
  font-size: 14px;
}

/* ---------- View 1: customize ---------- */

.stage {
  width: min(78vw, 420px);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06), 0 30px 70px -25px rgba(0,0,0,0.35);
  position: relative;
}

#vinylCanvas {
  cursor: pointer;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
}

.controls {
  margin-top: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 999px;
  background: #f3f3f1;
  border: 1px solid #e0e0dd;
  color: #171717;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.upload-btn:hover { background: #eaeae7; border-color: #cfcfcb; }

.mode-row {
  display: flex;
  gap: 8px;
}

.mode-btn {
  padding: 7px 18px;
  border-radius: 999px;
  border: 1px solid #171717;
  background: transparent;
  color: #171717;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover, .mode-btn.active {
  background: #171717;
  color: #fff;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-settings {
  width: 100%;
}

.color-options {
  display: flex;
  align-items: center;
  gap: 12px;
}

#marbleColor1, #marbleColor2 {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
}
#marbleColor1::-webkit-color-swatch-wrapper, #marbleColor2::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
#marbleColor1::-webkit-color-swatch, #marbleColor2::-webkit-color-swatch { border: 2px solid rgba(0,0,0,0.2); border-radius: 50%; }

.remix-btn {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid #171717;
  background: transparent;
  color: #171717;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.remix-btn:hover, .remix-btn:active { background: #171717; color: #fff; }

.color-label {
  font-size: 13px;
  color: #767676;
  margin-right: 4px;
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
  transition: transform 0.15s, border-color 0.15s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.selected { border-color: #171717; }

#colorPicker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: none;
  cursor: pointer;
  overflow: hidden;
}
#colorPicker::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
#colorPicker::-webkit-color-swatch { border: 2px solid rgba(0,0,0,0.2); border-radius: 50%; }

.primary-btn {
  margin-top: 4px;
  padding: 14px 48px;
  border-radius: 999px;
  border: none;
  background: #171717;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 24px -8px rgba(0,0,0,0.35); }
.primary-btn:active { transform: translateY(0); }

/* ---------- View 2: player ---------- */

#view-player {
  align-items: flex-start;
  background-color: #fff;
}

#view-player .view-inner {
  position: relative;
  z-index: 1;
  min-height: 100svh;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

.player-background {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #fff;
  background-position: 0 0;
  background-repeat: no-repeat;
}

.player-stage {
  position: relative;
  width: min(88vw, 640px);
  aspect-ratio: 1536 / 1024;
  margin: auto;
  flex: 0 0 auto;
}

.player-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.vinyl-mount {
  position: absolute;
  left: var(--platter-cx, 40.48%);
  top: var(--platter-cy, 48.13%);
  width: var(--platter-dw, 63.46%);
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  overflow: hidden;
}

.vinyl-mount canvas {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 50% 50%;
}

.vinyl-mount.spinning canvas {
  animation: spin var(--spin-seconds, 1.35s) linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tonearm-pivot {
  position: absolute;
  inset: 0;
  transform-origin: var(--pivot-x, 78.55%) var(--pivot-y, 22.23%);
  transform: rotate(var(--parked-angle, -30deg));
  transition: transform 0.9s cubic-bezier(.36,1.4,.4,1);
  z-index: 5;
  pointer-events: none;
}

.tonearm-pivot.playing {
  transform: rotate(var(--playing-angle, 2deg));
}

.stick-img {
  position: absolute;
  left: var(--pivot-x, 78.55%);
  top: var(--pivot-y, 22.23%);
  width: var(--stick-w, 40%);
  aspect-ratio: 1 / 1;
  transform: translate(-81.26%, -17.3%);
  pointer-events: none;
  user-select: none;
}

/* FLIP transition ghost */
.vinyl-flip {
  position: fixed;
  z-index: 50;
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.7s cubic-bezier(.5,0,.2,1);
  will-change: transform;
}

.player-controls {
  margin-top: 0;
  flex: 0 0 auto;
}

#backBtn {
  position: fixed;
  top: max(20px, calc(env(safe-area-inset-top) + 12px));
  right: max(20px, calc(env(safe-area-inset-right) + 16px));
  z-index: 10;
  font-size: large;
}

#view-player.has-custom-background .ghost-btn,
#view-player.has-custom-background .dl-btn {
  background: #fff;
}

#view-player.has-custom-background .ghost-btn:hover,
#view-player.has-custom-background .ghost-btn:active,
#view-player.has-custom-background .dl-btn:hover,
#view-player.has-custom-background .dl-btn:active {
  background: #171717;
}

.background-upload-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.background-button-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.background-button-row .ghost-btn {
  padding-right: 16px;
  padding-left: 16px;
}

.ghost-btn {
  padding: 10px 22px;
  border-radius: 999px;
  background: transparent;
  border: 1px solid #171717;
  color: #171717;
  font-size: 13px;
  cursor: pointer;
  margin-bottom: 0;
  transition: background 0.15s, color 0.15s;
}
.ghost-btn:hover, .ghost-btn:active { background: #171717; color: #fff; }
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.download-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.download-label {
  margin: 0;
  text-align: center;
}

.download-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.dl-btn {
  padding: 11px 20px;
  border-radius: 999px;
  border: 1px solid #171717;
  background: transparent;
  color: #171717;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dl-btn:hover, .dl-btn:active { background: #171717; color: #fff; }
.dl-btn:disabled { opacity: 0.5; cursor: default; }

.download-hint {
  min-height: 16px;
  margin: 0;
  color: #888;
  font-size: 12px;
}

/* ---------- Photo crop editor ---------- */

body.photo-editor-open { overflow: hidden; }

.photo-editor {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  font-family: "Noto Sans KR", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
}

.photo-editor[hidden] { display: none; }

.photo-editor-card {
  width: min(100%, 540px);
  max-height: calc(100svh - 32px);
  overflow-y: auto;
  padding: 28px;
  border-radius: 28px;
  background: #fff;
  text-align: center;
}

.photo-editor-card h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.photo-editor-help {
  margin: 8px 0 20px;
  color: #777;
  font-size: 13px;
}

.photo-crop-stage {
  position: relative;
  width: min(76vw, 440px);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 20px;
  background: #111;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.photo-crop-stage:active { cursor: grabbing; }

#photoEditorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.photo-crop-line {
  position: absolute;
  inset: 4.45%;
  border: 2px solid #fff;
  border-radius: 50%;
  pointer-events: none;
}

.photo-zoom-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
  color: #777;
  font-size: 12px;
}

.photo-zoom-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  cursor: pointer;
}

.photo-zoom-row input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 1px;
  border: 0;
  background: #171717;
}

.photo-zoom-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7.5px;
  border: 0;
  border-radius: 50%;
  background: #171717;
}

.photo-zoom-row input[type="range"]::-moz-range-track {
  width: 100%;
  height: 1px;
  border: 0;
  background: #171717;
}

.photo-zoom-row input[type="range"]::-moz-range-progress {
  height: 1px;
  background: #171717;
}

.photo-zoom-row input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: #171717;
}

.background-editor-card {
  width: min(100%, 780px);
}

.background-crop-stage {
  position: relative;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 18px;
  background: #111;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.background-crop-stage:active { cursor: grabbing; }

#backgroundEditorCanvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.background-crop-line {
  position: absolute;
  inset: 0;
  border: 2px solid #fff;
  border-radius: inherit;
  pointer-events: none;
}

.photo-editor-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.photo-cancel-btn,
.photo-apply-btn {
  min-width: 108px;
  padding: 12px 24px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.photo-cancel-btn {
  border: 1px solid #171717;
  background: #fff;
  color: #171717;
}

.photo-apply-btn {
  border: 1px solid #171717;
  background: #171717;
  color: #fff;
}

@media (max-width: 600px) {
  #view-customize {
    align-items: flex-start;
  }

  #view-customize .view-inner {
    position: relative;
    min-height: 100svh;
    padding: max(24px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  }

  #view-customize .stage {
    position: relative;
    width: min(74vw, 330px);
    margin-top: auto;
    margin-bottom: auto;
  }

  #view-customize .controls {
    margin-top: 0;
    padding-top: 0;
    gap: 18px;
    flex: 0 0 auto;
  }

  .mode-row {
    gap: 12px;
  }

  .mode-btn {
    padding: 10px 24px;
    font-size: 15px;
  }

  .color-settings {
    min-height: 118px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }

  .color-row {
    width: 100%;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 12px;
  }

  .color-label {
    margin-right: 0;
    font-size: 14px;
  }

  #solidColorRow .color-options {
    width: 232px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  #solidColorRow .swatches {
    display: contents;
  }

  .swatch {
    width: 32px;
    height: 32px;
  }

  #colorPicker,
  #marbleColor1,
  #marbleColor2 {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
  }

  .marble-options {
    justify-content: center;
  }

  .primary-btn {
    margin-top: 0;
    padding: 14px 48px;
    font-size: 16px;
  }

  .photo-editor {
    align-items: flex-end;
    padding: 12px;
  }

  .photo-editor-card {
    padding: 22px 16px max(20px, env(safe-area-inset-bottom));
    border-radius: 24px;
  }

  .photo-crop-stage {
    width: min(84vw, 440px);
  }

  .title { font-size: 20px; }
}

@media (max-width: 600px) and (max-height: 740px) {
  #view-customize .stage {
    width: min(60vw, 240px);
  }

  #view-customize .controls {
    padding-top: 0;
    gap: 12px;
  }

  .color-settings {
    min-height: 104px;
  }

  .color-row {
    gap: 8px;
  }

  #solidColorRow .color-options {
    width: 208px;
  }

  .swatch,
  #colorPicker,
  #marbleColor1,
  #marbleColor2 {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }
}
