:root {
  --bg: #05060d;
  --fg: #e6ecf7;
  --muted: #8b95ab;
  --accent: #6aa9ff;
  --good: #7dff9b;
  --panel: rgba(12, 16, 32, 0.82);
  --border: rgba(106, 169, 255, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}

[hidden] { display: none !important; }

#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 14px;
  color: var(--muted);
  pointer-events: none;
  flex-wrap: wrap;
}
#hud b { color: var(--fg); font-variant-numeric: tabular-nums; }
#hud-level { color: var(--accent); font-weight: 600; }
#hud-lives { letter-spacing: 2px; color: var(--fg); }
.hud-btn {
  margin-left: auto;
  pointer-events: auto;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(5, 6, 13, 0.35), rgba(5, 6, 13, 0.85));
  overflow-y: auto;
}
.overlay h1 {
  margin: 0 0 4px;
  font-size: clamp(32px, 7vw, 56px);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.overlay h2 { margin: 0 0 12px; font-size: 32px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  width: min(760px, 100%);
}
.levels button {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  text-align: left;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
  font: inherit;
}
.levels button:hover, .levels button:focus-visible {
  border-color: var(--accent);
  outline: none;
  transform: translateY(-1px);
}
.levels .num { color: var(--accent); font-weight: 700; font-size: 13px; }
.levels .name { display: block; font-size: 17px; font-weight: 600; margin: 4px 0; }
.levels .desc { display: block; color: var(--muted); font-size: 13px; }
.levels .best { display: block; color: var(--good); font-size: 12px; margin-top: 8px; }

.help { margin-top: 24px; color: var(--muted); font-size: 14px; line-height: 1.7; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--fg);
  font: 12px ui-monospace, monospace;
}

.actions { display: flex; gap: 12px; margin-top: 12px; }
.actions button {
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.actions button.primary { background: var(--accent); color: #05060d; border-color: var(--accent); font-weight: 600; }

/* Golden book */
.entry {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, 100%);
  margin: 4px 0 8px;
}
.entry .made-it { margin: 0; color: #ffd66b; font-weight: 600; }
.entry input, .entry textarea {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--fg);
  resize: none;
  -webkit-user-select: text;
  user-select: text;
}
.entry button {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #ffd66b;
  background: #ffd66b;
  color: #05060d;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.error { color: #ff7a8a; margin: 0; font-size: 14px; }
#entry-done { color: #ffd66b; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 12px; }
.tabs button {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: #05060d; background: #ffd66b; border-color: #ffd66b; }
.book-list { width: min(760px, 100%); max-height: 60vh; overflow: auto; background: var(--panel); border-radius: 10px; padding: 4px 8px; }
.book-list table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
.book-list th { color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.book-list td { padding: 8px; border-bottom: 1px solid rgba(106, 169, 255, 0.12); vertical-align: top; }
.book-list td:nth-child(1), .book-list td:nth-child(3) { font-variant-numeric: tabular-nums; white-space: nowrap; }
.book-list td:nth-child(4) { color: var(--muted); overflow-wrap: anywhere; }
.book-list td:nth-child(5) { color: var(--muted); white-space: nowrap; }
.book-list tr.mine td { color: #ffd66b; }
@media (max-width: 560px) {
  .book-list th:nth-child(5), .book-list td:nth-child(5) { display: none; }
}

/* On-screen controls, shown on touch devices. */
#touch { display: none; }
body.touch #touch.active {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
}
#touch .pad { display: flex; gap: 12px; pointer-events: auto; }
#touch button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: rgba(20, 28, 56, 0.55);
  color: var(--fg);
  font: 600 13px system-ui, sans-serif;
  touch-action: none;
}
#touch button[data-action="left"], #touch button[data-action="right"] { font-size: 30px; }
#touch button.pressed { background: rgba(106, 169, 255, 0.45); border-color: var(--accent); }
#touch button.fire { border-color: rgba(255, 92, 122, 0.6); }
#touch button.thrust { border-color: rgba(255, 138, 31, 0.6); }
