:root {
  --ink: #2b2140;
  --pink: #ff8fb8;
  --lemon: #ffe066;
  --mint: #7ce7c4;
  --paper: #fffdf8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body,
#game-root {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #9ad8ff;
  font-family: "Gowun Dodum", sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
}

#view {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

button,
.back,
.mute,
.ghost,
.prompt {
  touch-action: manipulation;
}

.back,
.mute {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  z-index: 8;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  font-family: "Jua", sans-serif;
  border-radius: 14px;
  padding: 6px 12px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}

.back {
  left: max(12px, env(safe-area-inset-left));
}

.mute {
  right: max(12px, env(safe-area-inset-right));
  font-size: 16px;
}

.hud {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(420px, calc(100% - 180px));
}

.hud-card {
  display: flex;
  gap: 18px;
  align-items: baseline;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 6px 16px;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: "Jua", sans-serif;
}

.money b,
.goal b {
  font-size: 22px;
}

.progress-wrap {
  width: 100%;
  height: 14px;
  background: rgba(255, 253, 248, 0.7);
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.progress {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, var(--pink), var(--lemon));
}

.prompt,
.keys {
  font-family: "Jua", sans-serif;
  text-shadow: 0 1px 0 #fff;
}

.prompt {
  background: var(--lemon);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 16px;
  cursor: pointer;
}

.keys {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 4;
  font-size: 14px;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: rgba(80, 140, 190, 0.28);
  backdrop-filter: blur(6px);
}

.panel {
  width: min(460px, calc(100% - 32px));
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 28px;
  padding: 28px 26px 24px;
  box-shadow: 10px 12px 0 var(--ink);
  text-align: center;
  max-height: calc(100% - 32px);
  overflow: auto;
}

.play-panel {
  width: min(540px, calc(100% - 32px));
}

.kicker {
  font-size: 13px;
  letter-spacing: 0.08em;
}

.panel h1,
.panel h2 {
  font-family: "Jua", sans-serif;
}

.panel h1 {
  font-size: 52px;
  line-height: 1;
  margin: 4px 0 8px;
}

.panel h2 {
  font-size: 32px;
  margin-bottom: 8px;
}

.lead {
  color: #6d5a7a;
  line-height: 1.55;
}

.controls {
  list-style: none;
  text-align: left;
  margin: 16px 0 20px;
  display: grid;
  gap: 8px;
}

.controls li {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
}

kbd {
  font-family: "Jua", sans-serif;
  background: var(--lemon);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 1px 6px;
}

button,
.ghost {
  font-family: "Jua", sans-serif;
  font-size: 18px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
}

#btn-start,
#btn-retry,
#btn-again {
  background: var(--pink);
  box-shadow: 4px 4px 0 var(--ink);
}

.ghost {
  background: #efe6ff;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.bet-label {
  font-family: "Jua", sans-serif;
  margin: 12px 0 8px;
}

.bet-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.bet-stepper {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px 8px;
  width: 100%;
}

.bet-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bet-col.minus {
  align-items: flex-end;
}

.bet-col.plus {
  align-items: flex-start;
}

.bet-amount {
  min-width: 110px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 3px 3px 0 var(--ink);
}

.bet-amount b {
  display: block;
  font-family: "Jua", sans-serif;
  font-size: 26px;
  line-height: 1.1;
}

.bet-amount span {
  font-size: 12px;
  color: #6d5a7a;
}

.bet-go {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.bet-row button {
  font-size: 14px;
  padding: 7px 10px;
  box-shadow: 3px 3px 0 var(--ink);
}

#btn-bet {
  background: var(--pink);
  font-size: 18px;
  padding: 10px 22px;
}

.bet-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.stage {
  margin-top: 8px;
}

.hint {
  color: #6d5a7a;
  font-size: 14px;
  margin-bottom: 10px;
}

.choice-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.choice {
  min-width: 92px;
  font-size: 28px;
  padding: 12px 10px 8px;
  box-shadow: 3px 3px 0 var(--ink);
  background: #fff;
  line-height: 1.15;
}

.choice span {
  display: block;
  font-size: 14px;
}

.choice.slim {
  font-size: 22px;
  min-width: 110px;
}

.wheel-box {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 8px auto 16px;
}

.wheel {
  width: 260px;
  height: 260px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  box-shadow: 5px 6px 0 var(--ink);
  position: relative;
  overflow: hidden;
  transition: transform 3.8s cubic-bezier(0.12, 0.72, 0.08, 1);
}

.wheel span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  margin-left: -22px;
  font-family: "Jua", sans-serif;
  font-size: 15px;
  color: var(--ink);
  text-shadow: 0 1px 0 #fff;
  text-align: center;
  transform-origin: 50% 0;
  pointer-events: none;
}

.wheel-pin {
  position: absolute;
  left: 50%;
  top: -6px;
  z-index: 2;
  width: 0;
  height: 0;
  margin-left: -12px;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 22px solid var(--ink);
}

.wheel-pin::after {
  content: "";
  position: absolute;
  left: -8px;
  top: -22px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 16px solid var(--lemon);
}

.wheel-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  border-radius: 50%;
  background: var(--lemon);
  border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
  z-index: 1;
  pointer-events: none;
}

#btn-spin {
  background: var(--mint);
  box-shadow: 4px 4px 0 var(--ink);
}

#btn-spin:disabled {
  opacity: 0.55;
  box-shadow: none;
  cursor: wait;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
}

.mcard {
  aspect-ratio: 3 / 4;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #8ec5ff;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 28px;
  cursor: pointer;
  font-family: "Jua", sans-serif;
}

.mcard.on,
.mcard.done {
  background: #fff;
}

.mcard.done {
  background: var(--mint);
}

.dice {
  width: 72px;
  height: 72px;
  margin: 8px auto 14px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: "Jua", sans-serif;
  font-size: 36px;
  display: grid;
  place-items: center;
}

.dice.spin {
  animation: dicepop 0.12s linear infinite;
}

.ladder-wrap {
  position: relative;
  width: min(360px, 100%);
  margin: 0 auto;
}

.ladder-picks {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.ladder-picks button {
  box-shadow: 3px 3px 0 var(--ink);
  background: var(--lemon);
}

.play-result {
  margin-top: 14px;
  font-family: "Jua", sans-serif;
  font-size: 22px;
}

.play-result.win {
  color: #1e8a62;
}

.play-result.lose {
  color: #c4496a;
}

.leave-early {
  margin-top: 14px;
}

.shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
  text-align: left;
}

.shop-item {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px;
}

.shop-item h3 {
  font-family: "Jua", sans-serif;
  font-size: 18px;
}

.shop-item p {
  font-size: 13px;
  color: #6d5a7a;
  margin: 4px 0 8px;
}

.shop-item .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.shop-item button {
  font-size: 14px;
  padding: 6px 10px;
  background: var(--mint);
  box-shadow: 2px 2px 0 var(--ink);
}

.shop-item button.on {
  background: var(--lemon);
}

.shop-item button:disabled {
  background: #efe6ff;
  box-shadow: none;
  opacity: 0.7;
}

@keyframes dicepop {
  from {
    transform: rotate(-12deg);
  }
  to {
    transform: rotate(12deg);
  }
}

@media (max-width: 640px) {
  .shop-grid {
    grid-template-columns: 1fr;
  }
  .card-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.touch-only {
  display: none;
}

.touch-ui {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  pointer-events: none;
}

.stick {
  pointer-events: auto;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: rgba(255, 253, 248, 0.5);
  position: relative;
  touch-action: none;
  box-shadow: 3px 3px 0 var(--ink);
}

.stick-knob {
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--pink);
  border: 3px solid var(--ink);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 3px 3px 0 var(--ink);
}

.touch-btn {
  pointer-events: auto;
  min-width: 92px;
  height: 92px;
  font-size: 18px;
  background: var(--lemon);
  box-shadow: 3px 3px 0 var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

.touch-btn.talk {
  border-radius: 50%;
}

.touch-btn.talk.ready {
  background: var(--mint);
}

.touch-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

@media (hover: none), (pointer: coarse) {
  .touch-ui:not(.hidden) {
    display: flex;
  }
  .touch-only {
    display: list-item;
  }
  .kb-only,
  .keys {
    display: none !important;
  }
  .hud {
    top: max(56px, calc(env(safe-area-inset-top) + 44px));
    width: min(420px, calc(100% - 20px));
  }
  .panel {
    padding: 20px 16px 18px;
  }
  .panel h1 {
    font-size: 42px;
  }
  .lead {
    word-break: keep-all;
  }
  .wheel-box,
  .wheel {
    width: 210px;
    height: 210px;
  }
  .choice {
    min-width: 72px;
    font-size: 24px;
    padding: 10px 8px 6px;
  }
  .bet-row button {
    font-size: 13px;
    padding: 6px 8px;
  }
  .bet-amount {
    min-width: 92px;
    padding: 8px 8px;
  }
  .bet-amount b {
    font-size: 22px;
  }
  body:has(#play:not(.hidden)) .hud,
  body:has(#shop:not(.hidden)) .hud,
  body:has(#result:not(.hidden)) .hud,
  body:has(#play:not(.hidden)) .touch-ui,
  body:has(#shop:not(.hidden)) .touch-ui,
  body:has(#result:not(.hidden)) .touch-ui {
    display: none !important;
  }
}

@media (hover: none) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
  .hud {
    top: max(12px, env(safe-area-inset-top));
    width: min(420px, calc(100% - 176px));
  }
  .stick {
    width: 108px;
    height: 108px;
  }
  .touch-btn.talk {
    min-width: 76px;
    height: 76px;
    font-size: 15px;
  }
}
