:root {
  --pink: #ff7ea8;
  --pink-soft: #ffd9e6;
  --mint: #7ee0c0;
  --blue: #79bdf2;
  --yellow: #ffd166;
  --violet: #b39ddb;
  --ink: #4a3d52;
  --paper: #fff8fb;
  --up: #2e9b6b;
  --down: #e5628a;
  font-family: ui-rounded, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.7) 0 6%, transparent 7%),
    linear-gradient(170deg, #ffeef5 0%, #eafaf6 55%, #fff3d6 100%);
  min-height: 100dvh;
  -webkit-user-select: none; user-select: none;
}
#app { min-height: 100dvh; }
.screen { max-width: 460px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom)); }
h1, h2, p { margin: 0; }
button { font: inherit; border: 0; cursor: pointer; }
img { -webkit-user-drag: none; user-drag: none; }

/* ---------- 버튼 공통 ---------- */
.btn-primary {
  width: 100%;
  padding: 15px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ff9dbb, var(--pink));
  color: #fff; font-weight: 900; font-size: 17px;
  box-shadow: 0 6px 0 #e5628a, 0 10px 18px rgba(229,98,138,.35);
  transition: transform .1s, box-shadow .1s;
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #e5628a, 0 4px 10px rgba(229,98,138,.3); }
.btn-primary:disabled { filter: grayscale(.4) brightness(1.05); opacity: .8; box-shadow: 0 4px 0 #d7a9b8; }
.btn-ghost {
  width: 100%; padding: 13px; border-radius: 16px;
  background: #fff; color: var(--ink); font-weight: 800;
  box-shadow: inset 0 0 0 2px rgba(74,61,82,.12);
}

/* ---------- 셋업 ---------- */
.logo { text-align: center; margin: 10px 0 16px; }
.logo-sub { display: block; letter-spacing: .3em; font-size: 12px; font-weight: 900; color: var(--pink); }
.logo h1 { font-size: 42px; font-weight: 1000; letter-spacing: -.02em; text-shadow: 0 3px 0 #fff, 0 5px 8px rgba(0,0,0,.08); }
.logo .tag { margin-top: 6px; color: #8a7d92; font-weight: 800; }
.panel {
  background: var(--paper);
  border-radius: 24px;
  padding: 18px 16px;
  box-shadow: 0 14px 30px rgba(120,90,110,.16), inset 0 0 0 2px #fff;
}
.panel h2 { font-size: 15px; margin: 4px 0 10px; color: #7a6c82; }
.char-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 16px; }
.char-card {
  background: #fff; border-radius: 16px; padding: 8px 2px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: inset 0 0 0 2px rgba(74,61,82,.08); transition: transform .12s;
}
.char-card img { width: 100%; max-width: 46px; height: 46px; object-fit: contain; }
.char-card .cn { font-size: 11px; font-weight: 900; }
.char-card .ct { font-size: 9px; color: #a99db1; }
.char-card.sel { box-shadow: inset 0 0 0 3px var(--pink); transform: translateY(-3px); background: #fff0f5; }
.rival-pick { display: flex; gap: 8px; margin-bottom: 14px; }
.rival-chip { flex: 1; padding: 11px 0; border-radius: 14px; background: #fff; font-weight: 800; box-shadow: inset 0 0 0 2px rgba(74,61,82,.1); }
.rival-chip.sel { background: var(--mint); color: #0c5c46; box-shadow: inset 0 0 0 2px #4bc59d; }
.best { text-align: center; font-size: 13px; font-weight: 800; color: var(--violet); margin-bottom: 12px; }
.foot { text-align: center; margin-top: 14px; font-size: 12px; color: #a99db1; }

/* ---------- 게임 ---------- */
.game { max-width: 460px; }
.hud { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.hud-title { flex: 1; text-align: center; font-weight: 900; font-size: 16px; }
.icon { width: 40px; height: 40px; border-radius: 12px; background: #fff; font-size: 18px; box-shadow: 0 3px 0 rgba(74,61,82,.1); }
.players { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; }
.pcard {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  background: #fff; border-radius: 14px; padding: 5px 9px 5px 5px;
  box-shadow: inset 0 0 0 2px rgba(74,61,82,.08);
}
.pcard.active { box-shadow: inset 0 0 0 2px var(--pink), 0 4px 10px rgba(255,126,168,.3); }
.pcard.done { opacity: .7; }
.pcard img { width: 30px; height: 30px; object-fit: contain; }
.pinfo { display: flex; flex-direction: column; line-height: 1.15; }
.pn { font-size: 12px; font-weight: 900; }
.pstat { font-size: 11px; color: #7a6c82; font-weight: 700; }
.pturn { color: var(--pink); font-weight: 900; }
.pdone { font-size: 11px; font-weight: 900; color: var(--violet); }

/* 보드 */
.board-wrap { background: rgba(255,255,255,.5); border-radius: 20px; padding: 8px; box-shadow: inset 0 0 0 2px #fff; }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 6px;
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  padding: 4px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  text-align: center;
  background: #fff;
  box-shadow: 0 3px 0 rgba(74,61,82,.08), inset 0 0 0 2px rgba(255,255,255,.9);
  overflow: visible;
}
.tile .te { font-size: 20px; line-height: 1; }
.tile .tt { font-size: 8px; font-weight: 800; line-height: 1.05; color: #6a5c72; max-height: 2.2em; overflow: hidden; }
.tile .tm { position: absolute; top: 2px; right: 3px; font-size: 8px; font-weight: 900; }
.tile .tm.up { color: var(--up); }
.tile .tm.down { color: var(--down); }
.t-plus { background: linear-gradient(180deg,#fff,#eafaf3); }
.t-minus { background: linear-gradient(180deg,#fff,#ffeef3); }
.t-chance { background: linear-gradient(180deg,#fff8e6,#ffe9b8); box-shadow: 0 3px 0 rgba(200,150,40,.18), inset 0 0 0 2px #fff2cf; }
.t-start { background: linear-gradient(180deg,#e9f3ff,#cfe6ff); box-shadow: 0 3px 0 rgba(60,120,200,.18), inset 0 0 0 2px #eaf4ff; }
.t-goal { background: linear-gradient(180deg,#fff3d6,#ffd166); box-shadow: 0 3px 0 rgba(200,150,20,.3), inset 0 0 0 2px #fff6dd; }
.t-skip1, .t-back2 { background: linear-gradient(180deg,#fff,#ffe6e6); }
.t-forward2 { background: linear-gradient(180deg,#fff,#e6f6ff); }

.token {
  position: absolute;
  width: 62%; height: 62%;
  object-fit: contain;
  left: 50%; bottom: 8%;
  transform: translateX(calc(-50% + (var(--oi) - (var(--on) - 1) / 2) * 34%));
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.28));
  transition: transform .18s;
  z-index: 5;
  animation: bob 1.6s ease-in-out infinite;
}
.token.lead { z-index: 6; animation: bobLead .7s ease-in-out infinite; }
@keyframes bob { 0%,100%{ margin-bottom:0 } 50%{ margin-bottom:3px } }
@keyframes bobLead { 0%,100%{ margin-bottom:0 } 50%{ margin-bottom:5px } }

/* 턴바 */
.turnbar { display: flex; align-items: center; gap: 10px; margin: 12px 0 8px; }
.dice { width: 56px; height: 56px; border-radius: 16px; background: #fff; display: grid; place-items: center; font-size: 34px; box-shadow: 0 5px 0 rgba(74,61,82,.12); }
.roll { flex: 1; }

/* 로그 */
.log { background: rgba(255,255,255,.65); border-radius: 14px; padding: 8px 12px; max-height: 92px; overflow-y: auto; font-size: 12px; }
.logline { padding: 2px 0; color: #6a5c72; font-weight: 700; }

/* 오버레이 */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(60,40,55,.42);
  display: grid; place-items: center; padding: 24px;
  opacity: 0; transition: opacity .18s;
}
.overlay.show { opacity: 1; }
.card.evt {
  width: 100%; max-width: 340px;
  background: var(--paper); border-radius: 24px; padding: 22px 18px;
  text-align: center; box-shadow: 0 20px 44px rgba(0,0,0,.28);
  transform: scale(.94); transition: transform .18s;
}
.overlay.show .card.evt { transform: scale(1); }
.evt-title { font-size: 20px; font-weight: 1000; margin-bottom: 8px; }
.evt-desc { font-size: 14px; color: #6a5c72; line-height: 1.5; font-weight: 700; }
.evt-delta { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }
.delta { font-weight: 900; font-size: 15px; padding: 4px 12px; border-radius: 12px; }
.delta.up { color: var(--up); background: #e6f7ef; }
.delta.down { color: var(--down); background: #ffe9f0; }
.card.evt .btn-primary { margin-top: 6px; }

/* 결과 */
.result { text-align: center; }
.result h1 { font-size: 34px; font-weight: 1000; margin: 18px 0 6px; }
.newbest { color: var(--pink); font-weight: 900; margin-bottom: 12px; }
.myscore { color: #7a6c82; font-weight: 800; margin-bottom: 12px; }
.rank-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 18px; }
.rank-row { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 8px 12px; box-shadow: inset 0 0 0 2px rgba(74,61,82,.06); }
.rank-row.me { box-shadow: inset 0 0 0 2px var(--pink); background: #fff4f8; }
.rank-row .rk { font-size: 20px; width: 34px; text-align: center; }
.rank-row img { width: 34px; height: 34px; object-fit: contain; }
.rank-row .rn { font-weight: 900; flex: 1; text-align: left; }
.rank-row .rs { font-size: 11px; color: #7a6c82; font-weight: 700; }
.result-btns { display: flex; flex-direction: column; gap: 10px; }
