@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;
  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; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  --screen-height: 100vh;
  --gutter: clamp(.5rem, 2vw, 1.25rem);
  --top: max(var(--gutter), env(safe-area-inset-top, 0px));
  --bottom: max(var(--gutter), env(safe-area-inset-bottom, 0px));
  --bar-height: 44px;
  --section-gap: clamp(.375rem, 1vh, .625rem);
  --rim: clamp(.25rem, 1vw, .625rem);
  --trim: calc(2px + 2 * var(--rim));
  --world-width: 296;
  --world-height: 310;
  --hud-height: 3.75rem;
  --field-height: calc(var(--screen-height) - var(--top) - var(--bottom) - 2 * (var(--bar-height) + var(--section-gap)) - var(--trim) - 22px);
  height: var(--screen-height);
  display: grid;
  grid-template: minmax(0, 1fr) auto minmax(0, .5fr) / minmax(0, 1fr);
  place-items: center;
  padding: var(--top) max(var(--gutter), env(safe-area-inset-right, 0px))
           var(--bottom) max(var(--gutter), env(safe-area-inset-left, 0px));
  -webkit-tap-highlight-color: transparent;
}
@supports (height: 100dvh) {
  body { --screen-height: 100dvh; --section-gap: clamp(.375rem, 1dvh, .625rem); }
}
main {
  grid-row: 2;
  display: grid;
  gap: var(--section-gap);
  /* Use the full phone width until the canvas reaches its height budget. */
  width: min(100%, 30rem, calc((var(--field-height) - var(--hud-height)) * var(--world-width) / var(--world-height) + var(--trim)));
  min-width: 0;
}
header, footer { min-height: var(--bar-height); }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .625rem;
}
h1 {
  margin: 0;
  color: var(--bright);
  font-size: clamp(1.5rem, 6.8vw, 2.25rem);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: .06em;
  white-space: nowrap;
}
#status { text-align: end; margin: 0; min-height: 1.3em; font-size: .875rem; line-height: 1.3; }
footer {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}

#board {
  position: relative;
  container-type: inline-size;
  min-width: 44px;
  min-height: 44px;
  padding: var(--rim);
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
/* Keep the press cue at the frame corners, clear of the falling fruit. */
#board::after {
  content: "";
  position: absolute;
  inset: -1px;
  background:
    linear-gradient(var(--ink), var(--ink)) left top / 14px 1px,
    linear-gradient(var(--ink), var(--ink)) left top / 1px 7px,
    linear-gradient(var(--ink), var(--ink)) right top / 14px 1px,
    linear-gradient(var(--ink), var(--ink)) right top / 1px 7px;
  background-repeat: no-repeat;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease-out;
}
#board.pressed::after { opacity: .75; transition-duration: 0s; }
#board:focus-visible { outline: 2px solid var(--bright); outline-offset: 3px; }
#status[data-warning="true"] { color: var(--accent); }

.forecast {
  /* Part of the board's aiming surface: drag and release below the fruit. */
  --hud-gap: clamp(.375rem, 2cqi, .75rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-columns: auto;
  grid-auto-flow: column;
  align-items: center;
  gap: var(--hud-gap);
  height: var(--hud-height);
  padding-top: var(--rim);
  border-top: 1px solid var(--line);
}
.metric {
  min-width: 0;
  display: grid;
  justify-items: start;
  align-content: end;
  gap: .3125rem;
}
.metric + .metric {
  min-width: 3rem;
  padding-left: var(--hud-gap);
  border-left: 1px solid var(--line);
}
.caption {
  color: var(--muted);
  font-size: .875rem;
  line-height: 1.1;
  white-space: nowrap;
}
.score-caption, .streak { display: flex; align-items: baseline; }
.score-caption { min-height: 1rem; gap: clamp(.375rem, 1.8cqi, .625rem); white-space: nowrap; }
#score {
  color: var(--bright);
  font-size: clamp(1.375rem, 4.5vw, 1.625rem);
  font-variant-numeric: tabular-nums;
  line-height: 1.625rem;
}
.streak { gap: .1875rem; color: var(--ink); white-space: nowrap; line-height: 1; }
#combo {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
#combo[data-strong="true"] { color: var(--bright); }
.combo-name { order: -1; color: var(--muted); font-size: .75rem; }
#combo[hidden] + .combo-name, [hidden] { display: none; }
#world, #next { image-rendering: pixelated; }
#next { display: block; }
#board[aria-disabled="true"] { cursor: default; }
#viewport {
  position: relative;
  aspect-ratio: var(--world-width) / var(--world-height);
  overflow: hidden;
  background: var(--bg);
}
#world { position: absolute; inset: 0; display: block; width: 100%; height: 100%; pointer-events: none; }
@media (max-height: 30rem) and (min-aspect-ratio: 6/5) {
  body { --gutter: .5rem; --rim: .25rem; --sidebar: 4.75rem; }
  main { width: min(100%, calc(var(--field-height) * var(--world-width) / var(--world-height) + var(--trim) + var(--sidebar) + .5rem)); }
  h1 { font-size: 1.5rem; }
  #playfield { display: grid; grid-template-columns: minmax(0, 1fr) var(--sidebar); gap: .5rem; }
  .forecast { height: auto; align-content: start; align-items: start; grid-auto-flow: row; grid-template-columns: 1fr; gap: .5rem; padding: 0; border: 0; }
  .metric + .metric { padding: .375rem 0 0; border: 0; border-top: 1px solid var(--line); align-self: stretch; }
  .combo-name { display: none; }
}
@container (max-width: 20rem) {
  .combo-name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #board::after { transition: none; }
}
