/*
 * Colours are the stock 16-colour EGA palette, as in the original game:
 *   blue #0000aa, cyan #00aaaa, light grey #aaaaaa, dark grey #555555,
 *   light blue #5555ff, light red #ff5555, black, white.
 *
 * Everything is sized in "DOS pixels": --u is the CSS size of one original
 * pixel.  game.js recomputes it (and --sx/--sy, the top-left of the playfield)
 * whenever the window changes, so the whole UI scales to any screen.
 */
:root { --u: 1.5px; --sx: 0px; --sy: 0px; --stw: 534; --sth: 324; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0000aa;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  font-family: "Courier New", Menlo, ui-monospace, monospace;
  font-weight: bold;
}

#board, #fx { position: fixed; left: 0; top: 0; }
#fx { pointer-events: none; }

/* title bar: light grey with a dark-grey lower edge, full window width */
#hdr {
  position: fixed; left: 0; top: 0; width: 100%; height: calc(var(--u) * 22);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 calc(var(--u) * 8); font-size: calc(var(--u) * 14);
  color: #000; background: #aaaaaa; pointer-events: none;
  border-top: calc(var(--u) * 1) solid #fff;
  border-bottom: calc(var(--u) * 2) solid #555555;
}
#hdr .title { letter-spacing: calc(var(--u) * 2); }

/* the playfield: the board (canvas) with one status row underneath it */
#stage {
  position: fixed;
  left: var(--sx); top: var(--sy);
  width: calc(var(--u) * var(--stw, 534)); height: calc(var(--u) * var(--sth, 324));
  pointer-events: none;
}
#stage > * { pointer-events: auto; }
/* the fireworks layer and title bar must never swallow taps meant for the board */
#stage > #fx, #stage > #hdr { pointer-events: none; }

/* bottom row:  Board N  |  Tiles Left: N  |  [Restart] [Undo] [Hint] */
#bar {
  position: absolute; left: 0; right: 0; top: calc(var(--u) * 294); height: calc(var(--u) * 24);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 calc(var(--u) * 4); font-size: calc(var(--u) * 15);
}
#boardno { justify-self: start; color: #5555ff; }
#tilesleft { justify-self: center; color: #aaaaaa; white-space: nowrap; pointer-events: none; }
#tl-count { color: #ff5555; }
#tilesleft.msg { color: #ffff55; }

/* buttons: cyan, black outline, dark-grey drop shadow */
#buttons { justify-self: end; display: flex; gap: calc(var(--u) * 6); }
#buttons button {
  width: calc(var(--u) * 44); height: calc(var(--u) * 24); margin: 0; padding: 0;
  font: inherit; font-size: calc(var(--u) * 13); color: #000; background: #00aaaa;
  border: calc(var(--u) * 2) solid #000; border-radius: 0; cursor: pointer;
  box-shadow: calc(var(--u) * 3) calc(var(--u) * 3) 0 #555555;
}
#buttons #btn-restart { width: calc(var(--u) * 60); }
#buttons button:active {
  box-shadow: none; transform: translate(calc(var(--u) * 2), calc(var(--u) * 2));
}
#buttons button:disabled { color: #006666; cursor: default; }

#overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 60, 0.55);
  display: flex; align-items: center; justify-content: center;
}
#overlay[hidden] { display: none; }
#dialog {
  min-width: calc(var(--u) * 300); max-width: 90vw; padding: calc(var(--u) * 16) calc(var(--u) * 20) calc(var(--u) * 20);
  text-align: center; background: #00aaaa; color: #000;
  border: calc(var(--u) * 2) solid #000;
  box-shadow: calc(var(--u) * 5) calc(var(--u) * 5) 0 #555555;
}
#dlg-title { font-size: calc(var(--u) * 20); margin-bottom: calc(var(--u) * 8); color: #fff; }
#dlg-text { white-space: pre-line; font-size: calc(var(--u) * 15); margin-bottom: calc(var(--u) * 16); line-height: 1.35; }
#dlg-buttons { display: flex; gap: calc(var(--u) * 14); justify-content: center; flex-wrap: wrap; }
#dlg-buttons button {
  font: inherit; font-size: calc(var(--u) * 16); min-width: calc(var(--u) * 84); height: calc(var(--u) * 38);
  padding: 0 calc(var(--u) * 12); color: #000; background: #aaaaaa; cursor: pointer; border-radius: 0;
  border: calc(var(--u) * 2) solid #000;
  box-shadow: calc(var(--u) * 3) calc(var(--u) * 3) 0 #555555;
}
#dlg-buttons button:active {
  box-shadow: none; transform: translate(calc(var(--u) * 3), calc(var(--u) * 3));
}

/* win screen: fireworks stay visible, the dialog moves to the bottom */
#overlay.win, #overlay.end { background: transparent; align-items: flex-end; padding-bottom: calc(var(--u) * 44); }
#overlay.win #dialog, #overlay.end #dialog { min-width: calc(var(--u) * 260); }
#overlay.end #dlg-title { color: #ff5555; }
#overlay.win #dlg-title { animation: winblink 0.6s steps(1) infinite; }
@keyframes winblink {
  0% { color: #ffff55; } 34% { color: #ff5555; } 67% { color: #ffffff; }
}
