:root {
  color-scheme: light;
  --ink: #2c3140;
  --muted: #847e8c;
  --yang: #f07062;
  --yin: #4ec4b8;
  --card: #ffffff;
  --line: #e7d5d2;
  --bg0: #f8d8d4;
  --bg1: #f6f1ec;
  --bg2: #ddf3ea;
  --flip: #f4a0a8;
  --mint: #7ed6be;
  --turn: #baa8e8;
  --gold: #f2ce66;
  --danger: #e2605c;
  font-family: system-ui, "Segoe UI", "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg0), var(--bg1) 55%, var(--bg2));
  min-height: 100dvh;
}
button, .chip { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}
h1 { font-size: 40px; line-height: 1.1; margin: 12px 0 8px; letter-spacing: -0.03em; }
h2 { font-size: 22px; margin: 0 0 8px; }
p.lead { color: var(--muted); margin: 0 0 18px; line-height: 1.4; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.btn {
  min-height: 52px;
  border-radius: 16px;
  padding: 12px 16px;
  background: var(--mint);
  color: white;
  font-weight: 700;
  width: 100%;
}
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.small { width: auto; min-height: 44px; }
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.topbar h2 { flex: 1; }
.levels { display: flex; flex-direction: column; gap: 8px; }
.level {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border-radius: 16px; padding: 12px 14px; text-align: left; min-height: 56px;
  box-shadow: 0 8px 20px rgba(180, 120, 120, 0.08);
}
.level .meta { color: var(--muted); font-size: 13px; }
.chapter { margin: 18px 0 8px; color: var(--muted); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; }
.banner {
  background: white; border-radius: 16px; padding: 14px 16px; line-height: 1.45; margin-bottom: 12px;
}
.chips { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 12px; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  background: white; border-radius: 14px; padding: 8px 12px; width: 100%;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip strong { font-size: 15px; font-weight: 700; }
.chip small { color: var(--muted); font-size: 13px; line-height: 1.35; font-weight: 400; margin-top: 2px; }
.chip.on { box-shadow: inset 0 0 0 2px var(--yang); }
.boards { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; }
.frame { min-width: 220px; flex: 1; }
.frame h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.seat { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; margin: 8px 0; }
.seat > span:first-child { font-size: 13px; color: var(--muted); }
.slot { display: block; width: 100%; }
.bar {
  height: 28px; border-radius: 999px; width: 100%; position: relative;
  box-shadow: inset 0 0 0 2px transparent;
}
.bar.yang { background: var(--yang); }
.bar.yin { background: transparent; display: flex; justify-content: space-between; }
.bar.yin i { width: 42%; height: 100%; border-radius: 999px; background: var(--yin); display: block; }
.bar.empty { background: transparent; box-shadow: inset 0 0 0 2px #e7b4b0; }
.bar.bad { outline: 3px solid var(--danger); }
.bar.old { box-shadow: 0 0 0 3px var(--gold); }
.bar.nudged { transform: translateX(6px); }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 16px; }
.sheet, .modal {
  position: fixed; inset: 0; background: rgba(44, 40, 48, 0.35);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
.card {
  background: white; border-radius: 28px; padding: 22px 18px 18px; width: min(440px, 100%);
  margin-bottom: calc(8px + env(safe-area-inset-bottom));
}
.card h2 { margin-bottom: 8px; }
.card p { line-height: 1.45; }
.quote { font-size: 18px; margin: 8px 0; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cell {
  background: white; border-radius: 12px; min-height: 72px; padding: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.cell.locked { opacity: 0.35; }
.mini { width: 46px; display: flex; flex-direction: column; gap: 2px; }
.mini b { display: block; height: 4px; border-radius: 99px; background: var(--yang); }
.mini b.break { background: linear-gradient(90deg, var(--yin) 38%, transparent 38% 62%, var(--yin) 62%); }
.toast { color: var(--danger); min-height: 1.2em; font-size: 14px; }
.goalmini { margin: 8px 0 12px; }

/* Sprite skin. Tokens are set only for roles whose PNG loaded. */
body[data-skin~="background"] {
  background-image: var(--skin-background);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}
body[data-skin~="panel"] .banner,
body[data-skin~="panel"] .card,
body[data-skin~="panel"] .level,
body[data-skin~="panel"] .cell {
  background-color: transparent;
  background-image: var(--skin-panel);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: none;
}
body[data-skin~="button"] .btn:not(.ghost) {
  background-color: transparent;
  background-image: var(--skin-button);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
body[data-skin~="buttonGhost"] .btn.ghost {
  background-color: transparent;
  background-image: var(--skin-buttonGhost);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: none;
}
body[data-skin~="chip"] .chip {
  background-color: transparent;
  background-image: var(--skin-chip);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: none;
}
body[data-skin~="barYang"] .bar.yang {
  background-color: transparent;
  background-image: var(--skin-barYang);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
body[data-skin~="barYin"] .bar.yin {
  background-image: var(--skin-barYin);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
body[data-skin~="barYin"] .bar.yin i { visibility: hidden; }
body[data-skin~="barEmpty"] .bar.empty {
  background-color: transparent;
  background-image: var(--skin-barEmpty);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  box-shadow: none;
}
body[data-skin~="slot"] .slot {
  background-image: var(--skin-slot);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  padding: 4px 0;
}
