@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: #040b09;
  --ink: #70f995;
  --bright: #9affb1;
  --muted: #599d72;
  --line: #2a6940;
  --accent: #fa785c;
  color-scheme: dark;
  font: 400 16px/1.4 "Obcoro Pixel", ui-monospace, monospace;
  font-synthesis: none;
  color: var(--ink);
  background: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
           max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
main {
  display: grid;
  grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr);
  max-width: 1040px;
  height: 100%;
  margin: auto;
}

header, .hud, .controls { display: flex; align-items: center; }
header { justify-content: space-between; gap: 12px; padding: 4px 0 8px; }
h1 {
  flex: none;
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: .04em;
  color: var(--bright);
}
.hud { min-width: 0; gap: 10px; margin: 0; }
.hud > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 2px;
  min-width: 0;
  text-align: right;
}
.hud > div + div { padding-left: 10px; border-left: 1px solid var(--line); }
dt, footer { color: var(--muted); }
dt { font-size: 13px; line-height: 16px; }
dd {
  overflow: hidden;
  margin: 0;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
}
#score { color: var(--bright); }

.console {
  display: grid;
  grid-template: minmax(0, 1fr) auto / minmax(0, 1fr);
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  touch-action: none;
}
.field {
  position: relative;
  anchor-name: --stack-field;
  isolation: isolate;
  overflow: hidden;
  min-height: 0;
}
body > .gp-quip {
  top: calc(max(16px, env(safe-area-inset-top)) + 84px);
  top: calc(anchor(--stack-field top) + 5px);
  right: max(var(--gfx-right), calc((100% - 1040px) / 2 + 8px));
}
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; touch-action: none; }
#structure { pointer-events: none; }
canvas:focus-visible { outline: 2px solid var(--bright); outline-offset: -3px; }

.controls {
  min-height: 67px;
  gap: 14px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
#hint {
  display: block;
  margin-top: 3px;
  color: var(--ink);
  font-size: 12px;
  line-height: 16px;
}
#drop-action {
  position: relative;
  isolation: isolate;
  flex: 1 1 0;
  min-width: 44px;
  min-height: 50px;
  max-width: 200px;
  margin-left: auto;
  border: 0;
  border-radius: 0;
  padding: 6px 12px;
  background: transparent;
  font: inherit;
  line-height: 20px;
  color: var(--accent);
  cursor: pointer;
  touch-action: manipulation;
}
#drop-action:focus-visible { outline: 2px solid var(--bright); outline-offset: 2px; }
#drop-action::before, #drop-action::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  background: var(--accent);
}
#drop-action::after { inset: 1px; background: #26130e; }
.key-hint {
  display: none;
  flex: none;
  border: 1px solid var(--line);
  padding: 2px 7px;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
}
.console:active #drop-action::after { background: #4a2419; }
.height-progress {
  flex: 1 1 0;
  max-width: 240px;
  min-width: 0;
}
.height-progress > :first-child {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}
#floor-count { color: var(--bright); font-size: 14px; font-weight: 400; }
.meter { height: 2px; margin-top: 4px; background: var(--line); }
#progress-fill {
  display: block;
  height: 100%;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 160ms ease-out;
}

footer { display: grid; gap: 4px; padding: 6px 0 0; text-align: center; font-size: 13px; line-height: 18px; }

@media (min-width: 621px) {
  body {
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  header { padding: 12px 0 20px; }
  .hud { gap: 24px; }
  .hud > div { grid-template-columns: auto minmax(0, 1fr); gap: 12px; }
  .hud > div + div { padding-left: 24px; }
  dt { font-size: 1rem; line-height: 1.4; }
  dd { font-size: 2rem; }
  .controls { gap: 18px; padding: 10px 22px; }
  footer { padding: 13px 0 4px; }
}
@media (min-width: 621px) and (pointer: fine) {
  .key-hint { display: block; margin-left: auto; }
  #drop-action { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #progress-fill { transition: none; }
}
