@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;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 "Obcoro Pixel", monospace;
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
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: max(10px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button {
  appearance: none;
  font: inherit;
  color: inherit;
  border-radius: 0;
  cursor: pointer;
}
button:focus-visible {
  outline: 2px solid var(--bright);
  outline-offset: 3px;
}

main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  width: min(100%, 49rem);
  height: 100%;
  min-width: 0;
  min-height: 0;
}
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
h1 {
  margin: 0;
  color: var(--bright);
  font-size: 2.25rem;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: .08em;
  white-space: nowrap;
}
.readout {
  display: grid;
  justify-items: end;
  min-width: 0;
}
#level {
  display: inline-block;
  color: var(--muted);
  font-size: .875rem;
  white-space: nowrap;
}
#status { min-height: 1.4em; margin: 0; font-size: .875rem; line-height: 1.4; text-align: right; }
#status[data-warning="true"] { color: var(--accent); }
footer {
  color: var(--muted);
  font-size: .75rem;
  letter-spacing: .08em;
  text-align: center;
}

#board {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  touch-action: none;
}
#board::after {
  content: "";
  position: absolute;
  z-index: 7;
  inset: auto 0 0;
  height: 5px;
  border-inline: 1px solid var(--ink);
  pointer-events: none;
}
#playfield {
  position: relative;
  min-width: 0;
  min-height: 0;
  isolation: isolate;
  overflow: hidden;
}
.instrument {
  position: relative;
  z-index: 6;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-top: 1px solid var(--line);
  background: #09130e;
}
.meter { display: inline-flex; align-items: baseline; gap: 10px; color: var(--muted); font-size: .875rem; }
#progress { color: var(--bright); font-size: 1rem; white-space: nowrap; }
#combo {
  display: flex;
  align-items: baseline;
  gap: 5px;
  justify-self: end;
  min-width: 0;
  color: var(--ink);
  font-size: .875rem;
  line-height: 1.25;
  white-space: nowrap;
}
#combo[data-tier="2"], #combo[data-tier="3"] { color: var(--bright); }
#combo:not(:empty)::before {
  content: "";
  width: 10px;
  height: 10px;
  background: linear-gradient(currentColor, currentColor) left bottom / 2px 4px no-repeat;
}
#combo[data-tier="2"]::before {
  background: linear-gradient(currentColor, currentColor) 4px bottom / 2px 7px no-repeat,
              linear-gradient(currentColor, currentColor) left bottom / 2px 4px no-repeat;
}
#combo[data-tier="3"]::before {
  background: linear-gradient(currentColor, currentColor) 8px bottom / 2px 10px no-repeat,
              linear-gradient(currentColor, currentColor) 4px bottom / 2px 7px no-repeat,
              linear-gradient(currentColor, currentColor) left bottom / 2px 4px no-repeat;
}
#undo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 64px;
  min-height: 48px;
  padding: 3px 10px;
  border: 1px solid #55b875;
  background: #07100c;
  font-size: .875rem;
  touch-action: manipulation;
}
.undo-arrow {
  position: relative;
  width: 10px;
  height: 6px;
  border: solid currentColor;
  border-width: 1px 1px 0 0;
}
.undo-arrow::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 0;
  width: 5px;
  height: 5px;
  border: solid currentColor;
  border-width: 0 0 1px 1px;
  transform: rotate(45deg);
}
#undo:not(:disabled):active { transform: scale(.94); background: #183523; }
#undo:disabled { color: var(--muted); border-color: var(--line); opacity: .58; cursor: default; }

/* The playfield receives the space left by the header, controls and footer.
   Its rack reserves room above the top shelf for a tilted pouring glass. */
#rack {
  --n: var(--mobile-cols);
  --r: var(--mobile-rows);
  --art-pixel: 1.38px;
  --glass-width: calc(32 * var(--art-pixel));
  --glass-limit: calc((16 + 17 * var(--layers)) * var(--art-pixel));
  --label-space: 24px;
  --gutter: clamp(8px, 2vw, 12px);
  --gap-x: clamp(6px, 2vw, 12px);
  --gap-y: clamp(10px, 1.4dvh, 14px);
  --headroom: clamp(28px, 4dvh, 38px);
  --footroom: clamp(6px, 1dvh, 12px);
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: var(--gap-y) var(--gap-x);
  width: calc(100% - 2 * var(--gutter));
  height: 100%;
  margin-inline: auto;
  padding-block: var(--headroom) var(--footroom);
}
.bottle {
  position: relative;
  display: block;
  flex: 0 0 calc((100% + var(--gap-x)) / var(--n) - var(--gap-x) - .03px);
  min-width: 44px;
  height: clamp(44px, calc((100% + var(--gap-y)) / var(--r) - var(--gap-y)),
    calc(var(--glass-limit) + var(--label-space)));
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: none;
}
.rest {
  position: absolute;
  inset: auto 0 16px;
  width: min(84%, calc(var(--glass-width) + 16px));
  height: 7px;
  margin-inline: auto;
  image-rendering: pixelated;
  pointer-events: none;
}
.bottle::after {
  content: attr(data-slot);
  position: absolute;
  inset: auto 0 0;
  color: var(--muted);
  font-size: .75rem;
  line-height: 1;
  letter-spacing: .1em;
}
.amount {
  position: absolute;
  inset: auto 0 0;
  height: 1em;
  visibility: hidden;
  color: var(--bright);
  font-size: 1rem;
  line-height: 1;
  pointer-events: none;
}
.bottle.credit .amount { visibility: visible; }
.bottle.credit::after { opacity: 0; }
.bottle.credit .rest { opacity: .4; }
.vial {
  position: absolute;
  inset: 0 0 auto;
  width: auto;
  max-width: calc(100% - 8px);
  height: calc(100% - var(--label-space));
  margin: auto;
  image-rendering: pixelated;
  transform-origin: 50% 0;
  pointer-events: none;
}
.bottle[aria-pressed="true"] { z-index: 2; }
.bottle[aria-pressed="true"]::after { color: var(--accent); }
#effects {
  position: absolute;
  z-index: 5;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

@media (hover: hover) {
  .bottle:not([aria-pressed="true"]):hover::after { color: var(--bright); }
  #undo:not(:disabled):hover { border-color: var(--ink); background: #11271b; }
}
@media (min-width: 601px) {
  body {
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }
  main { height: min(100%, 46rem); gap: 12px; }
  .readout { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: baseline; gap: 2px 16px; }
  #level { font-size: 1rem; }
  .instrument { gap: 12px; padding: 6px 20px; }
  #rack {
    --n: var(--cols);
    --r: var(--rows);
    --art-pixel: 1.625px;
    --label-space: 28px;
    --gutter: clamp(16px, 3vw, 32px);
    --gap-x: clamp(10px, 2vw, 26px);
    --gap-y: clamp(16px, 3dvh, 30px);
    max-width: calc(var(--n) * 96px + (var(--n) - 1) * var(--gap-x));
  }
}
@media (max-height: 520px) {
  body {
    padding-block: max(5px, env(safe-area-inset-top)) max(5px, env(safe-area-inset-bottom));
  }
  main { gap: 5px; }
  h1 { font-size: 1.75rem; }
  .instrument { padding-block: 2px; }
  #rack {
    --headroom: clamp(22px, 9dvh, 42px);
    --footroom: 6px;
    --label-space: 19px;
    --gap-y: 10px;
  }
  .rest { bottom: 12px; height: 5px; }
  .bottle::after { font-size: 10px; }
  .amount { font-size: 12px; }
}
@media (orientation: landscape) and (max-height: 520px) and (min-width: 460px) and (max-width: 600px) {
  #rack {
    --n: var(--cols);
    --r: var(--rows);
    --gutter: 10px;
    --gap-x: clamp(4px, 1.5vw, 9px);
  }
}
@media (prefers-reduced-motion: reduce) {
  #undo:not(:disabled):active { transform: none; }
}
