:root {
  --bg: #16181d;
  --panel: #1e2128;
  --text: #d6d8de;
  --muted: #8a8f9b;
  --accent: #55ffff;
  --key: #2a2e37;
  --line: #262a32;
  --link: #86d6dc;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  /* The visible height (100% where dvh is unknown), not 100vh: on tablets and phones 100vh is the
     height with the address bar hidden, so the page was taller than the screen and scrolled the
     header away as soon as the game screen took the focus. */
  height: 100dvh;
}
header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 16px;
  flex-wrap: wrap;
}
header h1 { margin: 0; font-size: 20px; letter-spacing: 0.04em; }
header h1 small { color: var(--muted); font-weight: normal; font-size: 13px; margin-left: 8px; }
nav { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
button {
  background: var(--key);
  color: var(--text);
  border: 1px solid #3a3f4a;
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  min-height: 0;
  container-type: size;   /* the stage is sized from the space actually left between header and footer */
}
/* Fallback first (viewport minus a typical header + footer), then the exact container height. */
#stage { position: relative; width: min(100%, calc((100vh - 170px) * 4 / 3)); width: min(100%, calc(100cqh * 4 / 3)); }
#stage.square { width: min(100%, calc((100vh - 170px) * 720 / 400)); width: min(100%, calc(100cqh * 720 / 400)); }
#screen {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  outline: none;
  cursor: none;
}
#stage.square #screen { aspect-ratio: 720 / 400; }
#screen:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  text-align: center;
  padding: 24px;
}
#overlay[hidden] { display: none; }
#overlay .card {
  background: var(--panel);
  border: 1px solid #3a3f4a;
  border-radius: 10px;
  padding: 20px 28px;
  max-width: 420px;
}
#overlay .card p { margin: 0 0 12px; }
#overlay .card p.tip { margin: 16px 0 0; }
/* The coffee link: a quiet amber pill with its own cup and smile, the same in the footer and on the exit card. */
.coffee {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 10px;
  border: 1px solid rgba(255, 201, 107, 0.38);
  border-radius: 999px;
  background: rgba(255, 201, 107, 0.07);
  color: #eec684;
  font-size: 13px;
  line-height: 18px;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.coffee:hover, .coffee:focus-visible { background: rgba(255, 201, 107, 0.16); border-color: #ffc96b; color: #ffdb9c; outline: none; }
.coffee svg { width: 17px; height: 17px; flex: none; }
.coffee b { font-weight: 600; }
#overlay .coffee { white-space: normal; border-radius: 16px; text-align: left; }
footer {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  justify-content: center;
  align-items: center;
}
/* The keys: a group per player and one for the game, each key cap with its word underneath. */
footer .keys { flex: 1 0 100%; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 40px; }
.keygroup h2 {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: #a4a9b5;
}
.keygroup ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 10px; justify-content: center; }
.keygroup li { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; line-height: 13px; }
.keygroup .caps { display: inline-flex; align-items: center; gap: 3px; }
.keygroup .caps i { width: 7px; height: 1px; background: currentColor; opacity: 0.7; }   /* the dash of A to Z */
kbd {
  display: inline-block;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  text-align: center;
  background: linear-gradient(#343945, #272b34);
  border: 1px solid #4b515e;
  border-bottom-width: 3px;
  border-radius: 5px;
  font: 600 11.5px/20px ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text);
}
footer .credits { text-align: center; line-height: 1.6; }
footer .sep { margin: 0 5px; opacity: 0.55; }
footer a:not(.coffee), .opts summary { color: var(--link); text-decoration: none; cursor: pointer; }
footer a:not(.coffee):hover, .opts summary:hover { color: var(--accent); text-decoration: underline; }
/* The URL options fold out over the footer instead of taking a line of it. */
.opts { display: inline-block; position: relative; }
.opts summary { list-style: none; display: inline-flex; align-items: center; gap: 5px; }
.opts summary::-webkit-details-marker { display: none; }
.opts summary::after { content: ""; border: 4px solid transparent; border-bottom-color: currentColor; margin-top: -4px; }
.opts[open] summary::after { border-bottom-color: transparent; border-top-color: currentColor; margin-top: 4px; }
.opts .pop {
  position: absolute;
  bottom: calc(100% + 10px);
  right: -12px;
  z-index: 20;
  width: max-content;
  max-width: min(400px, calc(100vw - 32px));
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid #3a3f4a;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  color: var(--text);
  text-align: left;
  line-height: 1.45;
}
.opts .pop p { margin: 0 0 8px; color: var(--muted); }
.opts .pop dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; align-items: baseline; }
.opts .pop dt, .opts .pop dd { margin: 0; }
.opts code { font: 11.5px/16px ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--key); border-radius: 4px; padding: 1px 5px; color: var(--text); }
/* touch controls (phones, tablets, or the Pad button) */
body { touch-action: manipulation; }
.touchpads { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.touchpads[hidden] { display: none; }
.tpad {
  position: absolute;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 6px;
  pointer-events: auto;
}
.tpad.left { left: max(10px, env(safe-area-inset-left)); }
.tpad.right { right: max(10px, env(safe-area-inset-right)); }
.tlabel { grid-column: 1 / -1; text-align: center; font-size: 10px; letter-spacing: 0.08em; color: var(--muted); }
.tbtn {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 12px;
  background: rgba(30, 33, 40, 0.72);
  border: 1px solid rgba(85, 255, 255, 0.45);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.tbtn.wide { grid-column: 1 / -1; width: auto; height: 44px; font-size: 15px; }
.tbtn.wide2 { grid-column: 1 / 3; width: auto; }
.tbtn.top { height: 38px; font-size: 13px; }
.tbtn.down, .tbtn:active { background: rgba(85, 255, 255, 0.35); border-color: var(--accent); }
.tkbd { position: fixed; bottom: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; pointer-events: none; }
/* Touch mode: the keys of the two players and the URL options make way (the pads carry the key
   names), the game keys shrink to one line. The footer stays wherever there is room for it:
   between the two pads on a tablet, above them on a narrow upright one. A phone has no room,
   there it is hidden. */
body.touch footer { display: none; }
body.touch footer .keygroup:not(.game), body.touch footer .keygroup h2, body.touch footer .opts, body.touch footer .opts-sep { display: none; }
body.touch footer .keys { flex: 0 1 auto; }
body.touch footer .keygroup li { flex-direction: row; gap: 5px; }
body.touch footer .credits { flex: 1 0 100%; order: 3; }
@media (min-width: 760px) and (min-height: 480px) {
  body.touch footer { display: flex; padding-left: 196px; padding-right: 196px; }
}
@media (min-width: 560px) and (max-width: 759.98px) and (min-height: 700px) {
  body.touch footer { display: flex; padding-bottom: 196px; }
}
body.touch main { align-items: flex-start; }
body.touch #stage { width: min(100%, calc((100vh - 60px) * 4 / 3)); width: min(100%, calc(100cqh * 4 / 3)); }
body.touch #stage.square { width: min(100%, calc((100vh - 60px) * 720 / 400)); width: min(100%, calc(100cqh * 720 / 400)); }
:fullscreen #stage, :fullscreen #stage.square { width: min(100vw, calc(100vh * 4 / 3)); }
:fullscreen header, :fullscreen footer { display: none; }
:fullscreen main { padding: 0; }
/* A low window keeps its lines for the game: the key legend goes (the Help of the game lists the keys too). */
@media (max-height: 599.98px) {
  footer .keys { display: none; }
}
/* The exit card on a phone: less padding, so that the coffee link stays on one line where it can. */
@media (max-width: 480px) {
  #overlay { padding: 12px; }
  #overlay .card { padding: 18px 16px; }
}
/* On a narrow window the options box is centred over the credits instead of hanging from its link. */
@media (max-width: 600px) {
  footer .credits { position: relative; }
  .opts { position: static; }
  .opts .pop { right: auto; left: 50%; transform: translateX(-50%); }
}
