@font-face { font-family: KMini; src: url(assets/fonts/KenneyMini.ttf) format("truetype"); font-display: block; }
@font-face { font-family: KPixel; src: url(assets/fonts/KenneyPixel.ttf) format("truetype"); font-display: block; }

:root {
  --ink: #1f1c24; --muted: #625c6b; --card: #f8f6f1; --line: #e2ddd3;
  --off: #a2413a; --on: #2f7d4f; --term: #ffcf5a;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: #fff; }
main { max-width: 720px; margin: 0 auto; padding: 8px; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 8px 0 6px; }
h2 { font-size: 1.1rem; margin: 0 0 2px; display: flex; align-items: center; gap: 8px; }
h2 .n { font: 13px/1 KMini, monospace; background: var(--ink); color: #fff; border-radius: 4px; padding: 5px 6px 4px; }
.intro p { margin: 0 0 14px; color: var(--muted); }
.lede { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
.trick, .measure { border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 12px 10px 10px; margin: 0 0 18px; }
.foot { color: var(--muted); font-size: .8rem; text-align: center; padding: 4px 0 16px; }
code { font-size: .85em; background: #eee9df; padding: 1px 4px; border-radius: 3px; }

/* ---------- pair ---------- */
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 560px) { .pair { grid-template-columns: 1fr; gap: 12px; } }
.side { margin: 0; min-width: 0; }
.side figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 4px; }
.side figcaption code { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 11px; white-space: nowrap; }
.side.off figcaption { color: var(--off); }
.side.on figcaption { color: var(--on); }
.side.off code { background: #f3dcd8; }
.side.on code { background: #d7ecdf; }
.view { position: relative; width: 100%; aspect-ratio: 288 / 208; overflow: hidden; border-radius: 6px; background: #1b1820; box-shadow: 0 0 0 2px #1b1820; touch-action: manipulation; -webkit-user-select: none; user-select: none; outline: none; }
.side.on .view { box-shadow: 0 0 0 2px #1b1820, 0 0 0 4px #7cc79a; }
.side.off .view { box-shadow: 0 0 0 2px #1b1820, 0 0 0 4px #e3a59d; }
.view:focus-visible { box-shadow: 0 0 0 2px #1b1820, 0 0 0 4px #3b82f6 !important; }

.bar { display: flex; align-items: center; gap: 8px; margin-top: 10px; min-height: 44px; }
.caption { flex: 1; margin: 0; font-size: .9rem; line-height: 1.35; min-height: 2.7em; display: flex; align-items: center; }
.caption .step { font: 11px/1 KMini, monospace; color: var(--muted); margin-right: 6px; white-space: nowrap; }
.bar button { font: 600 13px/1 system-ui, sans-serif; border: 1px solid #cfc8bb; background: #fff; color: var(--ink); border-radius: 6px; padding: 9px 11px; cursor: pointer; white-space: nowrap; min-height: 36px; }
.bar button:hover { background: #f0ece4; }
.bar button.try[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
@media (max-width: 420px) { .bar { flex-wrap: wrap; } .caption { flex-basis: 100%; } .bar button { flex: 1; } }

/* ---------- solo ---------- */
body.solo .intro, body.solo .measure, body.solo .foot { display: none; }
body.solo .trick { display: none; }
body.solo .trick.solo-on { display: block; margin: 0; }
body.solo main { padding: 4px; }

/* ---------- stage (logical 288 x 208) ---------- */
.stage { position: absolute; left: 0; top: 0; width: 288px; height: 208px; transform-origin: 0 0; font: 10px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #f1ece4; overflow: hidden; }
.view:not(.live) .stage { pointer-events: none; }
.spr { background-image: url(assets/tiny-dungeon.png); background-repeat: no-repeat; image-rendering: pixelated; }
.map { position: absolute; left: 0; top: 0; width: 288px; height: 160px; }
.tile { position: absolute; }
.turn { position: absolute; left: 4px; top: 4px; font: 8px/1 KMini, monospace; background: #0009; padding: 3px 4px 2px; border-radius: 2px; letter-spacing: .05em; }
.topbtn { position: absolute; top: 3px; height: 15px; font: 8px/1 KMini, monospace; color: #f1ece4; background: #2b2633; border: 1px solid #5d556b; border-radius: 2px; padding: 0 4px; cursor: pointer; display: flex; align-items: center; gap: 3px; }
.topbtn.hov, .topbtn:hover { background: #3c3547; }

.unit { position: absolute; width: 32px; height: 32px; transition: left .18s, top .18s, opacity .5s, transform .5s; cursor: pointer; }
.unit .spr { position: absolute; left: 0; top: 0; }
.unit.flip .body { transform: scaleX(-1); }
.unit .hpb { position: absolute; left: 4px; bottom: -1px; width: 24px; height: 3px; background: #000a; }
.unit .hpb i { display: block; height: 100%; background: #e04b4b; transition: width .3s; }
.unit.p .hpb i { background: #57c26a; }
.unit .sel { position: absolute; left: 0; top: 0; display: none; animation: bob 1.2s ease-in-out infinite; }
.unit.selected .sel { display: block; }
.unit.targetable .body { filter: drop-shadow(0 0 1px #ff6b5a) drop-shadow(0 0 1px #ff6b5a); }
.unit.hov .body { filter: brightness(1.25); }
.unit.targetable.hov .body { filter: drop-shadow(0 0 1px #ff6b5a) drop-shadow(0 0 1px #ff6b5a) brightness(1.3); }
.unit.dead { opacity: 0; transform: translateY(6px) scale(.8); pointer-events: none; }
.unit.guarded .body { filter: drop-shadow(0 0 2px #7fb2ff); }
.unit.hit .body { animation: hit .3s; }
.unit.lunge .body { animation: lunge .3s; }
@keyframes bob { 50% { transform: translateY(-1px); } }
@keyframes hit { 30% { transform: translateX(2px); filter: brightness(3); } 60% { transform: translateX(-2px); } }
@keyframes lunge { 40% { transform: translateX(8px); } }
.ustat { position: absolute; left: -3px; top: -3px; display: flex; gap: 1px; }
.ustat .st { width: 11px; height: 11px; position: relative; background: #000b; border-radius: 2px; padding: 1px; }
.ustat .st b { position: absolute; right: -4px; bottom: -4px; font: 7px/1 KMini, monospace; background: #111; color: #fff; border-radius: 2px; padding: 1px 1px 0; min-width: 7px; text-align: center; }
.face { position: absolute; top: 10px; width: 8px; height: 12px; font: 700 11px/11px system-ui, sans-serif; text-align: center; color: #ffcf5a; background: #000a; border-radius: 2px; }
.preview { position: absolute; left: 50%; top: -12px; transform: translateX(-50%); white-space: nowrap; font: 8px/1 KMini, monospace; color: #1b1820; background: #ffcf5a; padding: 2px 3px 1px; border-radius: 2px; }
.uhint { position: absolute; left: 30px; top: -2px; white-space: nowrap; font: 7px/1 KMini, monospace; color: #cfc6da; background: #000b; padding: 2px 2px 1px; border-radius: 2px; }
.uhint kbd { color: #1b1820; }

/* HUD */
.hud { position: absolute; left: 0; top: 160px; width: 288px; height: 48px; background: #221e29; border-top: 2px solid #3a3343; }
.card { position: absolute; left: 4px; top: 6px; width: 112px; height: 36px; }
.card .por { position: absolute; left: 0; top: 2px; width: 32px; height: 32px; background-color: #3a3343; border-radius: 3px; }
.card .nm { position: absolute; left: 36px; top: 0; font: 9px/1 KMini, monospace; white-space: nowrap; }
.card .hp { position: absolute; left: 36px; top: 12px; width: 52px; height: 6px; background: #000a; border-radius: 1px; }
.card .hp i { display: block; height: 100%; background: #57c26a; border-radius: 1px; transition: width .3s; }
.card .hpt { position: absolute; left: 91px; top: 11px; font: 8px/1 KMini, monospace; color: #cfc6da; }
.card .sts { position: absolute; left: 36px; top: 22px; display: flex; gap: 3px; }
.st { width: 12px; height: 12px; display: block; }
.st svg { width: 100%; height: 100%; display: block; }
.card .st { width: 13px; height: 13px; cursor: help; border-radius: 2px; }
.card .st.hov, .card .st:hover { background: #ffffff22; }
.acts { position: absolute; left: 120px; top: 8px; display: flex; gap: 3px; }
.act { position: relative; width: 29px; height: 29px; padding: 0; background: #322c3b; border: 1px solid #5d556b; border-radius: 3px; cursor: pointer; display: grid; place-items: center; }
.act.hov, .act:hover { background: #453d52; border-color: #8a7f9a; }
.act.armed { border-color: #ffcf5a; background: #4f4330; box-shadow: 0 0 0 1px #ffcf5a; }
.act.press { transform: translateY(1px); background: #5c5068; }
.act .spr { width: 24px; height: 24px; }
.act.used { opacity: .45; }
.kb { position: absolute; right: -3px; top: -4px; font: 7px/1 KMini, monospace; background: #f1ece4; color: #1b1820; border-radius: 2px; padding: 2px 2px 1px; box-shadow: 0 1px 0 #0008; }
.endb { position: absolute; left: 249px; top: 8px; width: 35px; height: 29px; font: 9px/1 KMini, monospace; color: #f1ece4; background: #5a3a2c; border: 1px solid #9a6a4d; border-radius: 3px; cursor: pointer; padding: 0; }
.endb.hov, .endb:hover { background: #774c39; }
.endb.press { transform: translateY(1px); }
.endb .kb { right: auto; left: 50%; transform: translateX(-50%); top: auto; bottom: -5px; }

/* FX */
.fx { position: absolute; inset: 0; pointer-events: none; }
.float { position: absolute; transform: translateX(-50%); font: 16px/1 KPixel, monospace; color: #ff5b4f; text-shadow: 1px 1px 0 #000, -1px 1px 0 #000; animation: rise 1s forwards; white-space: nowrap; }
.float.heal { color: #6fe08a; }
.float.note { color: #d9d2e3; font-size: 13px; }
.callout { position: absolute; transform: translateX(-50%); font: 9px/1 KMini, monospace; color: #1b1820; background: #ffcf5a; border: 1px solid #1b1820; padding: 3px 4px 2px; border-radius: 2px; white-space: nowrap; animation: callout 1.4s forwards; z-index: 2; }
.callout.bad { background: #ff8e7a; }
.callout.blue { background: #a9c9ff; }
@keyframes rise { 0% { opacity: 0; margin-top: 4px; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: -14px; } }
@keyframes callout { 0% { opacity: 0; transform: translate(-50%, 4px) scale(.8); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 20% { transform: translate(-50%, 0) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -6px); } }
.banner { position: absolute; left: 50%; top: 22px; transform: translateX(-50%); background: #120f16ee; border: 1px solid #5d556b; border-radius: 3px; padding: 4px 8px 3px; text-align: center; white-space: nowrap; animation: banner 2.6s forwards; z-index: 3; }
.banner .t { font: 10px/1.1 KMini, monospace; }
.banner .c { font-size: 9.5px; color: #ffcf5a; margin-top: 2px; }
@keyframes banner { 0% { opacity: 0; } 8% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
.keycap { position: absolute; right: 5px; top: 136px; font: 9px/1 KMini, monospace; background: #f1ece4; color: #1b1820; border-radius: 3px; padding: 4px 5px 3px; box-shadow: 0 2px 0 #8a7f9a; animation: banner 1.1s forwards; z-index: 4; }
.keycap small { font: 8px/1 system-ui, sans-serif; color: #625c6b; margin-left: 3px; }

/* tooltips */
.tips { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.tip { position: absolute; pointer-events: auto; max-width: 172px; background: #141118f2; border: 1px solid #6c6380; border-radius: 3px; padding: 4px 6px 5px; box-shadow: 0 2px 6px #000a; animation: tipin .12s ease-out; }
.tip[data-level="1"] { border-color: #b59a52; background: #1c1810f5; }
@keyframes tipin { from { opacity: 0; transform: translateY(2px); } }
.tip .tt { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 10px; color: #fff; margin-bottom: 1px; }
.tip .tt kbd { font: 7px/1 KMini, monospace; background: #f1ece4; color: #1b1820; border-radius: 2px; padding: 2px 2px 1px; align-self: center; }
.tip .tb { font-size: 9.5px; color: #d9d2e3; }
.tip .tb b { color: #fff; }
.tip .tb.raw { font: 8.5px/1.35 ui-monospace, Menlo, monospace; color: #b9b0c6; word-spacing: -1px; }
.tip .tf { margin-top: 3px; font-size: 8.5px; color: #ffcf5a; cursor: pointer; }
.tip .tf.hov, .tip .tf:hover { text-decoration: underline; }
.term { color: var(--term); font-weight: 700; border-bottom: 1px dotted #ffcf5a99; cursor: help; }
.term.hov, .term:hover { background: #ffcf5a33; }
.lockbar { position: absolute; left: 2px; right: 2px; bottom: 1px; height: 2px; background: #ffffff14; border-radius: 1px; overflow: hidden; }
.lockbar i { display: block; height: 100%; width: 0; background: #ffcf5a; }
.tip.locking .lockbar i { width: 100%; transition: width 1s linear; }
.tip.locked { border-color: #ffcf5a; }
.tip.locked .tt::after { content: "pinned"; font: 7px/1 KMini, monospace; color: #ffcf5a; align-self: center; margin-left: auto; }
.tip.locked .tt kbd { margin-left: 4px; }

/* overlays */
.ov { position: absolute; left: 8px; top: 6px; width: 272px; height: 150px; background: #141118f5; border: 1px solid #8a7f9a; border-radius: 4px; padding: 6px 8px; z-index: 5; animation: tipin .15s ease-out; }
.ov h3 { margin: 0 0 4px; font: 10px/1 KMini, monospace; color: #fff; display: flex; justify-content: space-between; }
.ov .x { font: 9px/1 KMini, monospace; color: #cfc6da; cursor: pointer; background: none; border: 1px solid #5d556b; border-radius: 2px; padding: 2px 3px 1px; }
.gl { display: grid; gap: 3px; }
.gl div { font-size: 9px; color: #d9d2e3; padding: 2px 4px; border-radius: 2px; }
.gl div.hl { background: #ffcf5a26; box-shadow: inset 2px 0 #ffcf5a; }
.keys { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 4px 6px; align-items: center; font-size: 9px; color: #d9d2e3; }
.keys kbd { font: 8px/1 KMini, monospace; background: #f1ece4; color: #1b1820; border-radius: 2px; padding: 2px 3px 1px; justify-self: end; white-space: nowrap; }
.ov .note { font-size: 8.5px; color: #8f869c; margin-top: 6px; }
.pause { display: grid; gap: 4px; justify-items: center; padding-top: 14px; }
.pause button { font: 9px/1 KMini, monospace; color: #f1ece4; background: #322c3b; border: 1px solid #5d556b; border-radius: 3px; padding: 5px 8px 4px; width: 130px; cursor: pointer; display: flex; justify-content: space-between; }
.pause button.hov, .pause button:hover { background: #453d52; }
.pause kbd { font: 7px/1 KMini, monospace; background: #f1ece4; color: #1b1820; border-radius: 2px; padding: 1px 2px; }

/* cursor */
.cur { position: absolute; left: 0; top: 0; width: 13px; height: 19px; z-index: 9; pointer-events: none; will-change: transform; }
.cur svg { width: 100%; height: 100%; display: block; filter: drop-shadow(1px 1px 0 #0007); }
.ring { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid #fff; border-radius: 50%; animation: ring .4s forwards; z-index: 8; pointer-events: none; }
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.2); opacity: 0; } }
.view.live .cur { display: none; }

/* measure */
.mt { width: 100%; border-collapse: collapse; font-size: .88rem; }
.mt th, .mt td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.mt td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.mt th.v { text-align: right; }
.mt .bad { color: var(--off); } .mt .good { color: var(--on); }
.mt small { color: var(--muted); display: block; font-size: .78rem; }

@media (prefers-reduced-motion: reduce) {
  .unit, .float, .callout, .banner, .tip, .ring { animation-duration: .01s !important; transition: none !important; }
}
