@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.4 "Obcoro Pixel", monospace;
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  --gutter: 8px;
  --top: max(var(--gutter), env(safe-area-inset-top));
  --bottom: max(var(--gutter), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--top) max(var(--gutter), env(safe-area-inset-right))
           var(--bottom) max(var(--gutter), env(safe-area-inset-left));
  color: var(--ink);
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Give the thumb more of the lower screen; the spacers collapse on short phones. */
body::before, body::after { content: ""; flex: 1 0 0; }
body::before { flex-grow: 3; }

main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(100%, 31rem);
  max-height: 100%;
  min-width: 0;
  min-height: 0;
}

header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

h1 {
  flex: none;
  margin: 0;
  color: var(--bright);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.125;
}

#level {
  flex: none;
  max-width: 35%;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 1px 6px;
  border: 1px solid var(--line);
  background: #0b1911;
  color: var(--ink);
  font-size: .875rem;
  line-height: 1.4;
  white-space: nowrap;
}
#hint {
  display: grid;
  align-content: center;
  min-height: 2.8em;
  min-width: 0;
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: .75rem;
  text-align: right;
  overflow-wrap: anywhere;
}
#hint[data-warning] { color: var(--accent); }

.board {
  position: relative;
  width: 100%;
  min-height: 0;
  aspect-ratio: 344 / 496;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  touch-action: none;
}
canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}
footer {
  flex: none;
  min-height: 44px;
  align-content: center;
  color: var(--muted);
  text-align: center;
  font-size: .875rem;
  line-height: 1.5;
  letter-spacing: .06em;
}

@media (min-width: 42rem) {
  body { --gutter: 16px; }
  body::before { flex-grow: 1; }
  main {
    gap: 12px;
    width: min(100%, 31rem, calc((100dvh - var(--top) - var(--bottom) - 7.5rem) * 344 / 496));
  }
  h1 { font-size: 2rem; }
  #hint { font-size: .875rem; }
}

/* Use the full height for the machine when a phone turns sideways. */
@media (orientation: landscape) and (min-width: 32rem) and (max-height: 30rem) {
  body {
    --top: max(4px, env(safe-area-inset-top));
    --bottom: max(4px, env(safe-area-inset-bottom));
  }
  main {
    display: grid;
    width: min(100%, 39rem);
    height: 100%;
    /* Six 44px handle columns plus the two frame edges. */
    grid-template-columns: minmax(266px, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    column-gap: 16px;
  }
  .board {
    grid-area: 1 / 1 / 3 / 2;
    width: 100%;
    height: 100%;
  }
  header { align-self: end; flex-wrap: wrap; }
  footer { grid-column: 2; }
}

