:root {
  --bg: #0d1020;
  --panel: #171b33;
  --edge: #2a3060;
  --text: #e8ecff;
  --muted: #9aa3c7;
  --blue: #4f8fd8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  /* Pan only: no pinch or double-tap page zoom (iOS ignores user-scalable=no). */
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas {
  display: block;
  touch-action: none;
}

/* Measures the safe-area insets for the renderer, which can't read env(). */
#safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  visibility: hidden;
  pointer-events: none;
}

/* One menu button in the top-right corner. */
#btn-menu {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}
#btn-menu:hover, #btn-menu:focus-visible { opacity: 1; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 18px 20px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
}
dialog::backdrop { background: rgba(5, 7, 16, 0.6); }

dialog h2 { margin: 0 0 12px; font-size: 20px; }

dialog label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  font-size: 14px;
  color: var(--muted);
}

dialog input, dialog select {
  width: 12em;
  max-width: 60%;
  padding: 5px 7px;
  border-radius: 6px;
  border: 1px solid var(--edge);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.row { margin: 12px 0; }
.row-name { font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.opts {
  display: flex;
  border: 1px solid var(--edge);
  border-radius: 9px;
  overflow: hidden;
  background: var(--bg);
}
dialog .opts label {
  flex: 1;
  display: block;
  margin: 0;
  position: relative;
  color: var(--text);
}
.opts label + label { border-left: 1px solid var(--edge); }
.opts label { cursor: pointer; }
.opts input {
  /* visually hidden but focusable; tapping the label selects it */
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.opts span {
  display: block;
  padding: 8px 4px;
  text-align: center;
  font-size: 14px;
  white-space: nowrap;
}
.opts input:checked + span { background: var(--blue); color: #fff; font-weight: 600; }
.opts input:focus-visible + span { outline: 2px solid #fff; outline-offset: -3px; }

.hint { font-size: 13px; color: var(--muted); line-height: 1.45; }
.hint a { color: var(--blue); }

menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  margin: 14px 0 0;
}
menu button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
menu button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }

/* start menu */
dialog.menu {
  width: min(320px, calc(100vw - 32px));
  text-align: center;
  padding: 28px 22px 24px;
}
dialog.menu h1 { margin: 0 0 18px; font-size: 30px; letter-spacing: 0.5px; }
.tagline { margin: -12px 0 22px; color: var(--muted); font-size: 14px; }
.pills { display: flex; flex-direction: column; gap: 10px; }
.pill {
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.pill.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.pill:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* how-to-play card */
ul.rules { padding-left: 18px; margin: 0 0 8px; font-size: 14px; line-height: 1.45; }
ul.rules li { margin: 8px 0; color: var(--muted); }
ul.rules b { color: var(--text); }
