:root {
  --paper: #fffdf6;
  --bg: #f6f1e3;
  --ink: #23201b;
  --muted: #6d665a;
  --line: #d9cfb8;
  --accent: #2b59c3;
  --good: #1f8a4c;
  --bad: #c0392b;
  --box: #f3e3c3;
  --private: #fdeef4;
  --sky1: #bfe3ff;
  --sky2: #fff6dc;
  --grass: #9ccf74;
  --dirt: #c9a16b;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe Print", "Marker Felt", cursive;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #24221e; --bg: #1a1916; --ink: #f1ece0; --muted: #b3ab9b; --line: #474238;
    --accent: #7ea2ff; --good: #4cc47f; --bad: #ff7a6b; --box: #4a3f2c; --private: #3d2533;
    --sky1: #1d2a44; --sky2: #3a3350; --grass: #3f6b33; --dirt: #5a4630;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.45; }
code { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .85em; background: var(--box); padding: 0 .3em; border-radius: 4px; }
button {
  font: inherit; cursor: pointer; border: 2px solid var(--ink); background: var(--accent); color: #fff;
  padding: .45em 1em; border-radius: 999px; box-shadow: 3px 3px 0 var(--ink);
}
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
input, select { font: inherit; padding: .25em .5em; border: 2px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
kbd { border: 2px solid var(--ink); border-bottom-width: 3px; border-radius: 6px; padding: 0 .35em; font-size: .85em; background: var(--paper); }

.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5em 1em; padding: .7em 16px; border-bottom: 2px dashed var(--line); background: var(--paper); }
.brand { font-weight: bold; font-size: 1.25em; }
.brand .sub { display: block; font-weight: normal; font-size: .6em; color: var(--muted); }
.keys { font-size: .9em; color: var(--muted); }
main { max-width: 1000px; margin: 0 auto; padding: 1em 16px; }
footer { text-align: center; font-size: .8em; color: var(--muted); padding: 1em 16px 2em; }

/* ---------- game world ---------- */
.game {
  position: relative; height: 380px; overflow: hidden; border: 3px solid var(--ink); border-radius: 16px;
  background: linear-gradient(var(--sky1), var(--sky2)); outline: none;
}
.game:focus-visible { box-shadow: 0 0 0 4px var(--accent); }
.world { position: absolute; top: 0; bottom: 0; left: 0; will-change: transform; }
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 70px; background: var(--dirt); border-top: 10px solid var(--grass); }
.cloud { position: absolute; font-size: 46px; opacity: .85; }
.hud { position: absolute; z-index: 10; top: 8px; left: 10px; right: 10px; display: flex; justify-content: space-between; pointer-events: none; }
.hud > div { background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: .1em .8em; font-size: .9em; }
.hud .used { opacity: .25; }
.toast { position: absolute; z-index: 11; left: 50%; top: 52px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .3em .9em; border-radius: 999px; font-size: .9em; white-space: nowrap; }

.bld { position: absolute; bottom: 70px; transform: translateX(-50%); text-align: center; }
.bld-art { font-size: 92px; line-height: 1; }
.bld-sign { display: inline-block; margin-top: -4px; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 0 .6em; font-size: .85em; white-space: nowrap; }
.bld .door { width: 46px; height: 70px; margin: 0 auto; background: #8a5a2b; border: 3px solid var(--ink); border-radius: 23px 23px 0 0; transform-origin: left; transition: transform .6s; }
.bld .door.open { transform: perspective(200px) rotateY(-70deg); }
.prompt {
  position: absolute; z-index: 5; bottom: 260px; transform: translateX(-50%); background: var(--paper); border: 2px solid var(--ink);
  border-radius: 10px; padding: .1em .6em; font-size: .85em; white-space: nowrap; animation: bob 1s infinite ease-in-out;
}
@keyframes bob { 50% { transform: translate(-50%, -6px); } }

.actor { position: absolute; bottom: 52px; width: 64px; transform: translateX(-50%); text-align: center; }
.actor.player { z-index: 4; width: 70px; }
.actor svg { width: 100%; overflow: visible; }
.actor .tag { display: block; font-size: .7em; color: var(--ink); white-space: nowrap; margin-top: -2px; }
.actor.flip svg { transform: scaleX(-1); }
.walking .leg-l, .walking .arm-r { animation: swingA .4s infinite alternate ease-in-out; }
.walking .leg-r, .walking .arm-l { animation: swingB .4s infinite alternate ease-in-out; }
.leg-l, .leg-r { transform-origin: 30px 68px; }
.arm-l, .arm-r { transform-origin: 30px 40px; }
@keyframes swingA { from { transform: rotate(-16deg); } to { transform: rotate(16deg); } }
@keyframes swingB { from { transform: rotate(16deg); } to { transform: rotate(-16deg); } }
.prop { animation: spin .35s linear infinite; transform-origin: 30px -5px; }
@keyframes spin { 50% { transform: scaleX(-1); } }

.flyer { position: absolute; z-index: 6; bottom: 170px; font-size: 30px; transform: translateX(-50%); transition: left 1s ease-in-out; }
.react { position: absolute; z-index: 6; bottom: 210px; font-size: 34px; transform: translateX(-50%); animation: pop .4s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.2); opacity: 0; } }

/* ---------- dialog ---------- */
.dialog { margin-top: 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; padding: .8em 1.1em; box-shadow: 5px 5px 0 var(--line); animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.dlg-who { font-weight: bold; color: var(--accent); }
.dlg-text { font-size: 1.08em; margin: .2em 0 .4em; }
.dlg-foot { display: flex; justify-content: space-between; align-items: center; gap: 1em; flex-wrap: wrap; }
.dlg-fn { font-size: .75em; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.dlg-next small { opacity: .75; }
.thinking::after { content: " ⏳"; }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6em 1em; margin: .4em 0; }
.form label { display: flex; flex-direction: column; font-size: .9em; }
.form .err { grid-column: 1 / -1; color: var(--bad); min-height: 1.2em; margin: 0; font-size: .9em; }
.note { font-size: .82em; color: var(--muted); }

.envs { display: flex; flex-wrap: wrap; gap: .5em; margin: .4em 0; }
.env { background: var(--box); border: 2px solid var(--ink); border-radius: 8px; padding: .2em .6em; font-size: .85em; animation: pop2 .4s backwards; }
@keyframes pop2 { from { transform: scale(.3); opacity: 0; } }
.env code { background: none; }
.tiles { display: flex; flex-wrap: wrap; gap: 5px; margin: .4em 0; }
.tile { width: 34px; height: 34px; display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 6px; background: var(--box); animation: flipin .4s backwards; }
@keyframes flipin { from { transform: rotateY(90deg); } }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .8em; margin: .4em 0; }
@media (max-width: 640px) { .two { grid-template-columns: 1fr; } }
.two > div { border: 2px solid var(--ink); border-radius: 10px; padding: .4em .8em; }
.two ul { margin: .2em 0; padding-left: 1.2em; }
.never { background: var(--private); }
.secret { filter: blur(5px); cursor: help; transition: filter .2s; }
.secret:hover { filter: none; }
.same { color: var(--bad); font-weight: bold; } .diff { color: var(--good); font-weight: bold; }
.cmp { border-collapse: collapse; font-size: .85em; margin: .3em 0; }
.cmp td, .cmp th { padding: .15em .7em; border-bottom: 1px solid var(--line); text-align: left; }
.summary { margin: .3em 0; padding-left: 1.4em; }
.summary li { margin: .25em 0; }

.pad { display: none; justify-content: center; gap: .8em; margin-top: .8em; }
.pad button { font-size: 1.2em; padding: .4em 1.1em; touch-action: manipulation; user-select: none; }
@media (hover: none), (max-width: 640px) { .pad { display: flex; } .keys { display: none; } .game { height: 330px; } }
.progress { text-align: center; color: var(--muted); font-size: .9em; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
