:root {
  --bg: #fff3dc;
  --bg2: #ffe6bd;
  --card: #fffdf8;
  --text: #5a3a22;
  --muted: #a07a5a;
  --orange: #ff9f43;
  --orange-d: #f08a24;
  --coral: #ff6f61;
  --coral-d: #e85a4c;
  --yellow: #ffd166;
  --yellow-d: #f2b93b;
  --peach: #ffc9a8;
  --line: #f3d9b0;
  --radius: 26px;
  --shadow: 0 6px 0 rgba(200, 130, 60, 0.25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  font-family: "Jua", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, #fff9ea 0, transparent 40%),
    radial-gradient(circle at 90% 90%, var(--bg2) 0, transparent 45%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.4;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.screen { display: none; }
.screen.active { display: block; animation: pop 0.3s ease; }
@keyframes pop {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* 첫 화면 */
.hero { text-align: center; padding: 28px 0 22px; }
.hero h1 {
  margin: 0 0 8px;
  font-size: 46px;
  letter-spacing: 1px;
  color: var(--coral);
  text-shadow: 0 3px 0 var(--yellow);
}
.hero p { margin: 0; color: var(--muted); font-size: 18px; }

.menu { display: grid; gap: 16px; }

.menu-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px 18px;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  text-align: left;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
}
.menu-card:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(200, 130, 60, 0.25); }
.menu-card strong { display: block; font-size: 26px; font-weight: 400; }
.menu-card small { font-size: 15px; opacity: 0.95; }
.c-roulette { background: var(--orange); }
.c-ladder { background: var(--coral); }
.c-coin { background: #f2b93b; }

.menu-icon {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.92);
  position: relative;
}
.icon-roulette {
  background-image: conic-gradient(#ff9f43 0 25%, #ffd166 0 50%, #ff6f61 0 75%, #ffc9a8 0);
  border: 5px solid #fff;
}
.icon-roulette::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: #fff;
}
.icon-ladder {
  background-image:
    linear-gradient(var(--coral), var(--coral)),
    linear-gradient(var(--coral), var(--coral)),
    linear-gradient(var(--coral), var(--coral)),
    linear-gradient(var(--coral), var(--coral));
  background-repeat: no-repeat;
  background-size: 6px 70%, 6px 70%, 28px 6px, 28px 6px;
  background-position: 18px 50%, 40px 50%, 18px 38%, 18px 62%;
}
.icon-coin {
  background: radial-gradient(circle at 35% 30%, #fff1b3, #ffd166 60%, #f2b93b);
  border: 5px solid #fff;
}

/* 공통 */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.topbar h2 { margin: 0; font-size: 28px; color: var(--coral); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 3px solid var(--line);
}
.card.center { text-align: center; }
.card h3 { margin: 0 0 12px; font-size: 20px; color: var(--orange-d); }

.btn {
  font: inherit;
  font-size: 18px;
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  cursor: pointer;
  color: #fff;
  background: var(--orange);
  box-shadow: 0 5px 0 var(--orange-d);
  transition: transform 0.1s, box-shadow 0.1s, opacity 0.2s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--orange-d); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.big { width: 100%; padding: 18px 20px; font-size: 24px; margin-top: 10px; }
.btn.primary { background: var(--coral); box-shadow: 0 5px 0 var(--coral-d); }
.btn.primary:active { box-shadow: 0 1px 0 var(--coral-d); }
.btn.secondary { background: var(--yellow); color: var(--text); box-shadow: 0 5px 0 var(--yellow-d); }
.btn.secondary:active { box-shadow: 0 1px 0 var(--yellow-d); }
.btn.back { background: var(--peach); color: var(--text); box-shadow: 0 4px 0 #e9a57b; padding: 10px 16px; font-size: 16px; }
.btn-row { display: grid; gap: 4px; }

.result {
  margin: 16px 0 0;
  min-height: 1.6em;
  text-align: center;
  font-size: 26px;
  color: var(--coral);
  word-break: keep-all;
}
.hint { margin: 0 0 12px; text-align: center; color: var(--muted); }

/* 편집기 */
.editor { display: grid; gap: 10px; }
.item-row { display: flex; gap: 8px; align-items: center; }
.item-row .dot {
  flex: none; width: 14px; height: 14px; border-radius: 50%;
}
.item-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 18px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 3px solid var(--line);
  background: #fff;
  color: var(--text);
  outline: none;
}
.item-row input:focus { border-color: var(--orange); }
.item-row .del {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--peach);
  color: var(--text);
  font: inherit; font-size: 22px;
  cursor: pointer;
}
.item-row .del:disabled { opacity: 0.4; cursor: not-allowed; }
.add-btn { margin-top: 4px; }
.limit-note { margin: 0; text-align: center; color: var(--muted); font-size: 14px; }

/* 룰렛 */
.wheel-wrap {
  position: relative;
  width: min(100%, 360px);
  margin: 8px auto 0;
  aspect-ratio: 1;
}
#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 6px 0 rgba(200, 130, 60, 0.3);
  transition: transform 4.2s cubic-bezier(0.12, 0.7, 0.1, 1);
}
.pointer {
  position: absolute;
  top: -10px; left: 50%;
  width: 0; height: 0;
  margin-left: -17px;
  border-left: 17px solid transparent;
  border-right: 17px solid transparent;
  border-top: 34px solid var(--coral-d);
  z-index: 2;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.15));
}

/* 사다리 */
.ladder-row {
  display: grid;
  gap: 0;
}
.ladder-row button, .ladder-row .slot {
  margin: 0 3px;
  min-width: 0;
}
.ladder-row button {
  font: inherit;
  font-size: 15px;
  border: 0;
  border-radius: 16px;
  padding: 10px 2px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}
.ladder-row button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15); }
.ladder-row.bottom .slot {
  text-align: center;
  font-size: 14px;
  padding: 8px 2px;
  border-radius: 16px;
  background: #fff;
  border: 3px solid var(--line);
  word-break: break-all;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.ladder-row.bottom .slot.hit {
  background: var(--yellow);
  border-color: var(--orange);
  transform: scale(1.08);
}
#ladder {
  display: block;
  width: 100%;
  height: 340px;
  margin: 6px 0;
}

/* 동전 (옆에서 본 모습) */
.coin-stage {
  height: 280px;
  position: relative;
  perspective: 900px;
  perspective-origin: 50% 82.5%;
  overflow: hidden;
  border-radius: 20px;
  background: linear-gradient(#fff4d6, #ffe9bd);
}
.ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 40px;
  background: #e9b27a;
  border-top: 6px solid #d99a5f;
}
.coin-shadow {
  position: absolute;
  left: 50%; top: 236px;
  width: 150px; height: 12px;
  margin-left: -75px;
  border-radius: 50%;
  background: rgba(110, 60, 20, 0.35);
  transform-origin: center;
}
.coin-pos {
  position: absolute;
  left: 50%; top: 151px;
  width: 160px; height: 160px;
  margin-left: -80px;
  transform-style: preserve-3d;
}
.coin {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateX(90deg);
}
.slice, .face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
.slice { background: #e0a52d; }
.slice.alt { background: #f2c04a; }
.face {
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: 38px;
  color: #a86a12;
  border: 8px solid #f2b93b;
  box-shadow: inset 0 0 0 6px #ffe39a;
}
.face.front { background: radial-gradient(circle at 35% 30%, #fff3bd, #ffd166 70%); transform: translateZ(9px); }
.face.back { background: radial-gradient(circle at 35% 30%, #ffe0cc, #ffb48a 70%); transform: rotateY(180deg) translateZ(9px); color: #9a4a22; border-color: #f08a24; box-shadow: inset 0 0 0 6px #ffd0b0; }
.tally { margin: 10px 0 0; color: var(--muted); }

/* 사다리 추가 */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 22px;
}
.stepper .label { width: 56px; white-space: nowrap; color: var(--muted); }
.stepper b { min-width: 36px; text-align: center; font-weight: 400; font-size: 32px; color: var(--coral); }
.stepper .unit { width: 28px; white-space: nowrap; color: var(--muted); }
.step-btn {
  width: 56px; height: 56px;
  border: 0; border-radius: 50%;
  font: inherit; font-size: 30px; line-height: 1;
  color: #fff; background: var(--orange);
  box-shadow: 0 5px 0 var(--orange-d);
  cursor: pointer;
}
.step-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--orange-d); }
.step-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ladder-board { position: relative; }
.ladder-cover {
  position: absolute;
  inset: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: repeating-linear-gradient(45deg, #ffd9a0 0 14px, #ffe8c2 14px 28px);
  color: var(--text);
  font-size: 20px;
  text-align: center;
}
.ladder-cover.open { display: none; }
.ladder-row.bottom .slot.win.shown { background: #ffe08a; border-color: var(--coral); color: var(--coral-d); }
.btn[hidden] { display: none; }

@media (max-width: 380px) {
  .hero h1 { font-size: 38px; }
  .menu-card strong { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  #wheel { transition-duration: 0.01s; }
  .screen.active { animation: none; }
}

.coin-badge {
  width: 96px; height: 96px;
  margin: 16px auto 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  border: 6px solid #f2b93b;
  box-shadow: inset 0 0 0 5px #ffe39a, 0 5px 0 #d9a02a;
  animation: badge-pop 0.4s ease;
}
.coin-badge[hidden] { display: none; }
.coin-badge.front { background: radial-gradient(circle at 35% 30%, #fff3bd, #ffd166 70%); color: #a86a12; }
.coin-badge.back { background: radial-gradient(circle at 35% 30%, #ffe0cc, #ffb48a 70%); color: #9a4a22; border-color: #f08a24; box-shadow: inset 0 0 0 5px #ffd0b0, 0 5px 0 #d27420; }
@keyframes badge-pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 캐릭터 */
body::before {
  content: "";
  position: fixed; inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(circle, rgba(255, 180, 160, 0.35) 0 5px, transparent 6px),
    radial-gradient(circle, rgba(255, 215, 120, 0.4) 0 4px, transparent 5px);
  background-size: 70px 70px, 70px 70px;
  background-position: 0 0, 35px 35px;
}
.ch { width: 64px; height: 64px; flex: none; overflow: visible; }
.ch.big { width: 96px; height: 96px; }
.bob { animation: bob 2.4s ease-in-out infinite; }
.bob.d1 { animation-delay: -0.8s; }
.bob.d2 { animation-delay: -1.6s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.hero-chars { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin-bottom: 8px; }
.menu-icon { display: flex; align-items: center; justify-content: center; width: 76px; height: 76px; background: #fffaf2; border: 4px solid rgba(255, 255, 255, 0.9); }
.menu-icon .ch { width: 62px; height: 62px; }
.menu-icon::after { display: none; }
.say { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; text-align: left; }
.bubble {
  position: relative;
  flex: 1;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 18px;
  word-break: keep-all;
}
.bubble::before {
  content: "";
  position: absolute;
  left: -11px; top: 50%;
  margin-top: -8px;
  border: 8px solid transparent;
  border-left: 0;
  border-right-color: var(--line);
}
.stage-ch { position: absolute; bottom: 34px; width: 58px; height: 58px; z-index: 2; }
.stage-ch.left { left: 10px; }
.stage-ch.right { right: 10px; }
.stage-ch.jump { animation: jump 0.5s ease-in-out 2; }
@keyframes jump { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-22px); } }
@media (prefers-reduced-motion: reduce) { .bob, .stage-ch.jump { animation: none; } }

img.ch { object-fit: contain; }

/* ---------- 시안 A 적용: 첫 화면 ---------- */
.hero h1 { color: #e2513f; text-shadow: 0 4px 0 var(--yellow); font-size: 50px; }
.hero p { color: #7a5638; font-size: 17px; }
.home-say { background: #fff; border: 3px solid var(--line); border-radius: 22px; padding: 12px 14px; margin: 0 0 18px; }
.home-say .ch { width: 44px; height: 44px; }
.home-say .bubble { border: 0; padding: 0; background: none; font-size: 17px; }
.home-say .bubble::before { display: none; }
.menu { gap: 14px; }
.menu-card { color: var(--text); padding: 16px; border-radius: 26px; gap: 14px; }
.menu-card strong { font-size: 25px; }
.menu-card small { font-size: 15px; color: #7a5638; opacity: 1; }
.c-roulette { background: #ffd9a8; box-shadow: 0 6px 0 #f0b46e; }
.c-ladder { background: #ffc8c0; box-shadow: 0 6px 0 #f0958a; }
.c-coin { background: #ffe7a0; box-shadow: 0 6px 0 #ecc35a; }
.menu-card:active { box-shadow: 0 2px 0 rgba(200, 130, 60, 0.35); }
.menu-icon { width: 60px; height: 60px; border: 4px solid #fff; background: #fffaf2; }
.icon-wheel { background: conic-gradient(#ff9f43 0 25%, #ffd166 0 50%, #ff8a7a 0 75%, #ffc9a8 0); }
.icon-lines { width: 34px; height: 34px; }
.icon-face { background: radial-gradient(circle at 35% 30%, #fff3bd, #ffd166 70%); font-size: 15px; color: #8a5a10; }
.home-foot { margin: 22px 0 0; text-align: center; font-size: 14px; color: #8a6a4a; }

/* ---------- 첫 화면: 스크롤 없이 한 화면에 맞추기 ---------- */
.app:has(#screen-home.active) { padding-top: 0; padding-bottom: 0; }
#screen-home.active {
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
  padding: clamp(10px, 2.5vh, 28px) 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 18px);
  overflow: hidden;
}
#screen-home .hero { padding: 0; }
#screen-home .hero-chars { margin-bottom: clamp(2px, 0.8vh, 8px); }
#screen-home .hero-chars .ch { width: clamp(40px, 7.5vh, 66px); height: clamp(40px, 7.5vh, 66px); }
#screen-home .hero-chars .ch.big { width: clamp(58px, 11vh, 96px); height: clamp(58px, 11vh, 96px); }
#screen-home .hero h1 { font-size: clamp(32px, 6.2vh, 54px); margin-bottom: clamp(2px, 0.6vh, 8px); }
#screen-home .hero p { font-size: clamp(14px, 2vh, 18px); }
#screen-home .home-say { margin: 0; padding: clamp(8px, 1.4vh, 12px) 14px; }
#screen-home .home-say .ch { width: clamp(32px, 5vh, 44px); height: clamp(32px, 5vh, 44px); }
#screen-home .home-say .bubble { font-size: clamp(14px, 2vh, 17px); }
#screen-home .menu { gap: clamp(10px, 1.8vh, 16px); }
#screen-home .menu-card { padding: clamp(10px, 1.7vh, 16px) 16px; }
#screen-home .menu-icon { width: clamp(42px, 7vh, 60px); height: clamp(42px, 7vh, 60px); }
#screen-home .icon-lines { width: 56%; height: 56%; }
#screen-home .menu-card strong { font-size: clamp(19px, 3vh, 25px); }
#screen-home .menu-card small { font-size: clamp(13px, 1.8vh, 15px); }
#screen-home .home-foot { margin: 0; font-size: clamp(12px, 1.6vh, 14px); }

/* PC처럼 넓고 낮은 화면: 메뉴를 가로 3칸으로 */
@media (min-width: 760px) {
  .app:has(#screen-home.active) { max-width: 980px; }
  #screen-home .home-say { max-width: 520px; width: 100%; margin: 0 auto; box-sizing: border-box; }
  #screen-home .menu { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
  #screen-home .menu-card {
    flex-direction: column;
    justify-content: center;
    text-align: center;
    padding: clamp(16px, 3vh, 28px) 16px;
    gap: clamp(8px, 1.6vh, 14px);
  }
  #screen-home .menu-icon { width: clamp(56px, 11vh, 96px); height: clamp(56px, 11vh, 96px); }
  #screen-home .menu-text { display: flex; flex-direction: column; gap: 4px; }
  #screen-home .menu-card strong { font-size: clamp(22px, 3.6vh, 30px); }
}
