@font-face { font-family: KMini; src: url(assets/kenney-mini-square.ttf) format('truetype'); font-display: block; }

:root {
  --ink: #1f1d1a; --muted: #6d675d; --line: #e4dfd4; --card: #fff; --bg: #faf8f3;
  --accent: #b9852a; --good: #2f7d43; --bad: #b2402f; --soft: #f5f1e7;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #ece7dc; --muted: #a49d90; --line: #38342e; --card: #1d1b18; --bg: #141310; --soft: #26231f; --good: #6cc183; --bad: #ee7a66; --accent: #e0b358; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.page { max-width: 720px; margin: 0 auto; padding: 24px 14px 40px; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .5em; }
.intro p { margin: 0 0 .7em; }
.hint-line { color: var(--muted); font-size: .95rem; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.toc a { font-size: .85rem; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; text-decoration: none; background: var(--card); }
.toc a:hover { border-color: var(--accent); }

/* ---------- one trick card ---------- */
.trick { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 22px 0; scroll-margin-top: 12px; }
.trick header { display: flex; gap: 12px; align-items: flex-start; }
.trick .num { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; display: grid; place-items: center; margin-top: 2px; }
.trick h2 { margin: 0; font-size: 1.25rem; line-height: 1.3; }
.trick h2 a { text-decoration: none; }
.lede { margin: 2px 0 0; color: var(--muted); font-size: .95rem; }
.task { margin: 12px 0 10px; font-size: .95rem; }
.task b { display: inline-block; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; background: var(--soft); border: 1px solid var(--line); padding: 0 7px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.side { margin: 0; min-width: 0; }
.side figcaption { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: .85rem; }
.tag { font-weight: 700; padding: 1px 9px; border-radius: 99px; font-size: .8rem; }
.off .tag { background: #e9e4da; color: #5e574b; }
.on .tag { background: #d9eedd; color: #1f6532; }
@media (prefers-color-scheme: dark) { .off .tag { background: #3a362f; color: #cfc7b8; } .on .tag { background: #1f3b27; color: #9be0ae; } }
.side code { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewport { position: relative; width: 100%; overflow: hidden; border-radius: 8px; background: #1b1626; outline: none; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.trick.trying .viewport { box-shadow: 0 0 0 2px var(--accent); cursor: pointer; }
.trick.trying .side.active .viewport { box-shadow: 0 0 0 3px var(--good); }
.stats { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 7px; font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats b { color: var(--ink); font-size: .95rem; }
.stats .better b { color: var(--good); }
.stats .worse b { color: var(--bad); }
.stats .lost { color: var(--bad); font-weight: 600; }
.live { font-size: .8rem; color: var(--muted); font-style: italic; min-height: 1.4em; }
.vkeys { margin-top: 6px; font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.vkeys[hidden] { display: none; }
.vkeys button { font: 600 .85rem/1 system-ui, sans-serif; min-width: 36px; padding: 7px 8px; border-radius: 6px; border: 1px solid var(--line); border-bottom-width: 3px; background: var(--card); color: var(--ink); cursor: pointer; }
.vkeys button:active { transform: translateY(2px); border-bottom-width: 1px; }

.caption { margin: 12px 0 10px; padding: 10px 13px; background: var(--soft); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; font-size: .93rem; line-height: 1.5; min-height: 5.2em; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.controls button { font: 600 .9rem system-ui, sans-serif; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.controls .try { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- summary table ---------- */
.summary h2 { font-size: 1.25rem; margin: 30px 0 6px; }
.summary p { color: var(--muted); font-size: .95rem; }
.summary .small { font-size: .85rem; }
#measure { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; font-variant-numeric: tabular-nums; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
td b { color: var(--good); }
tbody tr:last-child > * { border-bottom: 0; }

/* ---------- phone ---------- */
@media (max-width: 600px) {
  .page { padding: 16px 10px 32px; }
  h1 { font-size: 1.4rem; }
  .trick { padding: 13px 12px; border-radius: 12px; }
  .pair { grid-template-columns: 1fr; gap: 16px; }
  .caption { min-height: 7.6em; }
}

/* ---------- solo embed: ?trick=<id>&solo ---------- */
body.solo { background: transparent; }
body.solo .intro, body.solo .summary { display: none; }
body.solo .page { padding: 0; max-width: none; }
body.solo .trick { margin: 0; }

/* =================== the game screen (320 x 240, scaled) =================== */
.screen { position: absolute; left: 0; top: 0; width: 320px; height: 240px; transform-origin: 0 0; overflow: hidden;
  font: 10px/1.2 KMini, monospace; color: #f4ead5; -webkit-font-smoothing: none; user-select: none; -webkit-user-select: none; }
.scene { position: absolute; inset: 0; width: 320px; height: 240px; image-rendering: pixelated; }
.content { position: absolute; inset: 0; }
.trick:not(.trying) .content { pointer-events: none; }
.ico { display: inline-block; background-image: url(assets/tiny-dungeon.png); background-repeat: no-repeat; image-rendering: pixelated; vertical-align: middle; flex: none; }

.hud { position: absolute; left: 6px; right: 6px; top: 3px; height: 16px; display: flex; align-items: center; gap: 8px; text-shadow: 1px 1px 0 #000; }
.hud .hp { color: #e5484d; letter-spacing: 1px; font-size: 11px; }
.hud .hp em { color: #4a3a44; font-style: normal; }
.hud .gold { margin-left: auto; color: #ffd76a; }
.hud .eq { width: 18px; height: 18px; display: grid; place-items: center; background: rgba(0,0,0,.45); border: 1px solid #8a6a4a; border-radius: 2px; }

.gb { font: inherit; color: #f4ead5; background: #4b3d63; border: 1px solid #000; border-radius: 2px; padding: 3px 6px; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 2px 0 #000; display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap; }
.gb:hover, .slot:hover, .row:hover { filter: brightness(1.18); }
.gb.go { background: #3e7b48; }
.gb.warn { background: #973a36; }
.gb.dim { opacity: .55; }
.gb.on { background: #d6a646; color: #22180b; }
.gb.bulk { background: #2f6c86; }
.gb.mem { outline: 1px solid #ffd76a; outline-offset: 1px; }
.gb.mem::before { content: '▸'; color: #ffd76a; margin-right: 2px; }
.kb { font-style: normal; font-size: 8px; line-height: 10px; padding: 0 3px; min-width: 10px; text-align: center; background: #f4ead5; color: #1b1626; border-radius: 2px; box-shadow: 0 1px 0 #000; }
.pressed { filter: brightness(1.45) !important; transform: translateY(1px); }
.hl { outline: 2px solid #ffd76a; outline-offset: -1px; }

.playbar { position: absolute; right: 8px; bottom: 8px; }
.playbar .gb { padding: 5px 10px; }
.hint { position: absolute; left: 8px; bottom: 11px; text-shadow: 1px 1px 0 #000; display: flex; align-items: center; gap: 3px; }

.panel { position: absolute; background: rgba(27,22,38,.97); border: 2px solid #8a6a4a; border-radius: 3px; box-shadow: inset 0 0 0 1px #000, 0 3px 0 rgba(0,0,0,.6); }
.ptitle { color: #ffd76a; font-size: 11px; }
.panel.menu { left: 96px; top: 34px; width: 128px; padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 5px; }
.panel.menu .ptitle { text-align: center; margin-bottom: 1px; }
.panel.menu .gb { justify-content: space-between; padding: 4px 7px; }
.panel.menu .gb.dim { justify-content: flex-start; cursor: default; }
.panel.bag, .panel.shop { left: 5px; right: 5px; top: 21px; bottom: 5px; }
.phead { position: absolute; left: 6px; right: 4px; top: 3px; height: 16px; display: flex; align-items: center; gap: 5px; }
.phead .x { margin-left: auto; padding: 1px 5px; }
.tabs { position: absolute; left: 6px; top: 21px; display: flex; gap: 3px; align-items: center; }
.tabs .gb { padding: 1px 5px; }
.sortlbl { color: #9a8fb0; margin-left: 3px; font-size: 8px; }
.grid { position: absolute; left: 6px; top: 39px; display: grid; grid-template-columns: repeat(6, 34px); grid-auto-rows: 34px; gap: 2px; }
.grid.notabs { top: 23px; }
.slot { position: relative; padding: 0; font: inherit; color: inherit; width: 34px; height: 34px; display: grid; place-items: center; background: #2c2540; border: 1px solid #4b3f61; border-radius: 2px; cursor: pointer; }
.slot.empty { background: #221c31; border-color: #312942; cursor: default; }
.slot.junk { background: #3b3a3f; border-color: #5a5860; }
.slot.junk .ico { filter: saturate(.3); }
.slot.sel { border-color: #ffd76a; box-shadow: 0 0 0 1px #ffd76a; background: #43395c; }
.slot .q { position: absolute; right: 1px; bottom: 0; font-size: 8px; font-weight: normal; text-shadow: 1px 1px 0 #000; }
.slot .pin { position: absolute; left: 1px; top: -1px; color: #ffd76a; font-size: 9px; font-weight: normal; text-shadow: 1px 1px 0 #000; }
.slot .e { position: absolute; right: 1px; top: 0; font-size: 8px; color: #7be08e; font-weight: normal; text-shadow: 1px 1px 0 #000; }
.bagfoot { position: absolute; left: 6px; width: 214px; bottom: 6px; display: flex; align-items: center; gap: 6px; }
.grid.notabs ~ .bagfoot { bottom: 6px; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager .gb { padding: 2px 6px; }
.gb.bulk { margin-left: auto; }
.detail { position: absolute; left: 226px; right: 5px; top: 22px; bottom: 6px; display: flex; flex-direction: column; align-items: stretch; gap: 4px; text-align: center; }
.detail .ico { align-self: center; margin: 2px 0 0; }
.dname { color: #ffd76a; line-height: 1.1; }
.dsub { color: #9a8fb0; font-size: 8px; margin-bottom: 2px; }
.dempty { color: #7d7393; margin-top: 50px; }
.shop .rows { position: absolute; left: 6px; right: 6px; top: 39px; display: flex; flex-direction: column; gap: 3px; }
.row { font: inherit; color: inherit; display: flex; align-items: center; gap: 7px; height: 24px; padding: 0 7px; background: #2c2540; border: 1px solid #4b3f61; border-radius: 2px; cursor: pointer; text-align: left; }
.row.sel { border-color: #ffd76a; box-shadow: 0 0 0 1px #ffd76a; background: #43395c; }
.row .rn { flex: 1; }
.row .own { color: #9a8fb0; font-size: 8px; }
.row .rp { color: #ffd76a; min-width: 30px; text-align: right; }
.buybar { position: absolute; left: 6px; right: 6px; bottom: 7px; display: flex; align-items: center; gap: 5px; }
.buybar .qn { min-width: 18px; text-align: center; font-size: 12px; }
.buybar .buy { margin-left: auto; padding: 4px 8px; }
.buybar .dempty { margin: 0 auto 4px; }

.toast { position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%); display: flex; align-items: center; gap: 7px; white-space: nowrap;
  background: #0f0c16; border: 1px solid #ffd76a; border-radius: 3px; padding: 4px 7px; box-shadow: 0 2px 0 #000; z-index: 3; overflow: hidden; }
.toast.undo { padding-right: 4px; }
.panel.bag ~ .toast { left: 118px; bottom: 40px; }
.toast .undo { background: #d6a646; color: #22180b; padding: 2px 6px; }
.toast .bar { position: absolute; left: 0; bottom: 0; height: 2px; width: 100%; background: #ffd76a; transform-origin: 0 50%; animation: shrink 5s linear forwards; }
.toast.fresh { animation: pop .22s ease-out; }
@keyframes shrink { to { transform: scaleX(0); } }
@keyframes pop { from { transform: translateX(-50%) translateY(6px); opacity: 0; } }
.veil { position: absolute; inset: 0; background: rgba(5,3,10,.6); display: grid; place-items: center; z-index: 4; }
.dialog { width: 190px; background: #1b1626; border: 2px solid #c8a35a; border-radius: 3px; padding: 9px 10px 10px; text-align: center; box-shadow: 0 4px 0 #000; }
.dt { color: #ffd76a; font-size: 11px; margin-bottom: 3px; }
.ds { color: #c9bfdc; margin-bottom: 9px; }
.db { display: flex; gap: 8px; justify-content: center; }
.db .gb { min-width: 58px; padding: 4px 8px; }

.cursor { position: absolute; left: 0; top: 0; width: 22px; height: 22px; margin: -2px 0 0 -3px; image-rendering: pixelated; pointer-events: none; z-index: 10; transform-origin: 3px 2px; filter: drop-shadow(1px 2px 0 rgba(0,0,0,.45)); }
.cursor.click { animation: clk .22s ease-out; }
@keyframes clk { 45% { scale: .78; } }
.trick.trying .cursor { display: none; }
.ripple { position: absolute; width: 18px; height: 18px; margin: -9px 0 0 -9px; border: 2px solid #ffd76a; border-radius: 50%; pointer-events: none; z-index: 9; animation: ripple .45s ease-out forwards; }
@keyframes ripple { from { transform: scale(.3); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.keypop { position: absolute; left: 50%; top: 92px; min-width: 40px; height: 40px; padding: 0 10px; margin-left: -20px; display: grid; place-items: center; font: 18px KMini, monospace; font-style: normal;
  background: #f4ead5; color: #1b1626; border-radius: 5px; box-shadow: 0 4px 0 #8f846e, 0 6px 0 #000; z-index: 11; pointer-events: none; animation: keypop .85s ease-out forwards; }
@keyframes keypop { 0% { transform: translateY(6px) scale(.8); opacity: 0; } 15% { transform: none; opacity: 1; } 30% { transform: translateY(3px); box-shadow: 0 1px 0 #8f846e, 0 3px 0 #000; } 45% { transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }
.done { position: absolute; left: 50%; top: 3px; transform: translateX(-50%); background: #2f7d43; color: #fff; padding: 2px 8px; border-radius: 2px; z-index: 12; box-shadow: 0 2px 0 #000; }
.done.fail { background: #973a36; }
.done[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .ripple, .keypop, .toast.fresh, .cursor.click { animation-duration: .01s; }
}
