:root {
  color-scheme: dark;
  font: 400 16px/1.45 "Obcoro Display Pixel", monospace;
  --ink: #e0ebd4;
  --muted: #9dbca9;
  --rail: #417063;
  --brass: #e2c188;
  color: var(--ink);
  background: #081411;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  margin: 0;
  padding: max(16px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
main { width: min(100%, 32rem); min-width: 0; margin: auto; }
header, h1 { display: flex; align-items: center; }
header { justify-content: space-between; gap: 10px; }
h1 {
  gap: .33em;
  margin: 0;
  font-size: clamp(28px, 6vw, 36px);
  font-weight: 400;
  letter-spacing: .035em;
  line-height: 1.15;
}
.game-mark { width: .96em; height: 1.05em; image-rendering: pixelated; }
#level {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--rail);
  color: var(--ink);
  font-size: 14px;
}
#rules { margin: 8px 0 14px; color: var(--muted); font-size: 14px; text-wrap: balance; }

#board {
  position: relative;
  border: 1px solid var(--rail);
  border-radius: 8px;
  background: #153628;
  box-shadow: 0 5px 0 #07110e, 0 12px 24px #050d0945;
}
.board-head, .tray-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 5px;
  font-size: 14px;
}
.board-head {
  padding: 8px 14px;
  border-radius: 7px 7px 0 0;
  border-bottom: 1px solid var(--rail);
  background: #102a23;
}
.stat, .capacity { color: var(--muted); white-space: nowrap; }
.stat b, .capacity b {
  color: var(--ink);
  font-size: 18px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
#feedback, #status { color: var(--brass); text-align: center; overflow-wrap: anywhere; }
#status[data-warning] { color: #ffae86; }

#pile {
  position: relative;
  isolation: isolate;
  width: min(calc(100% - 16px), 26rem, max(17rem, calc(100dvh - 26.5rem)));
  aspect-ratio: 6 / 6.45;
  margin: 8px auto;
}
.tile, .tile-flight, #tray li {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
}
.tile {
  position: absolute;
  left: calc(var(--x) * 100% / 6);
  top: calc(var(--y) * 100% / 6);
  width: calc(100% / 6);
  height: calc(100% / 6);
  min-width: 44px;
  min-height: 44px;
  border-radius: 6px;
  appearance: none;
  background: transparent;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  cursor: pointer;
}
.tile-sprite {
  display: block;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.tile[aria-disabled="true"] { cursor: default; }
.tile:focus-visible { outline: 3px solid #e48d3c; outline-offset: -4px; }
@media (hover: hover) {
  .tile:not([aria-disabled="true"]):hover { outline: 1px solid var(--brass); outline-offset: -1px; }
}
.tile:not([aria-disabled="true"]):active .tile-sprite { transform: translateY(1px); }
.tile-flight { position: absolute; z-index: 5; pointer-events: none; }
.tile-flight[data-points]::after {
  content: attr(data-points);
  position: absolute;
  bottom: 100%;
  padding: 0 5px;
  background: #102a23;
  color: var(--brass);
  font-size: 16px;
}
@media (prefers-reduced-motion: no-preference) {
  .tile.is-revealed .tile-sprite { animation: uncover 150ms ease-out; }
}
@keyframes uncover { from { opacity: .6; } }

.tray-area {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--rail);
  border-radius: 0 0 7px 7px;
  background: #102a23;
}
.tray-head, #tray { width: min(100%, 21rem); margin-inline: auto; }
#tray {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-block: 5px 0;
  padding: 0;
  list-style: none;
}
#tray li {
  height: clamp(46px, 7dvh, 58px);
  border: 1px solid #386555;
  border-radius: 5px;
  background: #0b211b;
  box-shadow: inset 0 2px 3px #061b16;
}
#board[data-warning] .capacity, #board[data-warning] #used { color: #ffae86; }
#board[data-warning] #tray li:last-child { border-color: #e1956e; }
footer { display: grid; gap: 6px; padding-top: 14px; text-align: center; }
footer .lb-tools { justify-content: center; }
footer small { color: var(--muted); font-size: 12px; }
