:root {
  --bg: #ffffff;
  --bg-2: #f1f2f5;
  --ink: #16181d;
  --muted: #7b808b;
  --line: #e3e5ea;
  --accent: #1f5eff;
  --title: 'Black Han Sans', 'Gowun Dodum', sans-serif;
  --body: 'Gowun Dodum', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 55%, var(--bg-2) 100%); color: var(--ink); font-family: var(--body); min-height: 100vh; -webkit-font-smoothing: antialiased; }
body.dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; max-width: 1120px; margin: 0 auto; }
.home-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.present-btn { border: 0; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 18px; font-weight: 700; font-size: 16px; }
.present-btn:hover { background: #2c3039; }

.main { max-width: 1120px; margin: 0 auto; padding: 0 16px 40px; }
.title-row { text-align: center; display: grid; gap: 6px; justify-items: center; }
h1 { margin: 0; font-family: var(--title); font-weight: 400; font-size: clamp(26px, 5vw, 40px); }
.name-field input { border: 0; border-bottom: 2px dashed var(--line); background: transparent; text-align: center; font: 700 18px var(--body); color: var(--muted); width: 220px; padding: 2px 4px; }
.name-field input:focus { outline: none; border-bottom-color: var(--accent); color: var(--ink); }

/* ---------- 무대 ---------- */
.workspace { height: calc(100vh - 72px); height: calc(var(--app-h, 100dvh) - var(--top-h, 72px)); min-height: 300px; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1 1 auto; min-height: 120px; perspective: 1400px; touch-action: pan-y; cursor: grab; overflow: hidden; }
.phone-wrap { position: absolute; left: 50%; top: calc(50% + 16px); transform: translate(-50%, -50%) translate(var(--sx, 0px), var(--sy, 0px)) scale(var(--fit, 1)); transition: transform .9s cubic-bezier(.45,.05,.25,1); }
.phone { position: relative; width: var(--w); height: var(--h); transform-style: preserve-3d; transition: transform-origin .9s cubic-bezier(.45,.05,.25,1); }
.phone.hinge-v.folded { transform-origin: 25% 50%; }
.leaf { position: absolute; transform-style: preserve-3d; transition: transform .9s cubic-bezier(.45,.05,.25,1); }
.phone.hinge-v .leaf-b { transform-origin: 0% 50% 6px; }
.phone.hinge-h .leaf-b { transform-origin: 50% 0% 6px; }
.phone.hinge-v.folded .leaf-b { transform: rotateY(-180deg); }
.phone.hinge-h.folded .leaf-b { transform: rotateX(180deg); }
.phone.spin.hinge-v .leaf-b { animation: foldv 7s ease-in-out infinite; }
.phone.spin.hinge-h .leaf-b { animation: foldh 7s ease-in-out infinite; }
@keyframes foldv { 0%, 12% { transform: rotateY(0); } 32%, 58% { transform: rotateY(-180deg); } 78%, 100% { transform: rotateY(0); } }
@keyframes foldh { 0%, 12% { transform: rotateX(0); } 32%, 58% { transform: rotateX(180deg); } 78%, 100% { transform: rotateX(0); } }
.face-ref { position: absolute; inset: 0; visibility: hidden; pointer-events: none; }
.face-ref.front { transform: translateZ(6px); }
.face-ref.back { transform: rotateY(180deg) translateZ(6px); }
.face-in { position: absolute; width: var(--w); height: var(--h); }
.front-in { background: #050505; padding: 7px; border-radius: var(--r); }
.back-in { background: linear-gradient(150deg, color-mix(in srgb, var(--back) 88%, white), var(--back) 45%, color-mix(in srgb, var(--back) 85%, black)); }
.phone.spin { animation: spin 7s linear infinite; }
@keyframes spin { from { transform: rotateY(-25deg) rotateX(6deg); } 50% { transform: rotateY(335deg) rotateX(6deg); } to { transform: rotateY(695deg) rotateX(6deg); } }
.slice { position: absolute; inset: 0; background: linear-gradient(90deg, #8d929b, #e7eaee 20%, #a6abb3 50%, #eef0f3 80%, #8d929b); border: 1px solid rgba(0,0,0,.08); }
.slice:first-child { background: var(--frame); }
.edges { position: absolute; width: var(--w); height: var(--h); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.face.front { transform: translateZ(6px); background: #050505; }
.face.back { transform: rotateY(180deg) translateZ(6px); background: var(--back); box-shadow: inset 0 0 0 3px var(--frame); }
.screen { width: 100%; height: 100%; border-radius: calc(var(--r) - 7px); color: #fff; padding: 22% 10% 0; text-align: left;
  background: radial-gradient(circle at 20% 80%, #7b5cff 0, transparent 45%), radial-gradient(circle at 85% 30%, #00c2ff 0, transparent 45%), radial-gradient(circle at 60% 95%, #ff6fae 0, transparent 40%), linear-gradient(160deg, #10163a, #1c2a6b); }
.clock { margin: 0; font-size: 52px; font-weight: 300; letter-spacing: -.02em; line-height: 1; }
.date { margin: 6px 0 0; font-size: 14px; opacity: .85; }
.layer { position: absolute; inset: 0; }
.part { position: absolute; transform: translate(-50%, -50%); cursor: grab; touch-action: none; }
.part svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 2px 2px rgba(0,0,0,.25)); }
.brand { position: absolute; left: 0; right: 0; bottom: 9%; text-align: center; font-weight: 700; letter-spacing: .12em; font-size: 13px; color: color-mix(in srgb, var(--back) 55%, #777); margin: 0; mix-blend-mode: multiply; }
.cover-screen { position: absolute; left: 8%; right: 8%; top: 5%; height: 38%; border-radius: 18px; background: radial-gradient(circle at 30% 70%, #3b2f7a 0, transparent 55%), #0b0b0d; box-shadow: inset 0 0 0 2px rgba(255,255,255,.08); color: #fff; display: grid; place-items: center; }
.cover-screen p { margin: 0; font-size: 26px; font-weight: 300; }
.cover-screen.side { left: 3%; right: auto; width: 44%; top: 2.5%; height: 95%; border-radius: calc(var(--r) - 6px); }
.brand.half { left: 50%; }
.crease { position: absolute; background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), rgba(0,0,0,.25), transparent); pointer-events: none; z-index: 1; }
.crease.v { top: 0; bottom: 0; left: calc(50% - 4px); width: 8px; }
.crease.h { left: 0; right: 0; top: calc(50% - 4px); height: 8px; background: linear-gradient(180deg, transparent, rgba(255,255,255,.18), rgba(0,0,0,.25), transparent); }
.crease.soft { opacity: .5; }

.edges { position: absolute; inset: 0; transform-style: preserve-3d; }
.edge-part { position: absolute; cursor: grab; touch-action: none; }
.edge-part > span { position: absolute; inset: 0; display: block; }
.btn-part { border-radius: 4px; border: 1px solid rgba(0,0,0,.25); }
.port { background: #0b0b0b; border-radius: 4px; border: 1px solid #666; }
.spen { background: linear-gradient(90deg, #333, #555); border-radius: 5px; border: 1px solid #111; }
.antenna { background: linear-gradient(90deg, #9aa0a8, #e3e6ea, #9aa0a8); border-radius: 4px; }
.antenna::after { content: ''; position: absolute; width: 12px; height: 12px; border-radius: 50%; background: #444; }
.antenna.top::after, .antenna.bottom::after { left: -2px; }
.antenna.top::after { top: -6px; }
.antenna.bottom::after { bottom: -6px; }
.antenna.left::after, .antenna.right::after { top: -2px; }
.antenna.left::after { left: -6px; }
.antenna.right::after { right: -6px; }
.strap svg { width: 100%; height: 100%; display: block; }
.strap.left svg { transform: rotate(90deg); }
.strap.right svg { transform: rotate(-90deg); }
.strap.top svg { transform: rotate(180deg); }

.trash { position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 20px); background: #fff1f0; color: #d33; border: 2px dashed #f3a6a2; border-radius: 999px; padding: 8px 16px; font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; }
.trash.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 컨트롤 ---------- */
.controls { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin: 4px 0 10px; flex: 0 0 auto; }
.seg { display: flex; background: var(--bg-2); border-radius: 999px; padding: 4px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.1); font-weight: 700; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.reset { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; color: var(--muted); }
.tray-hint { text-align: center; color: var(--muted); font-size: 15px; margin: 0 0 6px; flex: 0 0 auto; }
.tray-hint b { color: var(--ink); }
.tray { display: flex; gap: 12px; overflow-x: auto; padding: 6px 4px 12px; scroll-snap-type: x proximity; flex: 0 0 auto; }
.tray-item { flex: 0 0 auto; width: 112px; border: 0; background: #fff; border-radius: 22px; padding: 14px 8px 10px; box-shadow: 0 4px 16px rgba(0,0,0,.08); display: grid; justify-items: center; gap: 8px; font-size: 14px; scroll-snap-align: start; touch-action: pan-x; user-select: none; -webkit-user-select: none; }
.tray-item:hover { transform: translateY(-2px); }
.tray-icon { height: 60px; display: grid; place-items: center; }
.tray-icon svg { max-width: 64px; max-height: 60px; width: auto; height: 60px; }
.tray-item:focus-visible, .seg button:focus-visible, .swatch:focus-visible, .present-btn:focus-visible, .reset:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 0; }
footer { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: 8px; }

.ghost { position: fixed; left: 0; top: 0; transform: translate(-50%, -50%) scale(1.05); pointer-events: none; z-index: 50; opacity: 0; filter: drop-shadow(0 8px 14px rgba(0,0,0,.3)); }
.ghost svg { width: 100%; height: auto; display: block; }
.ghost.show { opacity: .95; }

/* ---------- 발표 ---------- */
.present { position: fixed; inset: 0; z-index: 60; background: radial-gradient(circle at 50% 40%, #1b2036 0%, #05060a 70%); color: #fff; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 24px 16px; perspective: 1400px; overflow: hidden; }
.present[hidden] { display: none; }
.present-phone { transform: scale(var(--pfit, .72)); transform-style: preserve-3d; margin-top: -40px; }
.slide { text-align: center; max-width: 720px; position: absolute; left: 16px; right: 16px; bottom: 96px; margin: 0 auto; }
.slide.in { animation: rise .6s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.slide .big { margin: 0; font-family: var(--title); font-size: clamp(34px, 7vw, 64px); line-height: 1.1; background: linear-gradient(90deg, #fff, #b9c8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.slide .small { margin: 10px 0 0; font-size: clamp(16px, 2.6vw, 20px); color: #c4c9d8; }
.slide em { font-style: normal; font-size: 12px; color: #8a90a2; }
.present-ad { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); width: min(728px, calc(100% - 32px)); }
.present-ad[hidden] { display: none; }
.present-ad .ad-slot { margin: 0 auto; color: #c4c9d8; }
.present-actions { position: absolute; right: 16px; bottom: 20px; display: flex; gap: 8px; }
.present-actions button { border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08); color: #fff; border-radius: 999px; padding: 10px 16px; }
.present-actions button:focus-visible { outline: 3px solid #8fb0ff; outline-offset: 2px; }

@media (max-width: 640px) {
  .top { padding: 8px 12px; }
  .main { padding: 0 12px 32px; }
  h1 { font-size: 22px; }
  .name-field input { font-size: 15px; }
  .controls { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; gap: 8px; margin: 2px -12px 6px; padding: 2px 12px; scrollbar-width: none; }
  .controls > * { flex: 0 0 auto; }
  .seg button { padding: 5px 10px; font-size: 14px; }
  .swatch { width: 24px; height: 24px; }
  .tray-hint { font-size: 13px; }
  .tray-hint .long { display: none; }
  .tray { gap: 8px; padding-bottom: 8px; }
  .tray-item { width: 84px; padding: 10px 4px 8px; font-size: 12px; gap: 4px; border-radius: 18px; }
  .tray-icon { height: 42px; }
  .tray-icon svg { height: 42px; }
  .present-phone { margin-top: -120px; }
  .slide { bottom: 80px; }
}
@media (max-height: 620px) {
  .tray-hint { display: none; }
  .title-row { grid-auto-flow: column; justify-content: center; align-items: baseline; gap: 10px; }
  .title-row h1 { font-size: 20px; white-space: nowrap; }
  .name-field input { width: 130px; font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { .phone.spin, .phone.spin .leaf-b { animation-duration: 30s; } * { transition: none !important; } }
