:root {
  --bg: #1d2330;
  --panel: #f8f8f0;
  --ink: #383838;
  --muted: #6b7280;
  --accent: #d84838;
  --line: #c8c8c0;
  --chat-bg: #10141c;
  --chat-ink: #e6e6e6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#app {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  min-height: 100%;
}

#screen {
  position: relative;
  width: min(720px, 100%);
  aspect-ratio: 3 / 2;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.panel {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 32px));
  max-height: calc(100% - 24px);
  overflow: auto;
  background: var(--panel);
  border: 4px solid #4a6a9a;
  border-radius: 10px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel h1 { margin: 0; font-size: 26px; letter-spacing: 2px; color: var(--accent); text-align: center; }
.panel .sub { margin: -6px 0 4px; text-align: center; color: var(--muted); font-size: 13px; }
.panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.panel label.inline { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.panel input:not([type=radio]) {
  font: inherit; font-size: 15px; padding: 8px 10px; border: 2px solid var(--line); border-radius: 6px; background: #fff;
}
.panel input:focus-visible { outline: 2px solid #4a6a9a; outline-offset: 1px; }
.panel fieldset { border: 2px solid var(--line); border-radius: 6px; margin: 0; padding: 6px 10px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.panel legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.panel .row { display: flex; gap: 8px; }
.panel button {
  flex: 1; font: inherit; font-weight: 700; padding: 10px; border-radius: 6px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
}
.panel button.ghost { background: transparent; color: #4a6a9a; border: 2px solid #4a6a9a; }
.panel button:disabled { opacity: .6; cursor: wait; }
.error { color: #b42318; min-height: 1em; margin: 0; font-size: 13px; }

#side {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#chat {
  background: var(--chat-bg);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  height: 300px;
}
#chatLog {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--chat-ink);
  word-wrap: break-word;
}
#chatLog .sys { color: #9ca3af; font-style: italic; }
#chatLog b { color: #f7c948; }
#chatInput {
  font: inherit; font-size: 13px; border: 0; border-top: 1px solid #2a3140; padding: 8px 10px;
  background: #171c26; color: var(--chat-ink); border-radius: 0 0 6px 6px;
}
#chatInput:focus-visible { outline: 2px solid #4a6a9a; }

#help {
  background: #262d3b;
  color: #d1d5db;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
}
#help h2 { margin: 0 0 6px; font-size: 14px; color: #fff; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 8px; }
#help dt { font-weight: 700; color: #f7c948; }
#help dd { margin: 0; }
#help p { margin: 6px 0 0; }
#status { color: #9ca3af; }

@media (max-width: 1080px) {
  #app { flex-direction: column; align-items: center; }
  #side { width: min(720px, 100%); }
  #chat { height: 200px; }
}
