@font-face {
  font-family: "Obcoro Pixel";
  src: url("../../assets/fusion-pixel-12px-monospaced-zh_tw.ttf.woff2") format("woff2");
  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: none;
  overscroll-behavior: none;
}
body {
  height: 100dvh;
  display: grid;
  place-items: center;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  padding: max(.5rem, env(safe-area-inset-top)) max(.375rem, env(safe-area-inset-right))
           max(.5rem, env(safe-area-inset-bottom)) max(.375rem, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

main {
  width: min(100%, 32rem);
  height: min(100%, 42rem);
  display: grid;
  grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr);
  gap: clamp(.25rem, 1.2dvh, .75rem);
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
h1 {
  margin: 0;
  color: var(--bright);
  font-size: clamp(1.5rem, 8vw, 2.25rem);
  font-weight: 400;
  letter-spacing: .05em;
  line-height: 1.2;
  white-space: nowrap;
}
.readout { display: flex; min-width: 0; flex-direction: column; align-items: flex-end; }
#level {
  display: inline-block;
  color: var(--bright);
  font-size: .875rem;
  white-space: nowrap;
}
#status { margin: 0; min-height: 1.5em; text-align: right; color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
#status.error { color: var(--accent); }
#resume {
  min-width: 44px;
  min-height: 44px;
  padding: .25rem .625rem;
  border: 1px solid var(--line);
  color: var(--bright);
  cursor: pointer;
}
footer { display: grid; align-items: center; color: var(--muted); font-size: .75rem; }

#board {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  padding: clamp(.5rem, 2dvh, 1rem) clamp(.3125rem, 1.2vw, 1rem);
  border: 1px solid var(--line);
  background: var(--panel);
  touch-action: none;
}
.play-area {
  position: relative;
  isolation: isolate;
  container-type: size;
  display: grid;
  grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr);
  gap: clamp(.25rem, 1.6dvh, .875rem);
  min-width: 0;
  min-height: 0;
}
#effects {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.score {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  align-content: space-between;
  gap: .25rem .5rem;
  min-height: 2.25rem;
  color: var(--muted);
  font-size: .875rem;
}
#score-label, .counter { white-space: pre; }
.counter { grid-column: 3; text-align: right; }
.counter strong {
  display: inline-block;
  color: var(--bright);
  font-size: 1.125rem;
  font-weight: 400;
  line-height: 1;
  transform-origin: center bottom;
}
#combo {
  grid-column: 2;
  justify-self: center;
  white-space: nowrap;
  color: var(--ink);
  font-size: .875rem;
  line-height: 1;
}
#combo:empty { visibility: hidden; }
#combo[data-tier="2"] { color: var(--bright); }
#combo[data-tier="3"] { color: var(--bright); font-size: 1rem; }
progress {
  grid-column: 1 / -1;
  width: 100%;
  height: .375rem;
  display: block;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
progress::-webkit-progress-bar { background: var(--bg); }
progress::-webkit-progress-value { background: var(--ink); border-right: 1px solid var(--bright); }
progress::-moz-progress-bar { background: var(--ink); border-right: 1px solid var(--bright); }

#field {
  --field-aspect: calc(5 / 4.6188);
  position: relative;
  place-self: center;
  /* Fill the middle row up to the playable width, keeping hexes undistorted. */
  height: min(100%, calc(100cqw / var(--field-aspect)));
  aspect-ratio: var(--field-aspect);
}
button {
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  font: inherit;
  background: none;
  touch-action: none;
}
.cell {
  position: absolute;
  width: 20%;
  height: 25%;
  transform: translate(-50%, -50%);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.cell[tabindex="0"] { cursor: pointer; }
.cell:focus-visible { outline: none; }
@media (hover: hover) {
  .offer:hover { border-color: var(--muted); }
}
.offer { transition: transform 175ms cubic-bezier(.2,1.55,.43,1); }
.offer.pressed { transform: scale(.945); transition: none; }

#offers {
  display: grid;
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  gap: clamp(.5rem, 2.4vw, .875rem);
  border-top: 1px solid var(--line);
  padding-top: .75rem;
}
.offer {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 44px;
  height: clamp(3.5rem, 9.25dvh, 4.625rem);
  border: 1px solid var(--line);
  background: #07110d;
  cursor: pointer;
}
.offer[aria-pressed="true"] {
  border-color: var(--accent);
  background: #26130e;
}
.offer[aria-disabled="true"] { border-style: dashed; cursor: default; }
.offer.pressed { border-color: var(--ink); }
.offer[aria-pressed="true"].pressed { border-color: var(--accent); }
.offer:focus-visible { outline: 1px solid var(--bright); outline-offset: 2px; }
@media (min-width: 36rem) {
  .readout { flex-direction: row; align-items: baseline; justify-content: flex-end; flex-wrap: wrap; gap: .25rem .875rem; }
  footer { text-align: center; }
}
@media (orientation: landscape) and (max-height: 32rem) {
  main { width: min(100%, 46rem); }
  h1 { font-size: 1.5rem; }
  .play-area {
    grid-template: "field score" auto "field tray" minmax(0, 1fr) / minmax(0, 1fr) minmax(10rem, 36%);
    column-gap: 1rem;
  }
  #field { grid-area: field; width: min(100%, calc(100cqh * var(--field-aspect))); height: auto; }
  .score { grid-area: score; }
  #offers { grid-area: tray; align-self: center; gap: .375rem; }
}
@media (prefers-reduced-motion: reduce) {
  .offer { transition: none; }
  .offer.pressed { transform: none; }
}
