:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c232d; --line: #2d3644;
  --text: #e6e6e6; --muted: #9aa4b2;
  --blue: #58C4DD; --green: #83C167; --yellow: #FFD166; --red: #FC6255; --purple: #B392F0;
}
* { box-sizing: border-box; }
html { font-size: clamp(14px, 1.02vw, 21px); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard", "NanumBarunGothic", sans-serif;
  line-height: 1.45; overflow-x: hidden;
}
button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.45rem 0.9rem; cursor: pointer;
}
button:hover { border-color: var(--blue); }
button:focus-visible, .rule:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
button.primary { background: var(--blue); color: #08131a; border-color: var(--blue); font-weight: 700; }
button.primary:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.4; cursor: default; }
button.wide { width: 100%; }
code { background: var(--panel2); padding: 0 0.3em; border-radius: 4px; }

/* 헤더 */
.top {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: 0.8rem 1.2rem 0.5rem; border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 1.7rem; letter-spacing: -0.02em; }
.subj { font-size: 0.8rem; background: var(--green); color: #0d1117; padding: 0.1em 0.5em; border-radius: 0.4em; margin-right: 0.5em; vertical-align: middle; }
.goal { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.95rem; }
.goal b { color: var(--yellow); margin-right: 0.4em; }
.back { color: var(--blue); text-decoration: none; white-space: nowrap; font-size: 0.9rem; margin-top: 0.3rem; }

/* 단계 탭 */
.steps { display: flex; gap: 0.4rem; padding: 0.55rem 1.2rem; flex-wrap: wrap; }
.steps button { font-size: 0.92rem; padding: 0.35rem 0.75rem; }
.steps button b { display: inline-block; width: 1.4em; height: 1.4em; line-height: 1.4em; text-align: center; border-radius: 50%; background: var(--line); margin-right: 0.3em; font-size: 0.85em; }
.steps button.on { border-color: var(--yellow); color: var(--yellow); }
.steps button.on b { background: var(--yellow); color: #0d1117; }

main { padding: 0 1.2rem; }
.step { display: none; }
.step.on { display: block; animation: fade 0.3s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
h2 { font-size: 1.35rem; margin: 0.3rem 0; }
.lead { margin: 0.2rem 0 0.6rem; font-size: 1.02rem; }
.lead b { color: var(--yellow); }
.msg { color: var(--muted); }
.note { color: var(--muted); font-size: 0.95rem; margin: 0.5rem 0; }
.note b { color: var(--text); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 0.8rem; padding: 0.8rem 1rem; }
.actions { display: flex; gap: 0.6rem; align-items: center; justify-content: flex-end; margin: 0.6rem 0; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; color: var(--muted); }
.toggle input { width: 1.2rem; height: 1.2rem; accent-color: var(--yellow); }
canvas.spr { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

/* 1단계: 사회 */
.society { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; margin-bottom: 0.6rem; }
.person {
  display: flex; align-items: center; gap: 0.6rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 0.7rem; padding: 0.35rem 0.6rem; position: relative;
}
.person canvas { width: 3.2rem; height: 4rem; flex: none; }
.person .pname { font-weight: 700; font-size: 1.02rem; }
.person .ptags { display: flex; flex-wrap: wrap; gap: 0.2rem; margin-top: 0.15rem; }
.person .ptags span { font-size: 0.75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 1em; padding: 0 0.45em; }
.person .q { position: absolute; right: 0.5rem; top: 0.3rem; color: var(--yellow); font-weight: 800; font-size: 1.1rem; }

/* 1단계: 규칙 카드 */
.rules { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.6rem; }
.rule {
  background: var(--panel); border: 2px solid var(--line); border-radius: 0.8rem; padding: 0.6rem 0.7rem;
  cursor: pointer; display: flex; flex-direction: column; transition: transform 0.15s, border-color 0.15s;
}
.rule:hover { transform: translateY(-2px); }
.rule.sel { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.25); }
.rule.pulse { transform: translateY(-4px); border-color: var(--blue); }
.rule .rh { display: flex; align-items: center; gap: 0.45rem; }
.rule .letter { width: 1.7rem; height: 1.7rem; border-radius: 0.4rem; display: grid; place-items: center; font-weight: 800; color: #0d1117; flex: none; }
.rule .rname { font-weight: 800; font-size: 1.05rem; line-height: 1.2; }
.rule .rsub { font-size: 0.8rem; color: var(--muted); }
.rule .rdesc { font-size: 0.84rem; margin: 0.35rem 0; min-height: 3.6em; color: #cfd6df; }
.bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.3rem; align-items: end; height: 8.5rem; border-bottom: 1px solid var(--line); }
.bars .b { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bars .b span { font-size: 0.85rem; font-weight: 700; }
.bars .b span.min { color: var(--red); }
.bars .b i { display: block; width: 100%; border-radius: 0.25rem 0.25rem 0 0; min-height: 2px; }
.icons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.3rem; justify-items: center; margin-top: 0.15rem; }
.icons canvas { width: 1.7rem; height: 2.1rem; }
.rstats { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; gap: 0.3rem; }
.rstats b { color: var(--text); }
.rstats .mn b { color: var(--red); }

/* 2단계 */
.s2grid { display: grid; grid-template-columns: 1fr 24rem; gap: 1rem; align-items: start; }
.stage-wrap {
  position: relative; overflow: hidden; border-radius: 0.8rem; border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 110%, #24324a 0%, #121821 70%);
  min-height: 19rem;
}
.stage { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; padding: 3.2rem 0.8rem 0.9rem; align-items: end; align-content: center; min-height: 19rem; }
.slot { display: flex; flex-direction: column; align-items: center; border: 3px solid transparent; border-radius: 0.7rem; padding: 0.4rem 0.2rem; position: relative; transition: border-color 0.08s, background 0.08s; }
.slot canvas { width: 6.4rem; height: 8rem; }
.slot .sname { font-weight: 700; margin-top: 0.3rem; font-size: 1rem; text-align: center; }
.slot .pay { position: absolute; top: -2.3rem; font-size: 1.35rem; font-weight: 800; opacity: 0; transition: opacity 0.4s; }
.slot.show .pay { opacity: 1; }
.slot.hl { border-color: var(--yellow); background: rgba(255, 209, 102, 0.08); }
.slot.me { border-color: var(--yellow); background: rgba(255, 209, 102, 0.14); box-shadow: 0 0 1.5rem rgba(255, 209, 102, 0.35); }
.slot .metag { position: absolute; top: 0.2rem; right: 0.2rem; background: var(--yellow); color: #0d1117; font-weight: 800; border-radius: 0.4rem; padding: 0 0.4rem; display: none; }
.slot.me .metag { display: block; animation: pop 0.4s; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
.curtain {
  position: absolute; top: 0; bottom: 0; width: 50.5%; z-index: 3;
  background: repeating-linear-gradient(90deg, #3b2466 0 1.4rem, #2a1850 1.4rem 2.8rem);
  border-bottom: 0.5rem solid var(--yellow);
  transition: transform 1.1s cubic-bezier(.65, .05, .3, 1);
}
.curtain.left { left: 0; box-shadow: inset -1rem 0 1.5rem rgba(0,0,0,.45); }
.curtain.right { right: 0; box-shadow: inset 1rem 0 1.5rem rgba(0,0,0,.45); }
.stage-wrap.open .curtain.left { transform: translateX(-101%); }
.stage-wrap.open .curtain.right { transform: translateX(101%); }
.curtain-label { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4rem; pointer-events: none; transition: opacity 0.4s; }
.curtain-label b { font-size: 2.4rem; color: var(--yellow); letter-spacing: 0.1em; }
.curtain-label span { color: #d8cdf0; }
.stage-wrap.open .curtain-label { opacity: 0; }
.result h3 { margin: 0 0 0.4rem; }
.result .you { font-size: 1.15rem; }
.result .big { font-size: 3rem; font-weight: 800; color: var(--yellow); line-height: 1.1; }
.result .big small { font-size: 1.1rem; color: var(--muted); margin-left: 0.2rem; }
.result h4 { margin: 0.7rem 0 0.3rem; font-size: 0.95rem; color: var(--muted); }
.mini { display: grid; grid-template-columns: auto 1fr 2.6rem; gap: 0.25rem 0.5rem; align-items: center; font-size: 0.9rem; }
.mini .mb { height: 0.9rem; border-radius: 0.2rem; }
.mini .cur { font-weight: 800; color: var(--yellow); }
.mini .v { text-align: right; font-weight: 700; }
.known { margin-top: 0.7rem; border-top: 1px dashed var(--line); padding-top: 0.6rem; }
.known .kbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; margin-top: 0.4rem; }
.known .kbtns button { font-size: 0.85rem; padding: 0.35rem 0.4rem; text-align: left; }
.known .kmsg { margin-top: 0.5rem; font-size: 0.92rem; }
.known .kmsg b { color: var(--yellow); }
.history { display: flex; flex-wrap: wrap; gap: 0.35rem; font-size: 0.82rem; color: var(--muted); }
.history span { border: 1px solid var(--line); border-radius: 1em; padding: 0.1rem 0.6rem; }

/* 3단계 */
.seg { display: flex; border: 1px solid var(--line); border-radius: 0.5rem; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--panel); }
.seg button.on { background: var(--yellow); color: #0d1117; font-weight: 700; }
.s3grid { display: grid; grid-template-columns: 1fr 24rem; gap: 1rem; align-items: start; }
.chart-card { padding: 0.4rem; }
#lifeChart { width: 100%; height: auto; max-height: 62vh; display: block; }
#lifeChart text { font-family: "Pretendard", "NanumBarunGothic", sans-serif; }
.now { display: flex; align-items: center; gap: 0.7rem; min-height: 5rem; margin-bottom: 0.5rem; }
.now canvas { width: 3.6rem; height: 4.5rem; }
.now b { color: var(--yellow); font-size: 1.15rem; }
.ltable { width: 100%; border-collapse: collapse; margin-top: 0.7rem; font-size: 0.9rem; }
.ltable th, .ltable td { padding: 0.3rem 0.3rem; border-bottom: 1px solid var(--line); text-align: right; }
.ltable th:first-child, .ltable td:first-child { text-align: left; }
.ltable th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.ltable tr.mine td { background: rgba(255, 209, 102, 0.1); }
.ltable .dot, .dot { display: inline-block; width: 0.7em; height: 0.7em; border-radius: 50%; margin-right: 0.35em; vertical-align: 0.05em; }

/* 4단계 */
.s4grid { display: grid; grid-template-columns: 1fr 27rem; gap: 1rem; align-items: start; }
.agents { display: grid; grid-template-columns: repeat(10, 1fr); gap: 0.35rem; }
.agent { background: var(--panel); border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.2rem 0.1rem 0.25rem; display: flex; flex-direction: column; align-items: center; min-height: 7.6rem; }
.agent canvas { width: 2.8rem; height: 3.5rem; }
.agent .vote { height: 1.35rem; font-size: 0.78rem; font-weight: 700; display: flex; gap: 0.2rem; }
.agent .vote .vb { border-radius: 0.6rem; padding: 0 0.4rem; color: #0d1117; animation: pop 0.25s; white-space: nowrap; }
.agent .vote .vb.k { background: transparent !important; border: 2px solid; color: var(--text); padding: 0 0.3rem; }
.agent .apos { font-size: 0.72rem; color: var(--muted); text-align: center; line-height: 1.15; min-height: 1.7em; }
.agent .apos b { color: var(--text); }
.types { display: grid; gap: 0.25rem; }
.trow { display: grid; grid-template-columns: 1.8rem 1fr auto; gap: 0.4rem; align-items: center; }
.trow canvas { width: 1.6rem; height: 2rem; }
.trow .tn { font-weight: 700; font-size: 0.92rem; }
.trow .td { font-size: 0.75rem; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 0.25rem; }
.stepper button { padding: 0 0.5rem; min-width: 1.9rem; font-weight: 700; }
.stepper .num { min-width: 1.8rem; text-align: center; font-weight: 800; font-size: 1.05rem; }
.sim-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; margin: 0.6rem 0; }
.sim-actions button { font-size: 0.88rem; padding: 0.4rem 0.3rem; }
.tally-head, .trow2 { display: grid; grid-template-columns: 6.6rem 1fr 1fr; gap: 0.4rem; align-items: center; }
.tally-head { font-size: 0.8rem; color: var(--muted); }
.trow2 { margin: 0.2rem 0; font-size: 0.88rem; }
.tb { display: flex; align-items: center; gap: 0.3rem; height: 1.3rem; }
.tb i { display: block; height: 100%; border-radius: 0.2rem; transition: width 0.5s; min-width: 0; }
.tb i.k { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,.35) 0 4px, transparent 4px 8px) !important; }
.tb span { font-weight: 700; font-size: 0.85rem; }
.simsum { margin-top: 0.5rem; font-size: 0.92rem; border-top: 1px dashed var(--line); padding-top: 0.5rem; }
.simsum b { color: var(--yellow); }

/* 5단계 */
.ctally { display: grid; grid-template-columns: 15rem auto auto 1fr; gap: 0.6rem 1rem; align-items: center; }
.ctally .hd { color: var(--muted); font-size: 0.9rem; }
.ctally .rl { font-weight: 800; font-size: 1.1rem; }
.ctally .rl small { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }
.counter { display: flex; align-items: center; gap: 0.4rem; }
.counter button { font-size: 1.3rem; padding: 0.1rem 0.7rem; font-weight: 800; }
.counter .num { min-width: 2.4rem; text-align: center; font-size: 1.6rem; font-weight: 800; }
.cbars { display: grid; gap: 0.25rem; }
.cbars .tb { height: 1.4rem; }

/* 6단계 */
.theory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem; margin-bottom: 1rem; }
.theory .wide2 { grid-column: span 2; }
.theory .wide4 { grid-column: 1 / -1; }
.simp { columns: 2; column-gap: 2rem; }
.theory h3 { margin: 0 0 0.35rem; font-size: 1.12rem; }
.theory p, .theory li { font-size: 0.92rem; margin: 0.2rem 0; }
.theory ol, .theory ul { padding-left: 1.2rem; margin: 0.2rem 0; }
.theory b { color: #fff; }
.t-blue { border-top: 4px solid var(--blue); } .t-blue h3 { color: var(--blue); }
.t-green { border-top: 4px solid var(--green); } .t-green h3 { color: var(--green); }
.t-yellow { border-top: 4px solid var(--yellow); } .t-yellow h3 { color: var(--yellow); }
.t-red { border-top: 4px solid var(--red); } .t-red h3 { color: var(--red); }
.t-gray { border-top: 4px solid var(--muted); }
.prio { color: var(--yellow); font-weight: 700; }

/* 접는 패널 */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; padding: 0.6rem 1.2rem 1.5rem; align-items: start; }
summary { cursor: pointer; font-weight: 800; font-size: 1.05rem; color: var(--blue); }
.pbody { font-size: 0.92rem; }
.pbody h4 { margin: 0.6rem 0 0.2rem; color: var(--yellow); }
.pbody ol { padding-left: 1.3rem; margin: 0.2rem 0; }
.prompt { white-space: pre-wrap; background: #0a0e14; border: 1px solid var(--line); border-radius: 0.5rem; padding: 0.6rem 0.8rem; font-size: 0.82rem; font-family: inherit; }
.small { font-size: 0.82rem; color: var(--muted); }
.sheet-box { background: repeating-conic-gradient(#1a2029 0 25%, #222a35 0 50%) 0 0 / 16px 16px; display: inline-block; padding: 0.4rem; border-radius: 0.4rem; }
.sheet-box canvas { image-rendering: pixelated; width: 240px; height: auto; display: block; }

.auto-badge { position: fixed; right: 1rem; bottom: 1rem; background: var(--red); color: #fff; font-weight: 700; padding: 0.4rem 0.9rem; border-radius: 2rem; cursor: pointer; z-index: 20; box-shadow: 0 4px 16px rgba(0,0,0,.4); }

/* 좁은 화면 */
@media (max-width: 1100px) {
  .s2grid, .s3grid, .s4grid { grid-template-columns: 1fr; }
  .rules { grid-template-columns: repeat(3, 1fr); }
  .society { grid-template-columns: repeat(3, 1fr); }
  .theory { grid-template-columns: 1fr 1fr; }
  .panels { grid-template-columns: 1fr; }
  .ctally { grid-template-columns: 1fr auto auto; }
  .ctally .cbars { grid-column: 1 / -1; }
  .agents { grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr)); }
  .simp { columns: 1; }
}
