:root {
  --bg: #000000;
  --panel: #0b0b0b;
  --text: #ffffff;
  --muted: #959595;
  --yellow: #edf171;
  --red: #9a6759;
  --cyan: #75cec8;
  --btn: #1c1c1c;
  --btn-border: #444444;
  --btn-active: #2e2c9b;
  --ok: #3f7d38;
  --back: #433900;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
#app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  max-width: 960px; margin: 0 auto;
}
#top { display: flex; justify-content: flex-end; padding: 2px 8px; flex: 0 0 auto; }
#mute {
  background: transparent; color: var(--muted); border: 1px solid #333; border-radius: 6px;
  font: inherit; font-size: 12px; padding: 4px 10px; min-height: 30px;
}
#stage { flex: 0 0 auto; display: flex; justify-content: center; }
#screen {
  width: 100%;
  image-rendering: pixelated; image-rendering: crisp-edges;
  background: #000; display: block;
}
#panel {
  flex: 1 1 auto; overflow: hidden;
  padding: 8px; background: var(--panel);
  border-top: 2px solid #813338;
}
.grid { display: grid; gap: 6px; }
.grid.g2 { grid-template-columns: 1fr 1fr; }
.grid.g3 { grid-template-columns: 1fr 1fr 1fr; }
.grid.small { grid-template-columns: 1fr 1fr; margin-top: 6px; }
.b {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: 16px; font-weight: 600; letter-spacing: 0.01em; line-height: 1.15;
  color: var(--text); background: var(--btn);
  border: 2px solid var(--btn-border); border-radius: 10px;
  min-height: 46px; padding: 4px 6px; text-align: center;
  touch-action: manipulation; cursor: pointer;
}
.b:active { background: var(--btn-active); border-color: var(--cyan); }
.b:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.b.back { background: var(--back); border-color: #8e5029; }
.b.ok { background: var(--ok); border-color: #a9ff9f; }
.b.dim { color: var(--muted); }
.b.util { font-size: 13px; min-height: 44px; color: var(--muted); font-weight: 400; }
.grid.g2 .b:only-child, .grid.g2 .b:last-child:nth-child(odd) { grid-column: 1 / -1; }
.grid.g3 .b:last-child:nth-child(3n+1) { grid-column: 1 / -1; }
.readout { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 4px; height: 30px; }
.readout .typed { font-size: 24px; color: var(--yellow); min-width: 4ch; }
.readout .max { color: var(--muted); font-size: 14px; }
.pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pad .b { min-height: 46px; font-size: 21px; }
.pad .b.max { color: var(--yellow); font-size: 16px; }
.pad .b.wide { grid-column: span 2; font-size: 17px; }
dialog {
  background: #111; color: var(--text); border: 2px solid #68372b; border-radius: 12px;
  width: min(92vw, 520px); padding: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog h2 { margin: 0 0 8px; font-size: 18px; color: var(--yellow); }
dialog p { color: #ccc; font-size: 14px; }
dialog textarea {
  width: 100%; font: 13px/1.3 ui-monospace, Menlo, Consolas, monospace; color: var(--text);
  background: #000; border: 1px solid #444; border-radius: 6px; padding: 8px;
  -webkit-user-select: text; user-select: text; word-break: break-all;
}
.mrow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
@media (min-width: 700px) and (min-height: 700px) {
  #panel { border-radius: 0 0 10px 10px; }
  .grid.g2, .grid.g3 { grid-template-columns: repeat(4, 1fr); }
  .grid.g2 .b:last-child:nth-child(odd), .grid.g3 .b:last-child:nth-child(3n+1) { grid-column: auto; }
  .pad, .readout { max-width: 460px; width: 100%; margin-left: auto; margin-right: auto; }
}
