:root {
  /* 눈 내리는 밤하늘: 밝은 모드·어두운 모드 모두 밤 배경 */
  color-scheme: dark;
  --sky-top: #0a1230;
  --sky-mid: #16265a;
  --sky-low: #2b3f7c;
  --bg: #0f1a3d;
  --card: #18264f;
  --ink: #eef3ff;
  --muted: #a7b4d8;
  --line: #2f4178;
  --red: #e5484f;
  --red-ink: #ffffff;
  --green: #4cc985;
  --chip: #223463;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --sky-top: #070d24; --card: #152147; }
}
:root[data-theme="dark"] { --sky-top: #070d24; --card: #152147; }

@font-face {
  font-family: "Jua Title";
  src: url("fonts/jua-title.woff2") format("woff2");
  font-display: swap;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1.5px 1.5px at 8% 12%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 22% 30%, #fff8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 38% 8%, #fffa 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 22%, #fff7 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 71% 14%, #fff9 50%, transparent 51%),
    radial-gradient(1px 1px at 86% 28%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 93% 6%, #fffa 50%, transparent 51%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 55%, var(--sky-low) 100%);
  background-attachment: fixed;
  background-color: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  gap: 24px;
}

.app {
  width: 100%;
  max-width: 720px;
  min-width: 0;
  padding: 20px 16px 32px;
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
/* 눈송이: 화면에 고정된 두 겹을 천천히 내린다 */
body::before, body::after {
  content: "";
  position: fixed;
  inset: -420px 0 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(3px 3px at 23px 31px, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 97px 141px, #ffffffd0 50%, transparent 51%),
    radial-gradient(4px 4px at 171px 63px, #ffffffe0 50%, transparent 51%),
    radial-gradient(2px 2px at 59px 203px, #ffffffb0 50%, transparent 51%),
    radial-gradient(3px 3px at 214px 229px, #ffffffc0 50%, transparent 51%),
    radial-gradient(2.5px 2.5px at 131px 251px, #ffffffd0 50%, transparent 51%),
    radial-gradient(2px 2px at 241px 117px, #ffffffa0 50%, transparent 51%);
  background-size: 263px 263px;
  animation: snow 14s linear infinite;
  opacity: .85;
}
body::after {
  background-size: 419px 419px;
  animation-duration: 24s;
  opacity: .5;
  filter: blur(1px);
}
@keyframes snow { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(30px, 263px, 0); } }
body::after { animation-name: snow2; }
@keyframes snow2 { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(-40px, 419px, 0); } }
@media (prefers-reduced-motion: reduce) { body::before, body::after { animation: none; } }
.app, .rail, .mbanner { position: relative; z-index: 1; }

/* 제목: 글자마다 기울기·높이가 다른 울퉁불퉁한 글씨 */
h1 {
  margin: 4px 0 0;
  font-family: "Jua Title", "Jua", -apple-system, "Apple SD Gothic Neo", sans-serif;
  font-weight: 400;
  font-size: clamp(34px, 8vw, 46px);
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: #fff;
}
h1::before { content: "🎅"; display: inline-block; margin-right: 6px; font-size: .8em; transform: rotate(-10deg); }
h1 span {
  display: inline-block;
  transform: translateY(var(--y)) rotate(var(--r));
  text-shadow: 0 3px 0 #c22a35, 0 6px 0 #7d1820, 0 10px 18px rgba(0, 0, 0, .45);
  animation: bob 3.2s ease-in-out infinite;
  animation-delay: var(--d);
}
h1 span.alt { color: #ffdede; }
h1 span.gap { width: .3em; }
@keyframes bob {
  0%, 100% { transform: translateY(var(--y)) rotate(var(--r)); }
  50% { transform: translateY(calc(var(--y) - 4px)) rotate(calc(var(--r) * -0.4)); }
}
@media (prefers-reduced-motion: reduce) { h1 span { animation: none; } }
h2 { font-size: 16px; margin: 0 0 10px; }
.top { margin-bottom: 18px; }
.muted { color: var(--muted); font-size: 14px; margin: 8px 0 0; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 14px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover:not(:disabled) { filter: brightness(0.97); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--red) 50%, transparent); outline-offset: 2px; }
.primary { background: var(--red); color: var(--red-ink); border-color: transparent; font-weight: 700; }
.ghost { background: transparent; }
.small { font-size: 14px; padding: 6px 10px; }
.big { font-size: 18px; padding: 16px 28px; border-radius: 16px; }

/* 처음 화면 */
.empty {
  background: color-mix(in srgb, var(--card) 80%, transparent);
  border: 2px dashed #5d73b4;
  border-radius: 20px;
  padding: 44px 16px;
  text-align: center;
}
.editor, .editor-only { display: none; }
body.has-photo .empty { display: none; }
body.has-photo .editor { display: block; }
body.has-photo .editor-only { display: flex; }
body.has-photo p.editor-only { display: block; }

/* 편집 화면 */
.stage-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  background: var(--card);
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
}
#stage { display: block; touch-action: none; max-width: 100%; }
.status { min-height: 1.5em; margin: 10px 0 0; font-weight: 600; }
.status[data-kind="warn"] { color: var(--red); }
.status[data-kind="ok"] { color: var(--green); }
.status[data-kind="busy"]::after { content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.sliders {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 14px 0 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}
.sliders label { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.sliders span { flex: none; min-width: 3em; }
.sliders input { flex: 1; min-width: 0; accent-color: var(--red); }
.sliders p { grid-column: 1 / -1; margin: 0; }
@media (max-width: 480px) { .sliders { grid-template-columns: 1fr; } }

/* 모자 목록 */
.picker { margin: 22px 0 0; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.tab { padding: 6px 14px; border-radius: 999px; font-size: 14px; }
.tab[aria-selected="true"] { background: var(--red); color: var(--red-ink); border-color: transparent; font-weight: 700; }
.hat-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
@media (max-width: 560px) {
  .hat-list { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
}
.hat-opt {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.25;
  padding: 6px;
  background: #e4ebfb;
  border: 2px solid transparent;
  border-radius: 14px;
}
.hat-opt[hidden] { display: none; }
.hat-opt img { width: 100%; height: 100%; object-fit: contain; }
.hat-opt[aria-pressed="true"] { border-color: var(--red); background: #fff0f0; box-shadow: 0 0 0 2px #fff6; }

.actions { gap: 10px; justify-content: flex-end; margin: 20px 0 0; }
.actions .primary { min-width: 140px; }

.privacy { margin: 22px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
footer { margin: 10px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
footer a { color: inherit; }

/* 끌어다 놓기 */
.drop-cover { display: none; }
body.dragging .drop-cover {
  display: block;
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--red) 12%, transparent);
  border: 4px dashed var(--red);
  pointer-events: none;
}

/* 광고: 넓은 화면은 양옆 160×600, 좁은 화면은 아래 320×50 (app.js 의 WIDE 와 같게) */
.rail, .mbanner { display: none; }
body.ads-on .mbanner {
  display: flex;
  justify-content: center;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
  background: var(--bg);
  min-height: 58px;
}
body.ads-on .app { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
@media (min-width: 1100px) {
  body.ads-on .mbanner { display: none; }
  body.ads-on .app { padding-bottom: 32px; }
  body.ads-on .rail { display: block; flex: 0 0 160px; position: sticky; top: 20px; height: 600px; margin-top: 20px; }
}
