/* Touch Artist — 어두운 작업실 위에 빛나는 파스텔 */

:root {
  --bg: #222222;
  --ink: #f5f4fa;
  --muted: rgba(245, 244, 250, 0.62);
  --st: env(safe-area-inset-top, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --gap: 22px;
  --lemon: #fff4a3;
  --mint: #a8f0d1;
  --coral: #ffb3a7;
  --lavender: #c9b8ff;
  --peach: #ffd9a8;
  --sky: #a6e3ff;
  --pink: #ffc6de;
  --lime: #d8f8a0;
  --rainbow: var(--lemon), var(--mint), var(--sky), var(--lavender), var(--pink), var(--coral), var(--peach), var(--lemon);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* ---------- 배경 ---------- */
.aurora,
.stars,
.vignette {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
}

.aurora {
  overflow: hidden;
}

.aurora i {
  position: absolute;
  width: 90vmax;
  height: 90vmax;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(var(--c) / 0.085), rgb(var(--c) / 0.03) 55%, transparent 100%);
  will-change: transform;
  animation: drift var(--d, 60s) ease-in-out infinite alternate;
}

.aurora i:nth-child(1) { --c: 255 244 163; left: -38vmax; top: -42vmax; --d: 58s; }
.aurora i:nth-child(2) { --c: 168 240 209; right: -42vmax; top: -24vmax; --d: 71s; animation-delay: -20s; }
.aurora i:nth-child(3) { --c: 201 184 255; left: -22vmax; bottom: -48vmax; --d: 64s; animation-delay: -35s; }
.aurora i:nth-child(4) { --c: 255 179 167; right: -32vmax; bottom: -44vmax; --d: 77s; animation-delay: -10s; }

@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(10vmax, 6vmax, 0) scale(1.12); }
  100% { transform: translate3d(-8vmax, 12vmax, 0) scale(0.94); }
}

.stars {
  opacity: 0.5;
  background-image:
    radial-gradient(1.3px 1.3px at 8% 14%, rgba(255, 255, 255, 0.7), transparent 70%),
    radial-gradient(1px 1px at 23% 62%, rgba(255, 244, 163, 0.6), transparent 70%),
    radial-gradient(1.4px 1.4px at 37% 28%, rgba(255, 255, 255, 0.55), transparent 70%),
    radial-gradient(1px 1px at 51% 83%, rgba(168, 240, 209, 0.6), transparent 70%),
    radial-gradient(1.2px 1.2px at 66% 9%, rgba(255, 255, 255, 0.6), transparent 70%),
    radial-gradient(1px 1px at 74% 47%, rgba(201, 184, 255, 0.65), transparent 70%),
    radial-gradient(1.3px 1.3px at 88% 71%, rgba(255, 255, 255, 0.55), transparent 70%),
    radial-gradient(1px 1px at 95% 24%, rgba(255, 198, 222, 0.6), transparent 70%);
  background-size: 560px 560px;
  animation: twinkle 9s ease-in-out infinite alternate;
}

.stars::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-image:
    radial-gradient(1px 1px at 15% 40%, rgba(255, 255, 255, 0.6), transparent 70%),
    radial-gradient(1.2px 1.2px at 44% 12%, rgba(166, 227, 255, 0.6), transparent 70%),
    radial-gradient(1px 1px at 62% 66%, rgba(255, 255, 255, 0.5), transparent 70%),
    radial-gradient(1.3px 1.3px at 81% 90%, rgba(255, 217, 168, 0.6), transparent 70%);
  background-size: 380px 380px;
  background-position: 120px 60px;
  animation: twinkle 7s ease-in-out -3s infinite alternate-reverse;
}

@keyframes twinkle {
  from { opacity: 0.35; }
  to { opacity: 0.85; }
}

.vignette {
  background: radial-gradient(130% 95% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.42) 100%);
}

body.no-motion .aurora i,
body.no-motion .stars,
body.no-motion .stars::after {
  animation: none;
}

/* ---------- 그림판 ---------- */
#stage {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  touch-action: none;
  cursor: crosshair;
}

#stage canvas,
#canvases {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#canvases {
  will-change: transform;
}

#refimg {
  position: absolute;
  pointer-events: none;
  opacity: 0.4;
  object-fit: contain;
}

#canvases.reveal {
  animation: reveal 1.2s ease both;
}

@keyframes reveal {
  from { opacity: 0; transform: scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* ---------- 빈 화면 안내 ---------- */
.hint {
  --c: var(--lemon);
  position: fixed;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 240px;
  height: 240px;
  margin: -120px 0 0 -120px;
  pointer-events: none;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.hint.show {
  opacity: 1;
  transform: scale(1);
  transition-duration: 1.4s;
}

.hint .orb,
.hint .wave {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  margin: -35px 0 0 -35px;
  border-radius: 50%;
}

.hint .orb {
  background: radial-gradient(circle, #fff 0 10%, var(--c) 32%, transparent 70%);
  animation: breathe 2.8s ease-in-out infinite;
}

.hint .wave {
  border: 2.5px solid var(--c);
  opacity: 0;
  animation: wave 2.8s ease-out 1.15s infinite;
}

.hint .wave.w2 {
  animation-delay: 1.5s;
}

.hint .hand {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 76px;
  height: 76px;
  margin: -8px 0 0 -37px;
  fill: rgba(255, 255, 255, 0.94);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.45));
  animation: tap 2.8s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(0.82); opacity: 0.7; }
  45% { transform: scale(1.18); opacity: 1; }
}

@keyframes wave {
  0% { transform: scale(0.6); opacity: 0; }
  10% { opacity: 0.85; }
  100% { transform: scale(3.3); opacity: 0; }
}

@keyframes tap {
  0%, 100% { transform: translate(26px, 34px) rotate(-8deg); }
  38% { transform: translate(0, 0); }
  44% { transform: translate(0, 3px) scale(0.95); }
  54% { transform: translate(0, 0); }
}

/* ---------- 작업실 입구 ---------- */
.secret {
  position: fixed;
  z-index: 3;
  top: 0;
  left: 0;
  width: calc(var(--sl) + 52px);
  height: calc(var(--st) + 52px);
  touch-action: none;
}

body.side-left .secret {
  left: auto;
  right: 0;
  width: calc(var(--sr) + 52px);
}

.secret.tap::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  animation: secretTap 0.45s ease-out forwards;
}

@keyframes secretTap {
  from { transform: scale(0.5); opacity: 1; }
  to { transform: scale(2.4); opacity: 0; }
}

/* ---------- 작업실 ---------- */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(var(--st) + 16px) calc(var(--sr) + 16px) calc(var(--sb) + 16px) calc(var(--sl) + 16px);
  background: rgba(12, 12, 16, 0.55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  touch-action: auto;
  animation: fadeIn 0.25s ease;
}

.panel[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
}

.panel-card {
  position: relative;
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: linear-gradient(160deg, rgba(60, 60, 74, 0.94), rgba(32, 32, 40, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  padding: 22px 22px 18px;
  animation: rise 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}

@keyframes rise {
  from { transform: translateY(18px) scale(0.98); opacity: 0; }
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--lemon), var(--mint), var(--lavender), var(--coral));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.panel button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.icon-btn {
  flex: none;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
}

.icon-btn svg,
.action svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.actions.two {
  grid-template-columns: repeat(2, 1fr);
  margin: 16px 0 0;
}

.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  padding: 12px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  transition: background 0.2s, transform 0.15s;
}

.action:active,
.icon-btn:active,
.seg button:active {
  transform: scale(0.96);
}

.action svg {
  width: 28px;
  height: 28px;
}

.action:nth-child(1) svg { color: var(--mint); }
.action:nth-child(2) svg { color: var(--peach); }
.action:nth-child(3) svg { color: var(--lavender); }
.action:nth-child(4) svg { color: var(--sky); }
.action.danger svg { color: var(--coral); }
.action:disabled { opacity: 0.5; }

.settings {
  display: grid;
  gap: 4px;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.row {
  display: grid;
  grid-template-columns: 116px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.row-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg button {
  flex: 1 1 auto;
  min-width: 60px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.seg button.on {
  background: linear-gradient(135deg, rgba(201, 184, 255, 0.32), rgba(168, 240, 209, 0.24));
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  box-shadow: 0 0 18px rgba(201, 184, 255, 0.25);
}

.swatches {
  display: inline-flex;
}

.swatches i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-left: -4px;
  border: 1.5px solid rgba(34, 34, 34, 0.9);
}

.swatches i:first-child {
  margin-left: 0;
}

.range-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.range-wrap input {
  flex: 1;
  height: 44px;
  accent-color: var(--lavender);
  touch-action: pan-x;
}

.width-dot {
  flex: none;
  display: block;
  border-radius: 50%;
  background: var(--lemon);
  box-shadow: 0 0 14px var(--lemon), inset 0 0 0 3px rgba(255, 255, 255, 0.35);
  margin-right: 8px;
}

.tip {
  margin: 14px 2px 2px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.tip b {
  color: var(--ink);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.thumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}

.thumb img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 16px;
  background: #222;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

.thumb span {
  font-size: 13px;
  color: var(--muted);
  padding-left: 4px;
}

.empty {
  grid-column: 1 / -1;
  margin: 30px 0;
  text-align: center;
  line-height: 1.7;
  color: var(--muted);
}

.viewer-title {
  font-size: 18px !important;
}

.viewer-img {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 18px;
  background: #222;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.toast {
  position: sticky;
  bottom: 0;
  margin: 14px auto 0;
  width: fit-content;
  max-width: 100%;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(20, 20, 26, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
}

.toast.show {
  animation: toast 2.4s ease forwards;
}

@keyframes toast {
  0% { opacity: 0; transform: translateY(8px); }
  10%, 80% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

@media (max-width: 560px) {
  .actions { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 1fr; gap: 6px; }
  .seg { flex-wrap: nowrap; }
  .seg button { flex: 1 1 0; min-width: 0; padding: 8px 4px; font-size: 14px; }
  .seg button .swatches { display: none; }
}

.noscript {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 20px;
}

@media (prefers-reduced-motion: reduce) {
  .aurora i,
  .stars,
  .stars::after,
  .trash .aura {
    animation: none;
  }
}

/* 저장 연출: 테두리를 도는 빛 액자 */
.frame {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
}

.frame::before,
.frame::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  left: 10px;
  border-radius: 22px;
  border: 3px solid transparent;
}

.frame::before {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.25), inset 0 0 40px rgba(255, 255, 255, 0.08);
}

.frame::after {
  top: 6px;
  right: 6px;
  bottom: 6px;
  left: 6px;
  border-radius: 26px;
  border-width: 6px;
  border-image: conic-gradient(from 0deg, var(--rainbow)) 1;
  filter: blur(6px);
  opacity: 0.6;
}

.frame.play {
  animation: frameIn 1.6s ease both;
}

@keyframes frameIn {
  0% { opacity: 0; transform: scale(1.04); }
  18% { opacity: 1; transform: scale(1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.995); }
}

/* 작업실 입구: 왼쪽 아래 */
.secret {
  top: auto;
  bottom: 0;
  height: calc(var(--sb) + 52px);
}

body.side-left .secret {
  left: auto;
  right: 0;
}
