:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --text: #1d1d24;
  --muted: #62626f;
  --border: #e2e2e8;
  --accent: #b8860b;
  --accent-soft: #fbf3dc;
  --fp: #2563eb;
  --lp: #dc2626;
  --code-bg: #f0f0f4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121217;
    --surface: #1b1b22;
    --text: #e8e8ee;
    --muted: #9a9aa8;
    --border: #2e2e38;
    --accent: #e0b44a;
    --accent-soft: #2c2616;
    --fp: #60a5fa;
    --lp: #f87171;
    --code-bg: #24242d;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  line-height: 1.7;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand { font-weight: 700; color: var(--text); }
.breadcrumb { color: var(--muted); font-size: 0.9rem; }
.breadcrumb a { color: var(--muted); }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}
h1 { font-size: 1.9rem; margin: 0.2em 0 0.1em; line-height: 1.3; }
h2 { font-size: 1.35rem; margin-top: 2em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
h3 { font-size: 1.1rem; margin-top: 1.6em; }
.subtitle { color: var(--muted); margin-top: 0; }

.card-list { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); padding: 0; list-style: none; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  color: var(--text);
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card .title { font-weight: 700; }
.card .desc { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }
.card .tag { font-size: 0.75rem; color: var(--accent); font-weight: 600; letter-spacing: 0.04em; }

.infobox {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 16px;
  margin: 16px 0;
}
.infobox table { width: 100%; border-collapse: collapse; }
.infobox th { text-align: left; width: 32%; color: var(--muted); font-weight: 500; }
.infobox th, .infobox td { padding: 8px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.infobox tr:last-child th, .infobox tr:last-child td { border-bottom: none; }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 20px;
  display: inline-block;
  min-width: 240px;
}
.toc ol { margin: 6px 0; padding-left: 20px; }

table.data { border-collapse: collapse; width: 100%; background: var(--surface); margin: 12px 0; }
table.data th, table.data td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
table.data th { background: var(--code-bg); }
.table-wrap { overflow-x: auto; }

.note, .todo {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  margin: 16px 0;
}
.todo { border-left-color: var(--muted); background: var(--code-bg); }

code, kbd { background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-size: 0.92em; }
.fp { color: var(--fp); font-weight: 700; }
.lp { color: var(--lp); font-weight: 700; }

/* 테이블 배치도 */
.layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  text-align: center;
  max-width: 420px;
  margin: 16px auto;
}
.layout .die {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 4px;
  background: var(--surface);
  font-weight: 700;
}
.layout .die small { display: block; font-weight: 400; color: var(--muted); }
.layout .seat { font-size: 0.9rem; }

/* 시뮬레이터 */
.sim {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.sim .dice-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.sim label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); }
.sim select, .sim button {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.sim button { cursor: pointer; border-color: var(--accent); }
.sim button:hover { background: var(--accent-soft); }
.sim .result { margin-top: 12px; font-size: 1.05rem; }
.sim .reason { color: var(--muted); font-size: 0.92rem; }

footer { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 24px 16px; border-top: 1px solid var(--border); }
table.data td.fp, table.data td.lp { white-space: nowrap; }

/* Couple Game 계산기 */
.sim input[type="number"] {
  font: inherit;
  width: 120px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.sim label.check { flex-direction: row; align-items: center; gap: 6px; }
.sim button:disabled { opacity: 0.45; cursor: default; background: none; }
.cards { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.playing-card {
  width: 58px;
  height: 80px;
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.15rem;
  background: var(--bg);
  line-height: 1.2;
}
.playing-card.back { color: var(--muted); background: var(--code-bg); }
.playing-card.red { color: var(--lp); }
.playing-card small { font-size: 0.7rem; font-weight: 400; color: var(--muted); }
.choices { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.choices button { display: flex; flex-direction: column; align-items: center; min-width: 88px; }
.choices button small { color: var(--muted); font-size: 0.78rem; }
.stage-title { font-weight: 700; margin-top: 4px; }
.manual { margin-top: 10px; }
.win { color: var(--fp); font-weight: 700; }
.lose { color: var(--lp); font-weight: 700; }
[hidden] { display: none !important; }
.sim input[type="number"]#sim-bet { width: 110px; }

/* Diamond 9 */
.d9-board { margin: 16px 0 8px; }
.d9-score { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; font-size: 1.05rem; }
.d9-score > div { display: flex; align-items: center; gap: 8px; }
.d9-label { font-size: 0.75rem; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.d9-dots { letter-spacing: 2px; color: var(--accent); }
.d9-field { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; color: var(--text); }
.d9-hand { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#d9-diamond rect { fill: var(--bg); stroke: var(--muted); stroke-width: 2; }
#d9-diamond rect.on { fill: var(--accent); stroke: var(--accent); }
#d9-diamond .d9-home { fill: var(--bg); stroke: var(--muted); stroke-width: 2; }
.d9-log { color: var(--muted); font-size: 0.9rem; padding-left: 22px; margin: 10px 0 0; }
table.data td.win, table.data td.lose { font-weight: 700; }
table.data td.win { color: var(--fp); }
table.data td.lose { color: var(--lp); }
.d9-runners { text-align: center; font-weight: 700; color: var(--accent); margin-top: 4px; }
