:root {
  --bg: #0b0b0d;
  --panel: #16161a;
  --line: #2a2a31;
  --text: #e8e6e3;
  --muted: #9a968f;
  --accent: #e0b23a;
  --accent-text: #1a1406;
  --danger: #d9534f;
  --key-bg: #222228;
  --gutter: 16px;
  --cover-glow: #241c0b;
  --header-h: 72px;
  --bar-h: 44px;
  color-scheme: dark;
}

/* Light theme follows the system setting (or data-theme="light" on <html>).
   The game area itself stays black. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f1ea;
    --panel: #ffffff;
    --line: #d6d0c4;
    --text: #1c1a17;
    --muted: #5f5a52;
    --accent: #9a6a00;
    --accent-text: #ffffff;
    --danger: #b3261e;
    --key-bg: #f0ece4;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --line: #d6d0c4;
  --text: #1c1a17;
  --muted: #5f5a52;
  --accent: #9a6a00;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --key-bg: #f0ece4;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { overflow-x: hidden; }

.top {
  min-height: var(--header-h);
  padding: 12px var(--gutter) 8px;
  text-align: center;
}
.top h1 {
  margin: 0;
  font-size: clamp(20px, 4vw, 30px);
  letter-spacing: 0.04em;
  color: var(--accent);
  text-transform: uppercase;
}
.top .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

main {
  padding: 0 var(--gutter) 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* The game area keeps 16:10 and fits both the width and the visible height. */
.stage, .bar {
  width: min(100%, calc((100vh - var(--header-h) - var(--bar-h) - 24px) * 16 / 10));
  width: min(100%, calc((100dvh - var(--header-h) - var(--bar-h) - 24px) * 16 / 10));
}
.stage {
  position: relative;
  min-width: 0;
  aspect-ratio: 16 / 10;
  background: #000;
  border: 1px solid var(--line);
  overflow: hidden;
}
.dos { position: absolute; inset: 0; }
.dos canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.cover {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: var(--gutter);
  text-align: center;
  background: radial-gradient(ellipse at center, var(--cover-glow) 0%, #000 70%);
  z-index: 10;
}
.cover[hidden] { display: none; }
.cover-note { margin: 0; color: #b8b2a7; font-size: 13px; max-width: 32em; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button:not(:disabled):hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.start {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 12px 28px;
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.bar {
  min-width: min(100%, 320px);
  min-height: var(--bar-h);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
}
.status { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.status.error { color: var(--danger); }
.actions { display: flex; gap: 8px; }

.hint {
  width: min(100%, 960px);
  margin: 0 0 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-left: 3px solid var(--accent);
  font-size: 14px;
}

.help { width: min(100%, 960px); }
.help h2 { font-size: 16px; margin: 16px 0 8px; color: var(--accent); }
.tables { display: flex; flex-wrap: wrap; gap: 16px; }
table {
  flex: 1 1 260px;
  min-width: 0;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
}
caption { text-align: left; font-weight: 600; padding: 0 0 4px; color: var(--text); }
th, td { padding: 6px 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 400; color: var(--muted); }
kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--key-bg);
  font: 600 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  text-align: center;
}
.fine { color: var(--muted); font-size: 12px; margin-top: 12px; }
.fine a { color: var(--muted); }

/* Start menu (inside the stage cover) */
.cover { overflow-y: auto; }
.menu, .invite { display: flex; flex-direction: column; align-items: center; gap: 14px; width: min(100%, 560px); }
.menu .start { width: 100%; }
.menu-net { width: 100%; display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid #3a3326; border-radius: 8px; background: rgba(0, 0, 0, 0.45); }
.modes { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.mode { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: #e8e6e3; }
.mode:hover { background: rgba(255, 255, 255, 0.05); }
.mode input { margin-top: 4px; accent-color: #e0b23a; }
.mode small { display: block; color: #b8b2a7; font-size: 12px; }
.mode[hidden] { display: none; }
.start.alt { font-size: 17px; padding: 10px 20px; }
.join-row { display: flex; gap: 8px; }
.join-row input, .np input {
  font: 600 15px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.12em;
  flex: 1 1 auto; min-width: 0; padding: 7px 9px;
  color: #e8e6e3; background: #0b0b0d; border: 1px solid #3a3a42; border-radius: 6px;
}
.join-row input { text-transform: uppercase; }
.join-row button { color: #e8e6e3; background: #16161a; border-color: #3a3a42; }
.join-row input:focus-visible, .np input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.invite-text { margin: 0; color: #e8e6e3; font-size: 15px; max-width: 30em; }
button.plain { background: transparent; border: 0; color: #b8b2a7; text-decoration: underline; font-size: 13px; }

/* Network panel below the stage */
.np { width: min(100%, 960px); margin: 0 0 8px; padding: 8px 12px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.np[hidden] { display: none; }
.np h2 { font-size: 16px; margin: 0 0 8px; color: var(--accent); }
.np-share { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.np-share[hidden], .np-link[hidden] { display: none; }
.np-codebox b { font: 700 22px/1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.12em; color: var(--accent); }
.np-link { display: inline-flex; gap: 8px; flex: 1 1 320px; min-width: 0; }
.np input { color: var(--text); background: var(--bg); border-color: var(--line); letter-spacing: 0; font-weight: 400; font-size: 13px; }
.np-msg { margin: 8px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.np-msg.error { color: var(--danger); }
.np-stats { margin: 6px 0 0; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--muted); overflow-wrap: anywhere; }
.np-warn { margin: 6px 0 0; padding: 6px 10px; font-weight: 600; color: #fff; background: var(--danger); border-radius: 4px; }
.dos canvas.np-screen { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }
.ns-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; display: none; }
body.ns-guest .ns-video { display: block; }
body.ns-guest .dos { display: none; }
.help .sub-h { font-size: 15px; margin: 18px 0 8px; color: var(--text); }
.kb-note { margin-top: 0; }
table.main-keys { flex: 0 1 520px; }
.cover-note.error-note { color: #ff8a80; }
body[data-mode] .cover .menu { display: none; }
.menu[hidden], .invite[hidden] { display: none; }
/* The network panel as an overlay on the stage while the game is not live */
.np.np-over {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 12;
  width: min(calc(100% - 2 * var(--gutter)), 640px); margin: 0; padding: 16px 18px;
  color: #e8e6e3; background: rgba(14, 14, 17, 0.94); border-color: #3a3326; border-radius: 8px; text-align: center;
}
.np.np-over h2 { color: #e0b23a; }
.np.np-over .np-share { justify-content: center; }
.np.np-over .np-codebox b { color: #e0b23a; font-size: 30px; }
.np.np-over input { color: #e8e6e3; background: #0b0b0d; border-color: #3a3a42; }
.np.np-over button { color: #e8e6e3; background: #16161a; border-color: #3a3a42; }
.np.np-over .np-msg { font-size: 15px; }
.np.np-over .np-msg.error { color: #ff8a80; }
.np.np-over .np-stats { color: #9a958c; }
.np-warn.np-warn-banner { position: absolute; left: 0; right: 0; top: 0; z-index: 12; margin: 0; border-radius: 0; text-align: center; font-size: 15px; padding: 8px 12px; opacity: 0.95; }
