
:root {
  --ink: #1f1b24; --muted: #625b69; --bg: #f7f4ef; --card: #fff; --line: #e5dfd7;
  --off: #8b8391; --on: #23905f; --gold: #ffd36b; --red: #ff5a52; --cream: #f3e8d6;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 720px; margin: 0 auto; padding: 16px 12px 20px; }

.intro h1 { font-size: 22px; line-height: 1.2; margin: 0 0 6px; }
.intro p { margin: 0 0 12px; color: var(--muted); }
.k-off { color: var(--off); } .k-on { color: var(--on); }

.tabbar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; padding: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab, .arrow, .btn, .pad button {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tab { flex: 1 0 auto; border-radius: 999px; padding: 5px 11px; font-size: 13px; white-space: nowrap; }
.tab .n { display: inline-block; min-width: 1.4em; height: 1.4em; line-height: 1.4em; border-radius: 50%; background: var(--line); font-size: 11px; font-weight: 700; text-align: center; margin-right: 2px; }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab[aria-selected="true"] .n { background: var(--gold); color: var(--ink); }
.arrow { width: 32px; height: 32px; border-radius: 50%; font-size: 20px; line-height: 1; flex: none; padding: 0; }
.tab:hover, .arrow:hover, .btn:hover { border-color: #bdb4a8; }
:focus-visible { outline: 2px solid #3b7cf0; outline-offset: 2px; }

.demo { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.demo-head h2 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
.demo-head .num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--gold); font-size: 13px; }
.demo-head .why { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.pane { margin: 0; min-width: 0; }
.tag { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 5px; }
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.off .tag { color: var(--off); } .on .tag { color: var(--on); }
.screen {
  position: relative; aspect-ratio: 12 / 10; background: #120d16; border-radius: 8px; overflow: hidden;
  container-type: inline-size; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.on .screen { box-shadow: 0 0 0 2px var(--on); }
.screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.playing .screen { cursor: pointer; }
.cap { margin: 7px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--muted); min-height: 4.35em; }
.on .cap { color: var(--ink); }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.btn { border-radius: 8px; padding: 6px 12px; font-size: 14px; }
.btn.play { background: var(--ink); color: #fff; border-color: var(--ink); }
.hint { font-size: 12.5px; color: var(--muted); }

.pad { display: grid; grid-template-columns: repeat(3, 52px) 12px 72px; grid-template-rows: repeat(3, 40px); gap: 6px; justify-content: center; margin-top: 10px; }
.pad[hidden] { display: none; }
.pad button { border-radius: 8px; font-size: 15px; padding: 0; }
.pad [data-a=up] { grid-column: 2; grid-row: 1; }
.pad [data-a=left] { grid-column: 1; grid-row: 2; }
.pad [data-a=wait] { grid-column: 2; grid-row: 2; font-size: 12px; color: var(--muted); }
.pad [data-a=right] { grid-column: 3; grid-row: 2; }
.pad [data-a=down] { grid-column: 2; grid-row: 3; }
.pad .pot { grid-column: 5; grid-row: 2; display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 700; }
.pad .pot .spr { width: 22px; height: 22px; }
.pad button:active { background: #efe9e0; }

.foot { margin-top: 12px; font-size: 12px; color: var(--muted); }
.foot a { color: inherit; }

/* solo: one trick, nothing else */
.solo body { background: transparent; }
.solo .intro, .solo .tabbar, .solo .foot { display: none; }
.solo #app { padding: 0; }

/* sprites from the Kenney sheet */
.spr {
  display: inline-block; flex: none; width: 1.3em; height: 1.3em; vertical-align: middle;
  background: url(assets/tiny-dungeon.png) var(--sx) var(--sy) / 1200% 1100% no-repeat; image-rendering: pixelated;
}
.spr.big { width: 2.6em; height: 2.6em; }
.spr.huge { width: 15cqw; height: 15cqw; position: relative; }
.spr.sil { filter: brightness(0) invert(.55); }
.spr.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.18); filter: drop-shadow(0 0 .25em var(--gold)); } }

/* ---------- end screens (inside the game screen) ---------- */
.end {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3.5cqw 5cqw 3cqw; background: rgba(14, 9, 18, .9); color: var(--cream);
  font-family: KPixel, ui-monospace, monospace; font-size: 7cqw; line-height: 1;
  opacity: 0; transition: opacity .35s;
}
.end.show { opacity: 1; }
.go { font-size: 16cqw; color: var(--red); letter-spacing: .03em; text-shadow: 0 .8cqw 0 #5b1621; }
.retry {
  margin-top: 4cqw; font: inherit; color: var(--gold); background: none; border: 0; padding: 1cqw 3cqw; cursor: pointer;
  animation: blink 1.1s steps(2, jump-none) infinite;
}
@keyframes blink { 50% { opacity: .35; } }
.end.has-trick { justify-content: flex-start; }
.end.has-trick .go { font-size: 9cqw; }
.end.has-trick .retry { margin-top: 1.5cqw; font-size: 6.5cqw; }
.trick { width: 100%; flex: 1; display: flex; flex-direction: column; justify-content: safe center; min-height: 0; padding-top: 1.5cqw; }
.dim { color: #a99bb0; }
.red { color: var(--red); font-weight: normal; }
.gold { color: var(--gold); }
.trick b { font-weight: normal; color: #fff; }

.rr-line, .rr-total, .dr-killer, .dr-head, .dr-row, .mp-gain, .mp-note, .nt > *, .ur-card {
  opacity: 0; transform: translateY(1.5cqw); transition: opacity .2s, transform .2s;
}
.in { opacity: 1 !important; transform: none !important; }

/* run recap */
.rr { display: flex; flex-direction: column; gap: 2.4cqw; }
.rr-line { display: grid; grid-template-columns: 1fr auto 3.2em; gap: 2cqw; align-items: baseline; }
.rr-line .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rr-line em { font-style: normal; color: var(--gold); }
.rr-line .val { color: #fff; }
.rr-line .pts, .rr-total .sc { color: #9be36b; text-align: right; }
.rr-total { display: flex; justify-content: space-between; align-items: center; gap: 2cqw; border-top: .5cqw solid #3a2c42; padding-top: 2.4cqw; font-size: 7.5cqw; }
.rr-total .sc { font-size: 1.15em; }
.best { font-size: 5.6cqw; color: #1f1b24; background: #cdbfd3; padding: .8cqw 2cqw; border-radius: 1cqw; white-space: nowrap; }
.best.new { background: var(--gold); }

/* death recap */
.dr { display: flex; flex-direction: column; gap: 1.4cqw; }
.dr-killer { display: flex; align-items: center; gap: 2.4cqw; background: #2a1a2a; border: .5cqw solid #5b1621; border-radius: 1.5cqw; padding: 1.2cqw 2.4cqw; line-height: 1.05; font-size: 6cqw; }
.dr-killer .spr.big { width: 11cqw; height: 11cqw; }
.dr-killer .kname { font-size: 7.5cqw; color: #fff; }
.dr-head { font-size: 5.4cqw; margin-top: .6cqw; }
.dr-row { display: grid; grid-template-columns: 7cqw 34cqw 1fr 5cqw; align-items: center; gap: 2cqw; font-size: 6cqw; }
.dr-row .spr { width: 7cqw; height: 7cqw; }
.dr-row .nm { white-space: nowrap; }
.dr-row .track { height: 3cqw; background: #2d2234; border-radius: .6cqw; overflow: hidden; }
.dr-row .bar { display: block; height: 100%; width: 0; background: var(--red); transition: width .5s cubic-bezier(.2, .8, .2, 1) .1s; }
.dr-row.in .bar { width: var(--w); }
.dr-row .amt { text-align: right; color: #fff; }
.dr-row .nm { font-size: 5.6cqw; }

/* permanent progress */
.mp { display: flex; flex-direction: column; align-items: center; gap: 2.6cqw; width: 100%; transition: opacity .25s, transform .25s; }
.mp-gain { font-size: 11cqw; color: #9be36b; }
.mp-next { display: flex; align-items: center; gap: 1.6cqw; font-size: 6.5cqw; }
.mp-next .spr { width: 9cqw; height: 9cqw; }
.mp-bar { position: relative; width: 100%; height: 6cqw; background: #2d2234; border: .6cqw solid #4a3a52; border-radius: 1.5cqw; overflow: hidden; }
.mp-bar .old { position: absolute; left: 0; top: 0; bottom: 0; background: #6f6a2e; }
.mp-bar .fill { position: absolute; top: 0; bottom: 0; width: 0; background: linear-gradient(#ffe48a, #f0b23a); box-shadow: 0 0 2cqw #f0b23a; }
.mp.full .mp-bar { border-color: var(--gold); }
.mp-num { font-size: 6cqw; color: #fff; }
.mp-note { font-size: 6cqw; text-align: center; }
.mp-note .dim { font-size: .9em; }

/* unlock reveal */
.ur { position: relative; width: 100%; flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.ur::after { content: ""; position: absolute; inset: -20cqw; background: #fff; opacity: 0; pointer-events: none; }
.ur.flash::after { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }
.mp.gone { position: absolute; opacity: 0; transform: scale(.9); pointer-events: none; }
.ur-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 1.2cqw; transform: scale(.6); transition: opacity .25s, transform .45s cubic-bezier(.3, 1.6, .5, 1); }
.ur-art { position: relative; display: grid; place-items: center; width: 24cqw; height: 17cqw; }
.ur-art .rays {
  position: absolute; inset: -4cqw -2cqw; border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 211, 107, .45) 0 12deg, transparent 12deg 30deg);
  -webkit-mask: radial-gradient(circle, #000 25%, transparent 70%); mask: radial-gradient(circle, #000 25%, transparent 70%);
  animation: spin 6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ur-kind { font-size: 6cqw; color: var(--gold); letter-spacing: .08em; text-transform: uppercase; }
.ur-name { font-size: 9cqw; color: #fff; }
.ur-desc { font-size: 6cqw; }
.ur-where { font-size: 5.6cqw; color: #9be36b; line-height: 1.1; }

/* next try */
.nt { display: flex; flex-direction: column; gap: 1.8cqw; }
.nt-head { font-size: 5.6cqw; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; }
.nt-tip, .nt-item { display: flex; align-items: flex-start; gap: 2.4cqw; line-height: 1.1; font-size: 6.2cqw; }
.nt-tip p, .nt-item p { margin: 0; }
.nt-tip .spr, .nt-item .spr { width: 10cqw; height: 10cqw; }
.nt-item { background: #2b2032; border-radius: 1.5cqw; padding: 1.6cqw 2.4cqw; align-items: center; }

@media (max-width: 560px) {
  .panes { grid-template-columns: 1fr; gap: 14px; }
  .cap { min-height: 0; }
  .intro h1 { font-size: 20px; }
  .demo { padding: 12px; border-radius: 12px; }
  .end { font-size: 6.2cqw; }
}
@media (prefers-reduced-motion: reduce) {
  .spr.pulse, .ur-art .rays, .retry { animation: none; }
  .ur.flash::after { animation: none; }
}
