:root {
  --ink: #1c1c1e;
  --dim: #85827a;
  --paper: #f4f3ef;
  --card: #fff;
  --soft: #e7e4dc;
  --gridline: #ebe8e1;
  --red: #e03131;
  --blue: #4f78b0;
  --cell: 48px;
  --line: 2.5px;
  --r: 12px;
  --step: 110ms;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; background: var(--paper); touch-action: manipulation; overscroll-behavior: none; }

body {
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, sans-serif;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

p, h1, h2 { word-break: auto-phrase; text-wrap: pretty; }
button { font-family: inherit; color: inherit; touch-action: manipulation; -webkit-touch-callout: none; }

#app {
  position: relative;
  height: var(--app-h, 100dvh);
  transform: translateY(var(--app-top, 0px));
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.band { flex: 0 0 auto; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 4px 14px 0; }
.title { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: 1px; white-space: nowrap; }
.dots { display: flex; gap: 5px; margin-right: auto; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); }
.dots i.on { background: var(--ink); }

#main { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.play { position: relative; padding: 4px 12px 8px; display: flex; flex-direction: column; justify-content: center; align-items: center; touch-action: none; min-height: 100%; }
.bwrap { position: relative; width: calc(var(--cell) * 7); height: calc(var(--cell) * 10); transition: transform .35s ease, opacity .35s ease; }
.bwrap.out { transform: translateX(-115%) rotate(-4deg); opacity: 0; }
.bwrap.in0 { transform: translateX(30%); opacity: 0; transition: none; }
.bwrap.thud { animation: thud .32s ease-out; }
@keyframes thud { 0% { translate: 0 0; } 25% { translate: 0 5px; } 55% { translate: 0 -2px; } 100% { translate: 0 0; } }
.layer { position: absolute; inset: 0; pointer-events: none; }
#keys { pointer-events: none; }
#keys .key { pointer-events: auto; }

.rule { position: absolute; top: 0; right: calc(var(--cell) * 2 + 6px); height: var(--cell); margin: 0; display: flex; align-items: center;
  font-size: 14px; font-weight: 700; white-space: nowrap; }
.gi { width: 1.25em; height: 1.25em; margin: 0 1px; }
.fuda { position: absolute; top: 0; left: calc(var(--cell) * 5); width: var(--cell); height: var(--cell); display: flex; align-items: center; justify-content: center; }
.fuda::before { content: ""; position: absolute; inset: 9%; border: 2px solid var(--ink); border-radius: 10px; background: var(--card); box-shadow: 0 2px 0 var(--ink); }
.fuda .hole { left: 0; top: 0; width: 100%; height: 100%; }
.fuda.pulse .hole i::after { animation: stampIn .22s ease-out; }
.fuda.jolt { animation: jolt .34s ease-out; }
@keyframes jolt { 0% { translate: 0 0; } 30% { translate: 0 4px; scale: 1.04 .92; } 60% { translate: 0 -1px; } 100% { translate: 0 0; } }

.floor { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 4px 0 var(--ink)); }
.floor .fl { fill: var(--card); }
.floor .grid line { stroke: var(--gridline); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
.floor .edge { fill: none; stroke: var(--ink); stroke-width: var(--line); vector-effect: non-scaling-stroke; stroke-linejoin: round; }

.hole { position: absolute; display: flex; align-items: center; justify-content: center; }
.hole i { position: relative; width: 76%; height: 76%; border-radius: 50%; border: 3px solid var(--ink); background: var(--card); display: flex; align-items: center; justify-content: center; }
.hole.goal i::after, .hole.red i::after { content: ""; width: 54%; height: 54%; border-radius: 50%; background: var(--red); }
.plate { position: absolute; display: flex; align-items: center; justify-content: center; }
.plate i { width: 78%; height: 78%; border-radius: 10px; border: var(--line) solid var(--ink); background: var(--blue); box-shadow: 0 3px 0 var(--ink); transition: transform .1s, box-shadow .1s; }
.plate.on i { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.door { position: absolute; display: flex; align-items: center; }
.door i { position: relative; margin: 0 6%; width: 88%; height: 26%; border-radius: 6px; border: var(--line) solid var(--ink); background: var(--blue); transform-origin: 0 50%; transition: transform .14s ease, opacity .14s; }
.door.open i { transform: scaleX(.14); }

.rock { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); will-change: transform; z-index: 3; }
.rock i { position: absolute; inset: 19.5%; border-radius: 50%; background: var(--soft); border: var(--line) solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  transform: translateY(-3px); transition: transform .12s cubic-bezier(.5,0,.8,.4), box-shadow .12s; }
.rock i::after { content: ""; position: absolute; left: 30%; right: 30%; top: 50%; height: 2.5px; margin-top: -1.25px; border-radius: 2px; background: #b9b4a8; }
.rock.filled { z-index: 1; }
.rock.filled i { transform: translateY(0); box-shadow: 0 0 0 var(--ink); background: #d9d5ca; }
.rock.filled i::after { opacity: 0; }
.rock.jig i, .key.jig, .fab.jig { animation: jig .52s; }
.rock.onkey i { transform: translateY(0); }

.key { position: absolute; padding: 0; border: 0; background: none; cursor: pointer; }
.key::after { content: ""; position: absolute; inset: 10% 10% 16%; border: var(--line) solid var(--ink); border-radius: 10px; background: var(--card); box-shadow: 0 3px 0 var(--ink); }
.key .ar { position: relative; z-index: 1; width: 42%; height: 42%; display: block; margin: -6% auto 0; }
.key::before { content: ""; position: absolute; inset: -5px; }
.key.down-now::after, .key:active::after, .key.held::after { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.key.down-now .ar, .key:active .ar, .key.held .ar { transform: translateY(3px); }
.key.held::after { background: #f0eee8; }
.key.undo { color: var(--dim); }
.key.undo[aria-disabled="true"] { opacity: .45; }

.pg { position: absolute; left: 0; top: 0; z-index: 4; width: var(--cell); height: var(--cell); pointer-events: none; will-change: transform; }
.pg .pgi { position: absolute; left: 10%; top: 6%; width: 80%; height: 88%; overflow: visible; transform-origin: 50% 100%; }
.pg.left .pgi { transform: scaleX(-1); }
.pg.bump .pgi { animation: bump .28s; }
.pg.left.bump .pgi { animation: bumpL .28s; }
.pg.hop .pgi { animation: hop .5s 2; }
.pg.left.hop .pgi { animation: hopL .5s 2; }
.pg.born .pgi { animation: popin .3s ease-out; }
.pg.hop1 .pgi { animation: hop .36s; }
.pg.left.hop1 .pgi { animation: hopL .36s; }
@keyframes bump { 30% { transform: scaleX(.86) scaleY(1.06); } }
@keyframes bumpL { 0%, 100% { transform: scaleX(-1); } 30% { transform: scaleX(-.86) scaleY(1.06); } }
@keyframes hop { 40% { transform: translateY(-22%); } }
@keyframes hopL { 0%, 100% { transform: scaleX(-1); } 40% { transform: scaleX(-1) translateY(-22%); } }
@keyframes popin { from { transform: scale(.4); opacity: 0; } }

.mark { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; z-index: 5; }
.stamp { position: absolute; width: 100%; height: 100%; pointer-events: none; animation: stampIn .18s ease-out; }
.stamp circle { fill: none; stroke: var(--red); stroke-width: 3; opacity: .9; }
@keyframes stampIn { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.mk { position: absolute; left: 0; top: 0; width: var(--cell); height: var(--cell); }
.mk .stamp { left: -60%; top: -60%; width: 220%; height: 220%; }

.pop { position: absolute; z-index: 20; top: 60px; right: 10px; background: var(--card); border-radius: var(--r); box-shadow: 0 4px 0 var(--ink); animation: pop .18s ease-out; transform-origin: 85% 0; }
.pop::after { content: ""; position: absolute; inset: 0; border: var(--line) solid var(--ink); border-radius: inherit; pointer-events: none; z-index: 6; }
.hpop { width: 232px; }
.gpop { width: 176px; z-index: 22; }
@keyframes pop { from { transform: scale(.2); opacity: .3; } }
.phead { position: relative; height: 46px; display: flex; align-items: center; padding: 0 4px 0 12px; border-bottom: 2px solid var(--ink); }
.ptitle { font-size: 15px; font-weight: 800; letter-spacing: 1px; white-space: nowrap; }
.px { position: absolute; right: 8px; top: 7px; width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--ink); background: var(--card);
  box-shadow: 0 2px 0 var(--ink); font-size: 18px; font-weight: 800; line-height: 1; padding: 0; cursor: pointer; }
.px:active { transform: translateY(2px); box-shadow: none; }
.px::before { content: ""; position: absolute; inset: -6px; }
.pin { position: relative; height: 92px; background: var(--paper); border-radius: 0 0 var(--r) var(--r); overflow: hidden; --cell: 44px; }
.pin .demo { position: absolute; left: 12px; top: 22px; width: calc(var(--cell) * 4.6); height: var(--cell); }
.pin .floor { filter: drop-shadow(0 3px 0 var(--ink)); }
.trail { position: absolute; overflow: visible; pointer-events: none; }
.trail path { fill: none; stroke: #9db4d3; stroke-width: 4px; stroke-linecap: round; stroke-dasharray: 1 9; }
.grows { display: flex; flex-direction: column; }
.grow { height: 46px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 12px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.grow + .grow { border-top: 1.5px solid var(--gridline); }
.glink { width: 100%; border: 0; background: none; font: inherit; font-size: 13px; font-weight: 700; color: inherit; cursor: pointer; text-align: left; }
.glink:active { background: var(--paper); }
.chev { font-size: 16px; color: var(--dim); }
.sw { position: relative; width: 38px; height: 22px; border-radius: 11px; border: 2px solid var(--ink); background: var(--card); padding: 0; cursor: pointer; flex: 0 0 auto; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--ink); transition: left .15s; }
.sw.on { background: var(--blue); }
.sw.on::after { left: 18px; background: #fff; }
.sw::before { content: ""; position: absolute; inset: -12px -4px; }

.fab { position: relative; flex: 0 0 auto; width: 44px; height: 44px;
  border-radius: 12px; border: var(--line) solid var(--ink); background: var(--card); box-shadow: 0 3px 0 var(--ink);
  font-size: 22px; font-weight: 900; line-height: 1; padding: 0; cursor: pointer; }
.fab[aria-expanded="true"] { background: var(--ink); color: #fff; }
.fab:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.gfab svg { width: 60%; height: 60%; display: block; margin: auto; }
.done .fab, .done .pop { display: none; }

@keyframes jig { 0%, 100% { translate: 0 0; rotate: 0deg; } 15% { translate: 0 -3px; rotate: -9deg; } 35% { translate: 0 -3px; rotate: 8deg; } 55% { translate: 0 -2px; rotate: -5deg; } 75% { translate: 0 -1px; rotate: 3deg; } }

.result { padding: 16px 14px 18px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.rhead { display: flex; align-items: center; gap: 14px; }
.rbig { position: relative; width: 56px; height: 56px; flex: 0 0 auto; }
.rbig .stamp { animation: none; inset: 0; }
.rtitle { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: 2px; }
.rsub { margin: 2px 0 0; font-size: 14px; color: var(--dim); }
.rimg { display: block; width: 100%; aspect-ratio: 1200 / 630; border: var(--line) solid var(--ink); border-radius: var(--r); background: var(--paper); }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; height: 48px; font-size: 16px; font-weight: 800;
  border: var(--line) solid var(--ink); border-radius: 12px; background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
}
.btn.x { background: var(--ink); color: #fff; }
.xlogo { width: 18px; height: 18px; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

#foot { padding: 6px 14px 16px; font-size: 12px; text-align: center; color: var(--dim); }

.toast { pointer-events: none; position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; z-index: 50; transition: opacity .5s; }
.toast.out { opacity: 0; }
