@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: 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;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 8px)
           calc(env(safe-area-inset-bottom) + 8px) calc(env(safe-area-inset-left) + 8px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

main {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  width: min(100%, 48rem);
  min-width: 0;
  height: 100%;
  max-height: 100%;
}
header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 3rem;
  margin-top: auto;
}
h1 {
  margin: 0;
  color: var(--bright);
  font-size: 1.875rem;
  font-weight: 400;
  letter-spacing: .075em;
  line-height: 1.2;
  white-space: nowrap;
}
.readout { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; min-width: 0; }
#level {
  padding: .125rem .5rem;
  border: 1px solid var(--line);
  color: var(--bright);
  font-size: .875rem;
  line-height: 1.25;
  white-space: nowrap;
}
#status { margin: 0; min-height: 1.35em; color: var(--ink); font-size: .875rem; text-align: right; line-height: 1.35; }
#resume-round {
  min-width: 44px;
  min-height: 44px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--bright);
  font: inherit;
  cursor: pointer;
}

footer {
  display: grid;
  flex: none;
  gap: 4px;
  margin-top: auto;
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}

#board {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  touch-action: none;
}
.instruments {
  display: grid;
  flex: none;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: .5rem;
  min-height: 2.875rem;
  padding: .5rem clamp(.75rem, 2.5vw, 1.25rem);
  border-bottom: 1px solid var(--line);
  background: #080f0d;
  color: var(--ink);
  font-size: .875rem;
  line-height: 1.2;
}
.ink-gauge, .clock { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
#ink-label, .clock-unit { color: var(--muted); }
#ink-meter {
  position: relative;
  width: clamp(2.625rem, 14vw, 6.75rem);
  height: .75rem;
  padding: 2px;
  border: 1px solid var(--line);
  background: var(--bg);
}
#ink-meter::after {
  content: "";
  position: absolute;
  inset: 2px;
  background: repeating-linear-gradient(90deg, transparent 0 7px, var(--bg) 7px 8px);
  pointer-events: none;
}
#ink-fill { height: 100%; background: var(--ink); transform-origin: left; }
#ink-value, .clock-value { font-variant-numeric: tabular-nums; }
#ink-value, #time { display: inline-block; width: 4ch; text-align: right; }
#ink-value { color: var(--bright); }
.clock { justify-self: end; color: var(--muted); }
body[data-phase="drawing"] #ink-meter { border-color: var(--muted); }
body[data-phase="flying"] #ink-fill { background: var(--muted); }
body[data-phase="flying"] #ink-value { color: var(--muted); }
body[data-phase="flying"] .clock { color: var(--bright); }
#time-ring {
  --sweep: 360deg;
  position: relative;
  display: inline-block;
  width: 1.375rem;
  height: 1.375rem;
}
#time-ring::before, .half, .half::before { position: absolute; inset: 0; }
#time-ring::before, .half::before { content: ""; border: 2px solid var(--line); border-radius: 50%; }
.half { clip-path: var(--clip); }
.half::before { border-color: currentColor; clip-path: var(--clip); }
.half.right { --clip: inset(0 0 0 50%); }
.half.left { --clip: inset(0 50% 0 0); }
.half.right::before { transform: rotate(clamp(-180deg, calc(var(--sweep) - 180deg), 0deg)); }
.half.left::before { transform: rotate(clamp(-180deg, calc(var(--sweep) - 360deg), 0deg)); }
#time-ring::after {
  content: "";
  position: absolute;
  left: calc(50% - .5px);
  bottom: calc(50% - .5px);
  width: 4px;
  height: 5px;
  border: solid var(--muted);
  border-width: 0 0 1px 1px;
}
#combo {
  --beat-scale: 1.07;
  --marks: 4px;
  position: relative;
  justify-self: center;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 100ms ease-out;
}
#combo:not([data-tier="0"]) { opacity: 1; }
#combo[data-tier="2"] { --beat-scale: 1.11; --marks: 10px; color: var(--bright); }
#combo[data-tier="3"] { --beat-scale: 1.15; --marks: 16px; color: var(--bright); }
body[data-phase="flying"] #combo:not([data-tier="0"])::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: var(--marks);
  height: 2px;
  transform: translateX(-50%);
  background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 6px);
}
/* Alternate names to restart the impact without a synchronous layout read. */
body[data-phase="flying"] #combo:not([data-tier="0"])[data-beat="0"] { animation: combo-beat-even 160ms ease-out; }
body[data-phase="flying"] #combo:not([data-tier="0"])[data-beat="1"] { animation: combo-beat-odd 160ms ease-out; }
@keyframes combo-beat-even { from { transform: scale(var(--beat-scale)); } to { transform: none; } }
@keyframes combo-beat-odd { from { transform: scale(var(--beat-scale)); } to { transform: none; } }
.playfield {
  position: relative;
  /* Match the portrait world without introducing side gutters on a tall phone. */
  aspect-ratio: 7 / 10;
  max-height: 34rem;
  min-height: 44px;
  overflow: hidden;
  background: var(--bg);
}
#arena {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
body[data-phase="flying"] #arena { cursor: default; }
#board[aria-disabled="true"] #arena { pointer-events: none; cursor: default; }
body[data-phase="won"] #arena, body[data-phase="lost"] #arena { cursor: default; }
body[data-phase="lost"] #status, #status[data-alert="true"] { color: var(--accent); }
body[data-phase="won"] #status { color: var(--bright); }

@media (min-width: 36rem) {
  main { height: auto; gap: .875rem; }
  header, footer { margin-top: 0; }
  h1 { font-size: 2.25rem; }
  .readout { flex-direction: row; align-items: center; gap: .875rem; }
  .playfield { aspect-ratio: 8 / 5; max-height: 30rem; }
}
@media (max-width: 22rem) {
  .instruments { gap: .25rem; padding-inline: .5rem; }
  .ink-gauge, .clock { gap: .375rem; }
}
@media (max-width: 19.5rem) {
  .instruments { padding-inline: .375rem; }
  .ink-gauge { gap: .25rem; }
  #time-ring { display: none; }
  #combo { font-size: .875rem; }
}
@media (max-height: 28rem) {
  main { width: min(100%, 48rem, max(18rem, calc(178dvh - 15rem))); gap: .25rem; }
  header { min-height: 2rem; }
  h1 { font-size: 1.5rem; }
  .instruments { min-height: 2rem; padding-block: .25rem; }
}
@media (prefers-reduced-motion: reduce) {
  #combo { transition: none; }
  body[data-phase="flying"] #combo:not([data-tier="0"])[data-beat] { animation: none; }
}
