/* 렌덤게임 - 코인게임방 테마
   모든 화면은 창 높이 안에 들어가도록 만든다 (페이지 스크롤 없음). */
:root {
  --bg: #120b2e;
  --panel: #1d1247;
  --panel-2: #2a1a66;
  --text: #ffffff;
  --sub: #c9c2ff;
  --pink: #ff3da5;
  --pink-d: #a3196a;
  --cyan: #26e6ff;
  --yellow: #ffe14d;
  --yellow-d: #b39a1f;
  --ink: #1a0a2e;
  --radius: 12px;
  --gap: 12px;
  --btn-h: 60px;
  --cell-h: 46px;
  --pixel: "Press Start 2P", "Courier New", monospace;
  --display: "Black Han Sans", "Malgun Gothic", sans-serif;
  --body: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }

body {
  overflow: hidden;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(38, 230, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(38, 230, 255, 0.07) 1px, transparent 1px);
  background-size: 26px 26px;
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
}

button { font-family: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

/* ---------- 화면 뼈대: 창 높이에 딱 맞춤 ---------- */
.app {
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
}
.screen { display: none; }
.screen.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: pop 0.3s ease;
}
.screen-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
@keyframes pop {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- 첫 화면 ---------- */
#screen-home { justify-content: space-between; gap: var(--gap); }
.scoreboard {
  display: flex;
  justify-content: space-between;
  font-family: var(--pixel);
  font-size: 11px;
  letter-spacing: 1px;
}
.sb-yellow { color: var(--yellow); }
.sb-cyan { color: var(--cyan); }
.sb-pink { color: var(--pink); }

.hero { text-align: center; }
.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(44px, 8vh, 64px);
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 6px var(--pink), 0 0 18px var(--pink), 4px 4px 0 #3b1a8f;
}
.insert-coin {
  margin: 14px 0 0;
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 2px;
  color: var(--yellow);
  animation: blink 1.1s steps(1) infinite;
}
.hero-sub { margin: 8px 0 0; font-size: 15px; color: var(--sub); }

.menu { display: grid; gap: var(--gap); }
.menu-card {
  --c: var(--pink);
  --glow: rgba(255, 61, 165, 0.45);
  --c-soft: #ff8ccb;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: clamp(72px, 11vh, 92px);
  padding: 10px 16px;
  border: 3px solid var(--c);
  border-radius: var(--radius);
  background: var(--panel);
  color: #fff;
  text-align: left;
  box-shadow: 0 0 14px var(--glow), inset 0 0 12px var(--glow);
  transition: transform 0.1s, box-shadow 0.15s;
}
.menu-card:hover { box-shadow: 0 0 22px var(--glow), inset 0 0 16px var(--glow); }
.menu-card:active { transform: scale(0.98); }
.c-pink { --c: var(--pink); --glow: rgba(255, 61, 165, 0.45); --c-soft: #ff8ccb; }
.c-cyan { --c: var(--cyan); --glow: rgba(38, 230, 255, 0.4); --c-soft: #8ff0ff; }
.c-yellow { --c: var(--yellow); --glow: rgba(255, 225, 77, 0.35); --c-soft: #fff0a3; }

.menu-icon {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--c);
  display: flex;
  align-items: center;
  justify-content: center;
}
.menu-icon svg { width: 36px; height: 36px; }
.menu-text { display: flex; flex-direction: column; gap: 4px; flex-grow: 1; }
.menu-stage { font-family: var(--pixel); font-size: 10px; color: var(--c-soft); }
.menu-title { font-family: var(--display); font-size: 26px; line-height: 1.1; }
.menu-tag { font-family: var(--pixel); font-size: 10px; color: var(--yellow); }

.coin-panel {
  padding: 14px 16px;
  border-radius: 14px;
  background: #2b2f3a;
  border: 4px solid #4a5163;
  display: flex;
  align-items: center;
  gap: 16px;
}
.coin-slot-box { display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: var(--pixel); font-size: 8px; color: #c6ccd8; }
.coin-slot {
  width: 54px;
  height: 66px;
  border-radius: 8px;
  background: #1a1d24;
  border: 3px solid #6b7385;
  display: flex;
  align-items: center;
  justify-content: center;
}
.coin-slot-hole { width: 8px; height: 38px; border-radius: 4px; background: #000; box-shadow: 0 0 8px var(--pink); }
.coin-panel-text { display: flex; flex-direction: column; gap: 8px; font-family: var(--pixel); font-size: 11px; line-height: 1.6; }
.coin-panel-text span:first-child { animation: blink 1.1s steps(1) infinite; color: var(--yellow); }
.coin-panel-sub { font-family: var(--body); font-size: 14px; color: #c6ccd8; }

/* ---------- 공통 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: var(--gap); flex-shrink: 0; }
.topbar h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 28px;
  color: #fff;
  text-shadow: 0 0 8px var(--pink);
}
.back {
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid var(--cyan);
  border-radius: 8px;
  background: transparent;
  color: var(--cyan);
  font-size: 15px;
}

.card {
  background: var(--panel);
  border: 2px solid #3b2a85;
  border-radius: 16px;
  padding: 14px;
  text-align: center;
}
.card-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.card-side {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;   /* 혹시 넘치면 이 상자 안에서만 */
}
.card h3 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 19px;
  font-weight: 400;
  color: var(--cyan);
}
.note { margin: 8px 0 0; font-size: 13px; color: var(--sub); }

.big-btn {
  display: block;
  width: 100%;
  min-height: var(--btn-h);
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: var(--pink);
  color: var(--ink);
  font-family: var(--display);
  font-size: 26px;
  box-shadow: 0 6px 0 var(--pink-d), 0 0 18px rgba(255, 61, 165, 0.55);
  transition: transform 0.1s, box-shadow 0.1s;
  flex-shrink: 0;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--pink-d), 0 0 10px rgba(255, 61, 165, 0.5); }
.big-btn:disabled { opacity: 0.5; pointer-events: none; }
.big-btn.alt { background: var(--yellow); box-shadow: 0 6px 0 var(--yellow-d), 0 0 18px rgba(255, 225, 77, 0.45); }
.big-btn.alt:active { box-shadow: 0 2px 0 var(--yellow-d); }

.btn-row { display: flex; gap: var(--gap); flex-shrink: 0; }
.btn-row .big-btn { font-size: 22px; padding: 10px 8px; }

.result {
  flex-shrink: 0;
  padding: 8px 12px;
  min-height: 52px;
  border-radius: 10px;
  background: #0b0620;
  border: 2px solid var(--cyan);
  box-shadow: inset 0 0 14px rgba(38, 230, 255, 0.25);
  color: var(--cyan);
  font-family: var(--display);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.result.done {
  animation: bounce 0.5s ease;
  color: var(--yellow);
  border-color: var(--yellow);
  box-shadow: inset 0 0 14px rgba(255, 225, 77, 0.3), 0 0 14px rgba(255, 225, 77, 0.4);
}
@keyframes bounce {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ---------- 항목 편집 (2칸 그리드) ---------- */
.items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.items .add-btn, .items .note { grid-column: 1 / -1; }
.item-row { display: flex; gap: 4px; }
.item-row input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  border: 2px solid #4a3aa0;
  border-radius: 10px;
  background: #0b0620;
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  outline: none;
}
.item-row input::placeholder { color: #8f86c9; }
.item-row input:focus { border-color: var(--cyan); box-shadow: 0 0 10px rgba(38, 230, 255, 0.4); }
.item-row button {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 2px solid var(--pink);
  border-radius: 10px;
  background: transparent;
  color: var(--pink);
  font-size: 24px;
  line-height: 1;
}
.add-btn {
  min-height: 44px;
  border: 2px dashed var(--cyan);
  border-radius: 10px;
  background: transparent;
  color: var(--cyan);
  font-size: 15px;
}
.add-btn:disabled { opacity: 0.4; }
.items .note { margin: 0; }

/* ---------- 룰렛: 남는 공간에 맞춰 정사각형 ---------- */
.wheel-area {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wheel-wrap {
  position: relative;
  width: min(100cqw, 100cqh, 520px);
  aspect-ratio: 1 / 1;
  padding: 10px;
}
.wheel-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 5px #2a1a66, 0 0 0 8px var(--yellow), 0 0 26px rgba(255, 225, 77, 0.45);
}
.pointer {
  position: absolute;
  top: 0;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 26px solid var(--yellow);
  z-index: 2;
  filter: drop-shadow(0 0 6px rgba(255, 225, 77, 0.8));
}

/* ---------- 사다리 ---------- */
.stepper-group { display: grid; gap: 8px; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 8px; }
.stepper-label { width: 76px; text-align: left; font-size: 15px; color: var(--sub); }
.step-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 3px 0 var(--yellow-d);
}
.step-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--yellow-d); }
.step-btn:disabled { opacity: 0.35; pointer-events: none; }
.step-val { min-width: 80px; font-family: var(--display); font-size: 22px; color: var(--yellow); }
.step-input {
  width: 54px;
  height: 40px;
  margin-right: 4px;
  border: 2px solid #4a3aa0;
  border-radius: 8px;
  background: #0b0620;
  color: var(--yellow);
  font-family: var(--display);
  font-size: 20px;
  text-align: center;
}

.ladder-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
}
.ladder {
  flex: 1 0 auto;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ladder-row { display: flex; flex-shrink: 0; }
.ladder-row > * { flex: 1 1 0; min-width: 0; margin: 0 2px; }
.canvas-wrap { position: relative; flex: 1; min-height: 90px; }
.ladder canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.cover {
  position: absolute;
  inset: 0;
  margin: 0 2px;
  border-radius: 10px;
  border: 2px solid var(--pink);
  background: repeating-linear-gradient(45deg, #1d1247, #1d1247 14px, #2a1a66 14px, #2a1a66 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--display);
  font-size: 21px;
  color: #fff;
  text-shadow: 0 0 8px var(--pink);
}
.cover-sub { font-family: var(--body); font-size: 14px; color: var(--yellow); text-shadow: none; animation: blink 1.1s steps(1) infinite; }

.ladder-top-btn {
  min-height: var(--cell-h);
  border: 2px solid var(--cyan);
  border-radius: 8px;
  background: #0b0620;
  color: var(--cyan);
  font-family: var(--display);
  font-size: 16px;
}
.ladder-top-btn:active { transform: translateY(2px); }
.ladder-top-btn:disabled { opacity: 0.45; pointer-events: none; }
.ladder-top-btn.picked { background: var(--cyan); color: var(--ink); box-shadow: 0 0 12px rgba(38, 230, 255, 0.6); }
.ladder-top-btn.picked::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 10px;
  margin-left: 5px;
  border: solid var(--ink);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
  vertical-align: 2px;
}

.ladder-bottom-cell {
  min-height: var(--cell-h);
  padding: 4px 2px;
  border-radius: 8px;
  border: 2px solid #4a3aa0;
  background: #0b0620;
  color: #8f86c9;
  font-family: var(--display);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-all;
  line-height: 1.2;
}
.ladder-bottom-cell.hit { border-color: #8f86c9; color: #fff; animation: bounce 0.5s ease; }
.ladder-bottom-cell.hit.win { background: var(--yellow); border-color: var(--yellow); color: var(--ink); box-shadow: 0 0 14px rgba(255, 225, 77, 0.7); }

/* ---------- 동전 (옆에서 본 모습) ---------- */
.coin-stage {
  flex: 1;
  min-height: 220px;
  position: relative;
  perspective: 900px;
  perspective-origin: 50% 20%;
  transform-style: preserve-3d;
}
.ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44px;
  border-radius: 8px;
  background: repeating-linear-gradient(90deg, #2a1a66, #2a1a66 20px, #24165a 20px, #24165a 40px);
  border-top: 4px solid var(--cyan);
  box-shadow: 0 -4px 14px rgba(38, 230, 255, 0.35);
}
.coin-wrap {
  position: absolute;
  left: 50%;
  margin-left: -75px;
  bottom: -26px;
  width: 150px;
  height: 150px;
  transform-style: preserve-3d;
  z-index: 1;
}
.coin {
  width: 150px;
  height: 150px;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(90deg);
  transition: transform 1.65s cubic-bezier(0.25, 0.6, 0.35, 1);
}
.face, .edge { position: absolute; inset: 0; border-radius: 50%; }
.edge { background: #b8860b; }
.face {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 36px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 8px solid;
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, 0.35);
}
.face.front { background: #ffe14d; border-color: #d4a017; color: #5c3d00; transform: translateZ(7px); }
.face.back-face { background: #c9c9d6; border-color: #8a8aa0; color: #2a2a40; transform: rotateY(180deg) translateZ(7px); }
.coin-shadow {
  position: absolute;
  left: 50%;
  margin-left: -65px;
  bottom: 30px;
  width: 130px;
  height: 14px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
}

.tally { display: flex; justify-content: center; gap: 28px; font-size: 15px; color: var(--sub); flex-shrink: 0; }
.tally b { font-family: var(--display); font-weight: 400; font-size: 22px; color: var(--yellow); margin-left: 6px; vertical-align: -2px; }

/* ---------- 키가 낮은 화면 (작은 폰, 낮은 노트북 창) ---------- */
@media (max-height: 760px) {
  :root { --gap: 8px; --btn-h: 50px; --cell-h: 40px; }
  .app { padding: 10px 14px; }
  .topbar h2 { font-size: 24px; }
  .big-btn { font-size: 22px; }
  .result { min-height: 44px; font-size: 19px; }
  .card { padding: 10px 12px; }
  .card h3 { margin-bottom: 6px; font-size: 17px; }
  .step-btn { width: 40px; height: 40px; }
  .settings-card .note { display: none; }
  .insert-coin { margin-top: 10px; }
}
@media (max-height: 640px) {
  .coin-panel { display: none; }
  .settings-card h3 { display: none; }
  .stepper-group { gap: 6px; }
}

/* ---------- 넓은 화면 (PC): 좌우 2단 ---------- */
@media (min-width: 900px) {
  .app { max-width: 1080px; padding: 22px 28px; }
  #screen-home { max-width: 520px; width: 100%; margin: 0 auto; }
  .screen-body { flex-direction: row; align-items: stretch; }
  .card-side { flex: 0 0 340px; }
  .settings-card { align-self: flex-start; }
  #screen-coin .screen-body { justify-content: center; }
  .coin-card { flex: 0 1 560px; }
}

@media (max-width: 380px) {
  .menu-title { font-size: 23px; }
  .scoreboard { font-size: 9px; }
  .stepper-label { width: 64px; font-size: 14px; }
}
