@font-face {
  font-family: "Obcoro Pixel";
  src: url("../../assets/fusion-pixel-12px-monospaced-zh_tw.ttf.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #030909;
  --panel: #040b09f7;
  --ink: #70f995;
  --bright: #9affb1;
  --muted: #599d72;
  --line: #2a6940;
  --accent: #fa785c;
  --accent-line: #d45b43;
  --pad-top: max(.75rem, env(safe-area-inset-top));
  --pad-bottom: max(.75rem, env(safe-area-inset-bottom));
  --tap-size: 48px;
  --cut: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  color-scheme: dark;
  font: 400 16px/1.5 "Obcoro Pixel", monospace;
  font-synthesis: none;
  color: var(--ink);
  background: var(--bg);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  height: 100dvh;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: var(--pad-top) max(.75rem, env(safe-area-inset-right))
           var(--pad-bottom) max(.75rem, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button {
  appearance: none;
  border-radius: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  touch-action: none;
}
button:focus-visible { outline: 2px solid var(--bright); outline-offset: 2px; }
button:disabled { cursor: default; }
button { transition: scale 155ms cubic-bezier(.2, 1.65, .34, 1); }
button:not(:disabled):active { scale: .95; transition-duration: 0s; }
main {
  display: flex;
  flex-direction: column;
  width: min(100%, 56rem);
  min-width: 0;
  max-height: 100%;
}
header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .625rem;
  padding-bottom: .625rem;
  border-bottom: 1px solid var(--line);
}
h1 {
  margin: 0;
  color: var(--bright);
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  line-height: 1.15;
  font-weight: 400;
  letter-spacing: .06em;
}
/* Keep the quip in the title area and leave the hint button visible. */
body > .gp-quip {
  left: var(--gfx-left);
  right: auto;
  max-width: min(17rem, calc(100% - var(--gfx-left) - var(--gfx-right) - 11rem));
}
.readout { display: flex; align-items: center; gap: clamp(.5rem, 1.7vw, .875rem); }
#level {
  padding: 0 .42em;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #09170f;
  font-size: .875rem;
  white-space: nowrap;
}
.cut-button {
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  border: 0;
  padding: .25em .8em;
  background: transparent;
  color: var(--accent);
  font-size: .875rem;
}
.cut-button::before, .cut-button::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  clip-path: var(--cut);
  background: var(--accent-line);
}
.cut-button::after { inset: 1px; background: #23140f; }
.cut-button:disabled { opacity: .45; }
.cut-button svg { width: .9em; height: .9em; fill: none; stroke: currentColor; stroke-width: 1.1; }
#board {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
}
#board::before, #board::after {
  content: "";
  position: absolute;
  z-index: 4;
  width: clamp(1.5rem, 6vw, 2.5rem);
  height: 3px;
  background: repeating-linear-gradient(120deg, var(--line) 0 2px, transparent 2px 5px);
  pointer-events: none;
}
#board::before { top: 0; left: clamp(8px, 2vw, 24px); }
#board::after { bottom: 0; right: clamp(8px, 2vw, 24px); }
#scene {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 0;
  height: min(60vh, 32rem);
  height: min(60dvh, 32rem);
  touch-action: none;
  background-color: #08120e;
}
#scene::before, #scene::after {
  content: "";
  position: absolute;
  z-index: 1;
  pointer-events: none;
  top: 45%;
  height: 10%;
  width: 5px;
  opacity: .7;
  background: repeating-linear-gradient(0deg, var(--line) 0 1px, transparent 1px 8px);
}
#scene::before { left: 0; }
#scene::after { right: 0; }
#ground {
  position: absolute;
  left: 50%;
  top: 72%;
  width: min(53%, 18rem);
  height: 11%;
  transform: translate(-50%, -50%);
  image-rendering: pixelated;
  pointer-events: none;
}
#lock, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#lock { cursor: grab; touch-action: none; }
#lock:active { cursor: grabbing; }
#board[aria-disabled="true"] #lock { pointer-events: none; cursor: default; }
#overlay { pointer-events: none; }
.progress { position: absolute; top: clamp(14px, 2.6vw, 25px); left: clamp(14px, 2.6vw, 26px); pointer-events: none; }
.metric-title { display: block; color: var(--muted); font-size: .75rem; letter-spacing: .09em; }
.numbers { position: relative; display: flex; align-items: baseline; gap: .44em; color: var(--muted); font-size: .875rem; line-height: 1.25; }
#removed-count {
  color: var(--bright);
  font-size: 1.75rem;
  font-weight: 400;
  transform-origin: left 70%;
  --pulse-start: scale(1.14);
  --pulse-end: scale(1);
  --pulse-opacity: 1;
  animation-duration: 230ms;
  animation-timing-function: cubic-bezier(.2, .85, .3, 1.2);
}
.gain {
  position: absolute;
  left: calc(100% + 6px);
  bottom: 0;
  color: var(--bright);
  font-size: 1rem;
  opacity: 0;
  --pulse-start: translateY(2px);
  --pulse-end: translateY(-13px);
  --pulse-opacity: 0;
  animation-duration: 620ms;
  animation-timing-function: ease-out;
}
/* Alternating names restart consecutive removals without a synchronous layout read. */
#removed-count[data-pulse="a"], #removed-count[data-pulse="a"] ~ .gain { animation-name: gain-a; }
#removed-count[data-pulse="b"], #removed-count[data-pulse="b"] ~ .gain { animation-name: gain-b; }
@keyframes gain-a {
  from { transform: var(--pulse-start); opacity: 1; }
  58% { opacity: 1; }
  to { transform: var(--pulse-end); opacity: var(--pulse-opacity); }
}
@keyframes gain-b {
  from { transform: var(--pulse-start); opacity: 1; }
  58% { opacity: 1; }
  to { transform: var(--pulse-end); opacity: var(--pulse-opacity); }
}
#combo {
  position: absolute;
  inset: clamp(16px, 2.6vw, 26px) 0 auto;
  width: max-content;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  background: #08150ff5;
  color: var(--ink);
  font-size: .8125rem;
  line-height: 1.35;
  pointer-events: none;
}
#combo::before {
  content: "";
  width: var(--ticks, 2px);
  height: 6px;
  background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 4px);
}
#combo[data-tier="2"] { --ticks: 6px; border-color: #52805f; }
#combo[data-tier="3"] { --ticks: 10px; border-color: var(--ink); color: var(--bright); }
.scene-foot {
  flex: none;
  display: grid;
  grid-template: "status pad undo" auto / minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 8px;
  min-height: calc(2 * var(--tap-size) + 16px);
  padding: 6px clamp(12px, 2.6vw, 24px);
  background: #08120e;
}
.piece-help { grid-area: status; min-width: 0; }
#guide { margin: 0 0 4px; }
#guide canvas { display: block; width: 112px; max-width: 100%; height: 44px; background: #0c1c14; }
#guide figcaption { color: var(--bright); font-size: .6875rem; line-height: 1.5; }
#guide figcaption span + span { color: var(--accent); }
#status { margin: 0; color: var(--muted); font-size: .8125rem; line-height: 1.4; }
#status[data-tone="hit"] { color: var(--accent); }
#status[data-tone="active"] { color: var(--ink); }
#undo {
  grid-area: undo;
  justify-self: end;
  display: flex;
  flex: none;
  align-items: center;
  gap: .35em;
  padding: .35em .1em .35em .55em;
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: .8125rem;
}
#undo:disabled { opacity: .5; }
#undo svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5; }
#move-pad {
  grid-area: pad;
  display: grid;
  grid-template-areas: ". up ." "left down right";
  grid-template-columns: repeat(3, clamp(54px, 6vw, 68px));
  gap: 4px;
}
#move-pad button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-size);
  padding: 2px;
  border: 1px solid var(--ink);
  color: var(--bright);
  background: #10241a;
  line-height: 1.1;
  white-space: nowrap;
}
#move-pad [data-direction="up"] { grid-area: up; }
#move-pad [data-direction="left"] { grid-area: left; }
#move-pad [data-direction="down"] { grid-area: down; }
#move-pad [data-direction="right"] { grid-area: right; }
#move-pad small { margin-top: 3px; font-size: .75rem; }
#move-pad .blocked { border-style: dashed; color: var(--accent); border-color: var(--accent-line); background: #23140f; }
#move-pad .suggested { color: var(--bg); background: var(--ink); }
#pieces {
  display: grid;
  flex: none;
  grid-template-columns: repeat(auto-fit, minmax(var(--tap-size), 1fr));
  gap: clamp(4px, .8vw, 10px);
  border-top: 1px solid var(--line);
  padding: clamp(9px, 1.65vw, 17px);
  background: #07100c;
}
.piece {
  position: relative;
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  height: clamp(55px, 7vw, 70px);
  padding: 0;
  overflow: hidden;
  background: #0b1610;
  border: 1px solid #467b55;
  color: var(--muted);
}
.piece span { position: absolute; top: 2px; left: 6px; font-size: .75rem; line-height: 1; }
.piece canvas { display: block; position: absolute; inset: 18% 4% 0; width: 92%; height: 82%; }
.piece[aria-pressed="true"] { background: #13291a; border-color: var(--ink); color: var(--bright); }
.piece.obstructing { color: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.piece[aria-pressed="true"]::after { content: ""; position: absolute; right: 4px; top: 4px; width: 4px; height: 4px; background: var(--ink); }
.piece:disabled { background: #08110c; border-color: #1c3425; }
.piece:disabled canvas { opacity: .42; }
.piece:disabled::after { content: "\2713"; position: absolute; right: 4px; top: 0; color: var(--ink); font-size: .8rem; }
footer { flex: none; margin-top: .875rem; color: var(--muted); font-size: .75rem; letter-spacing: .04em; text-align: center; }
@media (hover: hover) {
  .cut-button:not(:disabled):hover::after { background: #402019; }
  .piece[aria-pressed="false"]:not(:disabled):hover { border-color: var(--ink); background: #16291c; }
  #move-pad button:not(:disabled):hover { border-color: var(--bright); }
  #undo:not(:disabled):hover { color: var(--bright); }
}
@media (max-width: 550px) {
  #scene { height: 64vh; height: 64dvh; }
  .progress { top: 12px; }
  #removed-count { font-size: 1.5rem; }
  .scene-foot { grid-template: "status pad" 1fr "undo pad" var(--tap-size) / minmax(0, 1fr) auto; }
  #undo { justify-self: start; padding-inline: 0 .55em; }
  .piece span { left: 4px; }
}
@media (max-height: 490px) and (orientation: landscape) {
  body { padding-block: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom)); }
  main { height: 100%; }
  header { padding-bottom: 3px; margin-bottom: 4px; }
  h1 { font-size: 1.5rem; }
  #board { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 5rem; grid-template-rows: minmax(0, 1fr) auto; }
  #scene { height: auto; }
  .scene-foot { grid-area: 2 / 1; grid-template: "status pad undo" auto / minmax(0, 1fr) auto auto; min-height: 0; }
  #move-pad { grid-template-areas: "left right up down"; grid-template-columns: repeat(4, 54px); }
  #pieces { grid-area: 1 / 2 / span 2; grid-template-columns: 1fr; grid-template-rows: repeat(6, minmax(var(--tap-size), 1fr)); gap: 3px; padding: 4px; border: 0; border-left: 1px solid var(--line); overflow-y: auto; }
  .piece { height: 100%; touch-action: pan-y; }
  footer { margin-top: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
  button:not(:disabled):active { scale: 1; }
  #removed-count[data-pulse] { animation-name: none; }
  .gain { --pulse-start: none; --pulse-end: none; }
  #removed-count[data-pulse] ~ .gain { animation-duration: 380ms; }
}
