:root {
  --bg: #0f0d0d;
  --bg2: #1a1616;
  --bg3: #242020;
  --line: #3a3232;
  --text: #e9e2dc;
  --muted: #a1958f;
  --red: #b3261e;
  --red2: #7a1a15;
  --blue: #2f6f9f;
  --gold: #c9a227;
  --green: #3f8f4f;
  --yellow: #d3b52a;
  --tile-red: #a32a24;
  --tile-green: #2f7a3a;
  --tile-yellow: #b99b1c;
  --tile-blue: #2a5c8f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; }

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
img { display: block; }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

.screen { display: flex; flex-direction: column; gap: 12px; min-height: 100vh; padding-top: env(safe-area-inset-top); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0 8px;
  background: linear-gradient(var(--bg) 85%, transparent);
}
.topbar-title { flex: 1; font-weight: 700; letter-spacing: .02em; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg2);
  font-size: 30px; line-height: 1; padding: 0 0 4px;
}
.text-btn {
  border: 1px solid var(--line); background: var(--bg2); white-space: nowrap; flex: none;
  border-radius: 999px; padding: 8px 12px; font-size: 14px; font-weight: 600;
}
.text-btn.ghost { background: transparent; color: var(--muted); }
.text-btn.active { border-color: var(--red); color: #fff; background: var(--red2); }
.lang-btn {
  margin-left: auto; flex: none;
  border: 1px solid var(--line); background: var(--bg2);
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700; letter-spacing: .05em;
}
.portrait-btn { padding: 0; border: 0; background: none; flex: none; }
.portrait-btn img { width: 48px; height: 48px; border-radius: 50%; }
.portrait-row { display: flex; padding: 0; border: 0; background: none; flex: none; }
.portrait-row img { width: 40px; height: 40px; border-radius: 50%; margin-left: -10px; border: 2px solid var(--bg); }
.portrait-row img:first-child { margin-left: 0; }

.tile-bar { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tile-priority { display: flex; align-items: center; justify-content: center; gap: 2px; min-width: 0; }
.tile-priority img { width: 30px; height: 34px; }
.tile-priority .gt { color: var(--muted); font-size: 16px; font-weight: 700; padding: 0 1px; }

/* ---------- home ---------- */
.center-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 10px 0 30px; }
.logo { width: 72px; height: 72px; opacity: .9; }
h1 { font-size: 26px; margin: 0; letter-spacing: .02em; }
.sub { color: var(--muted); margin: 0 0 8px; font-size: 15px; }
.foot { color: #5f5652; font-size: 12px; text-align: center; margin: 0; }

.big-btn {
  width: min(100%, 420px); padding: 22px 18px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--bg2);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  transition: transform .08s;
}
.big-btn:active { transform: scale(.98); }
.big-btn.killer { border-color: var(--red2); background: linear-gradient(160deg, #2a1414, #1a1010); }
.big-btn.survivor { border-color: #1f4566; background: linear-gradient(160deg, #142230, #101820); }
.big-title { font-size: 22px; font-weight: 800; }
.big-sub { font-size: 13px; color: var(--muted); }

.killer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; width: min(100%, 440px); }
.killer-card {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 16px;
  padding: 16px 10px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px;
}
.killer-card img { width: 110px; height: 110px; border-radius: 50%; }
.killer-card:active { transform: scale(.98); }

/* ---------- panels ---------- */
.panel {
  background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-size: 15px; line-height: 1.55;
}
.panel h3 { margin: 0 0 8px; font-size: 17px; }
.panel h4 { margin: 12px 0 4px; font-size: 15px; color: var(--gold); }
.panel ul { margin: 4px 0 8px; padding-left: 20px; }
.panel li { margin: 3px 0; }
.panel .hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; text-align: right; }
.panel table { width: 100%; border-collapse: collapse; font-size: 14px; }
.panel td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.panel td:first-child { font-weight: 700; white-space: nowrap; width: 34%; }
.panel .muted, .muted { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.lang-menu { position: absolute; right: 0; top: 52px; background: var(--bg3); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 140px; box-shadow: 0 8px 20px rgba(0,0,0,.5); z-index: 30; }
.lang-menu button { text-align: left; border: 0; background: transparent; padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.lang-menu button.on { background: var(--red2); color: #fff; }
.topbar { position: sticky; }
.lang-wrap { position: relative; margin-left: auto; flex: none; }
.lang-wrap .lang-btn { margin-left: 0; padding: 7px 10px; }

/* ---------- counters ---------- */
.counters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.counters.survivors { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.counter { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.counter-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.counter-label img { width: 22px; height: 22px; }
.counter-label img.round { border-radius: 50%; width: 30px; height: 30px; }
.counter-ctl { display: flex; align-items: center; gap: 6px; }
.ctl-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg3); font-size: 22px; line-height: 1; }
.ctl-btn.plus { border-color: var(--red2); }
.ctl-val {
  width: 52px; height: 40px; text-align: center; font-size: 22px; font-weight: 800;
  background: transparent; border: 0; color: var(--text); -moz-appearance: textfield;
}
.ctl-val::-webkit-outer-spin-button, .ctl-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.counter-note { font-size: 12px; color: var(--muted); min-height: 16px; text-align: center; }
.counter-note.power { color: var(--gold); font-weight: 700; }
.counters.survivors .ctl-btn { width: 36px; height: 36px; font-size: 20px; }
.counters.survivors .ctl-val { width: 40px; font-size: 20px; }
.counters.survivors .counter { padding: 8px 6px; }
.counter.power-ready { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }

@keyframes blink { 0%, 100% { box-shadow: 0 0 0 0 rgba(179, 38, 30, 0); } 50% { box-shadow: 0 0 0 6px rgba(179, 38, 30, .55); background: var(--red2); } }
.ctl-btn.blink { animation: blink 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); background: var(--red); } }
.ctl-btn.pulse { animation: pulse .7s ease-in-out 4; }

/* ---------- stage ---------- */
.stage {
  position: relative; min-height: 290px; border-radius: 18px; cursor: pointer;
  border: 1px solid var(--line); background: radial-gradient(ellipse at center, #241c1c 0%, var(--bg2) 70%);
  display: flex; align-items: center; justify-content: center; text-align: center; user-select: none;
}
.stage:active { filter: brightness(1.1); }
.stage-idle { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--muted); font-size: 15px; }
.stage-idle p { margin: 0; }
.die-img { width: 110px; height: 110px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); }
.deck-back {
  width: 170px; height: 236px; border-radius: 8px; border: 2px solid #4a3a3a;
  background: repeating-linear-gradient(135deg, #2a1e1e 0 6px, #241a1a 6px 12px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 6px 12px rgba(0,0,0,.6), 3px 3px 0 #1a1212, 6px 6px 0 #150f0f;
}
.deck-back img { width: 56px; height: 56px; opacity: .8; }
.deck-back span { font-weight: 800; font-size: 20px; }
.stage-idle.deck { gap: 6px; }

.stage-result { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px; width: 100%; }
.card-wrap { position: relative; width: 170px; }
.card-wrap img { width: 100%; border-radius: 8px; box-shadow: 0 8px 18px rgba(0,0,0,.6); }
.card-title { position: absolute; top: 4%; left: 8%; right: 8%; font-weight: 800; font-size: 17px; text-align: left; text-shadow: 0 1px 2px #000; color: #fff; }
.card-label { font-size: 22px; font-weight: 800; }
.card-label small { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-weight: 800; font-size: 16px; }
.badge.bp { background: var(--red2); color: #fff; }
.badge.bp img { width: 18px; height: 18px; }
.badge.warn { background: #3a2f10; color: var(--gold); font-size: 13px; font-weight: 600; }
.power-result { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.power-result img { width: 96px; height: 96px; border-radius: 50%; box-shadow: 0 0 0 4px var(--red2), 0 0 24px rgba(179,38,30,.6); }
.power-result h3 { margin: 0; font-size: 20px; }
.power-result p { margin: 0; font-size: 15px; line-height: 1.5; text-align: left; max-width: 480px; }
.stage-rolling .die-img { animation: drop .55s cubic-bezier(.3,.9,.4,1.15); }
@keyframes drop {
  0% { transform: translateY(-180px) rotate(-720deg) scale(1.15); opacity: 0; }
  10% { opacity: 1; }
  55% { transform: translateY(0) rotate(-40deg) scale(.96, 1.04); }
  72% { transform: translateY(-16px) rotate(-12deg) scale(1.02, .98); }
  100% { transform: translateY(0) rotate(0) scale(1); }
}
.stage { perspective: 900px; }
.stage-rolling .deck-back { animation: flipout .18s ease-in forwards; }
@keyframes flipout { from { transform: rotateY(0); } to { transform: rotateY(90deg); } }
.flip-card { animation: flipcard .18s ease-out; }
@keyframes flipcard { from { transform: rotateY(-90deg); } to { transform: rotateY(0); } }
.power-text { text-align: left; font-size: 15px; line-height: 1.5; max-width: 480px; }
.flip-in { animation: dropin .32s cubic-bezier(.2,.8,.3,1.2); }
@keyframes dropin { from { transform: translateY(-36px) scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }
.result-hint { font-size: 12px; color: var(--muted); }

.forced-move {
  background: #1b2430; border: 1px solid #27405a; border-radius: var(--radius);
  padding: 10px 14px; font-size: 14px; line-height: 1.45;
}
.forced-move b { color: #8fc1ea; }
.deck-tools { display: flex; gap: 8px; justify-content: center; }

/* ---------- skill check ---------- */
.skillcheck { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.sc-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sc-row .sc-title { font-weight: 700; font-size: 14px; color: var(--muted); margin-right: auto; }
.sc-count { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.sc-count button { border: 0; background: transparent; width: 38px; height: 34px; font-weight: 700; }
.sc-count button.on { background: var(--red2); color: #fff; }
.sc-roll { border: 1px solid var(--red2); background: var(--red2); color: #fff; border-radius: 999px; padding: 7px 16px; font-weight: 800; }
.sc-dice { display: flex; gap: 8px; justify-content: center; min-height: 0; flex-wrap: wrap; }
.sc-die {
  width: 60px; height: 60px; border-radius: 14px; background: #111; border: 2px solid #333;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 26px; color: #fff;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.6), 0 4px 8px rgba(0,0,0,.5); overflow: hidden;
}
.sc-die img { width: 60px; height: 60px; }
.sc-die.fail { border-color: var(--red); box-shadow: 0 0 0 2px rgba(179,38,30,.35), 0 4px 8px rgba(0,0,0,.5); }
.sc-die.great { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(201,162,39,.35), 0 4px 8px rgba(0,0,0,.5); }
.sc-die.rolling { animation: drop .45s cubic-bezier(.3,.9,.4,1.15); }
.sc-summary { font-size: 14px; text-align: center; min-height: 18px; }
.sc-summary .fail { color: #f08a84; font-weight: 700; }
.sc-summary .great { color: var(--gold); font-weight: 700; }

/* ---------- accordion / priority ---------- */
.accordion { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.acc-head { width: 100%; display: flex; justify-content: space-between; align-items: center; border: 0; background: transparent; padding: 14px 16px; font-weight: 800; font-size: 16px; }
.acc-head .chev { font-size: 22px; line-height: 0; transition: transform .2s; color: var(--muted); }
.acc-head.open .chev { transform: rotate(180deg); }
.acc-body { padding: 0 8px 8px; }
.prio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 8px; border-top: 1px solid var(--line); font-size: 15px; line-height: 1.45; }
.prio-num { width: 26px; height: 26px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex: none; }
.prio img { width: 30px; height: 34px; flex: none; }
.prio img.round { border-radius: 50%; width: 30px; height: 30px; }
.prio-body { flex: 1; min-width: 0; }
.prio-body b { display: block; }
.prio-body small { color: var(--muted); font-size: 13px; }
.prio-body .sub-list { margin: 6px 0 0; padding-left: 18px; font-size: 13.5px; color: #cfc6c0; }
.prio-body .sub-list li { margin: 2px 0; }
.prio.note { color: var(--muted); font-size: 13.5px; }
.prio .skip { display: inline-block; font-size: 11.5px; background: #3a2f10; color: var(--gold); border-radius: 4px; padding: 0 6px; margin-left: 4px; }
.prio-more { display: block; border: 0; background: transparent; color: var(--gold); font-size: 13px; padding: 2px 0; font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #2c2424; color: #fff; border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 50;
  box-shadow: 0 6px 16px rgba(0,0,0,.5);
}

/* ---------- responsive ---------- */
@media (min-width: 640px) {
  .stage { min-height: 320px; }
  .counters.survivors { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card-wrap { width: 190px; }
  .tile-priority img { width: 34px; height: 39px; }
}
@media (max-width: 380px) {
  .tile-priority img { width: 24px; height: 27px; }
  .tile-priority .gt { font-size: 13px; }
}
