:root {
  --bg: #16181d;
  --panel: #1e2128;
  --text: #d6d8de;
  --muted: #8a8f9b;
  --accent: #55ffff;
  --key: #2a2e37;
  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;
  min-height: 100vh;
}
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.coffee { margin: 16px 0 0; font-size: 13px; }
.coffee a { color: var(--muted); text-decoration: none; }
.coffee a:hover { color: var(--accent); text-decoration: underline; }
footer {
  padding: 10px 16px 14px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  justify-content: center;
  align-items: center;
}
footer table { border-collapse: collapse; }
footer td, footer th { padding: 1px 10px; text-align: left; font-weight: normal; }
footer th { color: var(--text); }
kbd {
  display: inline-block;
  min-width: 22px;
  text-align: center;
  background: var(--key);
  border: 1px solid #454a56;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font: 12px/18px ui-monospace, Consolas, monospace;
  color: var(--text);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
/* 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; }
body.touch footer { display: none; }
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; }
@media (max-width: 720px) {
  #stage { width: 100%; }
  footer table { font-size: 12px; }
}
