@font-face {
  font-family: "Archivo Black";
  src: url("fonts/archivo-black.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk-var.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --paper: #F4F1EA;
  --ink: #111111;
  --red: #E63329;
  --blue: #1B3B8B;
  --yellow: #F2B705;
  --grey: #8A867C;
  --slot: #1d1d1d;
  --cell: 64px;
  --gap: 6px;
  --display: "Archivo Black", Impact, sans-serif;
  --text: "Space Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font-family: var(--text); overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }

#app { height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); gap: 12px; }

header { width: min(100%, 560px); display: flex; align-items: center; gap: 14px; }
.title { font-family: var(--display); font-size: 26px; line-height: .9; letter-spacing: -.5px; text-align: left; }
.title span, h1 span { display: block; color: var(--red); }
.info { flex: 1; min-width: 0; }
#lvlName { font-family: var(--display); font-size: 20px; }
#lvlTier { font-size: 14px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--grey); }
.count { display: flex; gap: 6px; }
.count div { min-width: 64px; padding: 6px 8px; border: 3px solid var(--ink); text-align: center; background: #fff; }
.count div:last-child { background: var(--ink); color: var(--paper); }
.count b { display: block; font-family: var(--display); font-size: 22px; line-height: 1; font-weight: normal; }
.count small { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }

main { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }

#frame {
  position: relative; padding: 14px; background: var(--ink); border-radius: 6px;
  box-shadow: 10px 10px 0 var(--blue);
}
#board {
  position: relative; width: calc(var(--cell) * 6); height: calc(var(--cell) * 6);
  background-color: var(--slot);
  background-image: linear-gradient(#2b2b2b 1px, transparent 1px), linear-gradient(90deg, #2b2b2b 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: -1px -1px;
  touch-action: none;
}
#exit {
  position: absolute; right: -2px; top: calc(14px + var(--cell) * 2); width: 16px; height: var(--cell);
  background: var(--slot); display: flex; flex-direction: column; justify-content: center; align-items: flex-end; gap: 4px; padding-right: 0;
}
#exit::after {
  content: ""; position: absolute; left: 100%; top: 50%; transform: translateY(-50%);
  border: calc(var(--cell) * .22) solid transparent; border-left-color: var(--red); margin-left: 6px;
  animation: nudge 1.4s ease-in-out infinite;
}
#exit i { display: none; }
@keyframes nudge { 50% { transform: translate(5px, -50%); } }

.block {
  position: absolute; left: 0; top: 0; border-radius: 6px; cursor: grab; touch-action: none; user-select: none;
  transition: transform .14s cubic-bezier(.2, .9, .3, 1.2);
  will-change: transform;
}
.block::before { content: ""; position: absolute; inset: var(--gap); border-radius: 6px; background: var(--c); border: 3px solid var(--ink); box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), inset 0 4px 0 rgba(255,255,255,.25); }
.block.h::after, .block.v::after {
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,.22); border-radius: 2px;
}
.block.h::after { width: 30%; height: 4px; }
.block.v::after { width: 4px; height: 30%; }
.block.dragging { transition: none; cursor: grabbing; z-index: 3; }
.block.dragging::before { box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), inset 0 4px 0 rgba(255,255,255,.25), 0 6px 14px rgba(0,0,0,.45); }
.block.target::after { content: "→"; background: none; color: #fff; font-family: var(--display); font-size: calc(var(--cell) * .42); width: auto; height: auto; }
.block.hint::before { animation: hint 0.9s ease-in-out infinite; }
@keyframes hint { 50% { filter: brightness(1.35); transform: scale(1.04); } }
.block.out { transition: transform .45s cubic-bezier(.5, 0, .9, .4); }

.hint-arrow {
  position: absolute; z-index: 4; pointer-events: none; font-family: var(--display); color: var(--yellow); font-size: calc(var(--cell) * .6);
  text-shadow: 0 0 6px var(--ink), 0 0 2px var(--ink); animation: hintArrow .9s ease-in-out infinite;
}
@keyframes hintArrow { 50% { opacity: .35; } }

#tools { width: min(100%, 560px); display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
#tools button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border: 3px solid var(--ink); background: #fff;
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px; font-weight: 600; transition: transform .08s;
}
#tools button span { font-family: var(--display); font-size: 20px; line-height: 1; }
#tools button:active { transform: translate(2px, 2px); }
#tools button:disabled { opacity: .35; cursor: default; }
#bHint { background: var(--yellow) !important; }
#bMute.off span { text-decoration: line-through; opacity: .5; }

.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; background: rgba(17,17,17,.55); padding: 16px; }
.overlay.hidden { display: none; }
.sheet { width: min(100%, 640px); background: var(--paper); border: 4px solid var(--ink); padding: 20px 20px 16px; box-shadow: 10px 10px 0 var(--red); margin: auto 0; }
.sheet-head { position: relative; padding-right: 40px; }
h1 { font-family: var(--display); font-size: clamp(40px, 11vw, 64px); line-height: .85; margin: 0 0 10px; letter-spacing: -1px; }
.sheet-head p { margin: 0 0 14px; font-size: 16px; }
.red { color: var(--red); }
.x { position: absolute; right: 0; top: 0; width: 40px; height: 40px; border: 3px solid var(--ink); font-size: 26px; line-height: 1; background: #fff; }
.tier { margin-top: 14px; }
.tier h3 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; font-family: var(--display); font-weight: normal; font-size: 18px; }
.tier h3 i { width: 14px; height: 14px; display: inline-block; background: var(--tc); border: 2px solid var(--ink); align-self: center; }
.tier h3 small { font-family: var(--text); font-size: 13px; color: var(--grey); margin-left: auto; letter-spacing: .5px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.lv { position: relative; aspect-ratio: 1; border: 3px solid var(--ink); background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--display); font-size: 18px; line-height: 1; }
.lv small { font-family: var(--text); font-size: 11px; letter-spacing: 1px; color: var(--yellow); -webkit-text-stroke: .4px var(--ink); margin-top: 3px; min-height: 11px; }
.lv.done { background: var(--ink); color: var(--paper); }
.lv.current { outline: 3px solid var(--red); outline-offset: 2px; }
.lv:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.foot { margin: 16px 0 0; font-size: 14px; color: var(--grey); }
.link { text-decoration: underline; color: var(--grey); }

#win { align-items: center; }
.card { width: min(100%, 380px); background: var(--paper); border: 4px solid var(--ink); padding: 22px; text-align: center; box-shadow: 10px 10px 0 var(--yellow); animation: pop .35s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.stars { font-size: 44px; letter-spacing: 6px; color: #d6d0c2; }
.stars b { color: var(--yellow); -webkit-text-stroke: 2px var(--ink); font-weight: normal; display: inline-block; animation: star .5s backwards cubic-bezier(.2, .9, .3, 1.6); }
.stars b:nth-child(2) { animation-delay: .15s; } .stars b:nth-child(3) { animation-delay: .3s; }
@keyframes star { from { transform: scale(0) rotate(-40deg); } }
h2 { font-family: var(--display); font-size: 40px; margin: 4px 0; font-weight: normal; }
.card p { margin: 0 0 16px; }
.row { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.btn { flex: 1; padding: 12px; border: 3px solid var(--ink); background: var(--red); color: #fff; font-family: var(--display); font-size: 16px; }
.btn.ghost { background: #fff; color: var(--ink); font-family: var(--text); font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }

@media (max-width: 420px) {
  #app { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .title { font-size: 20px; }
  #lvlName { font-size: 16px; }
  #lvlTier { font-size: 11px; }
  .count div { min-width: 54px; padding: 4px 6px; }
  .count b { font-size: 18px; }
  .count small { font-size: 9px; }
  #frame { padding: 10px; box-shadow: 6px 6px 0 var(--blue); }
  #exit { top: calc(10px + var(--cell) * 2); }
  #tools button { font-size: 9px; letter-spacing: .3px; }
  :root { --gap: 4px; }
}
