:root {
  --bg: #fbf8f1;
  --surface: #ffffff;
  --text: #1d1a14;
  --muted: #5c5547;
  --border: #c9bfa8;
  --accent: #8a5a00;
  --accent-text: #ffffff;
  --focus: #1a5fd0;
  --error: #a3221b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #221f17;
    --text: #f3eee2;
    --muted: #b9b09c;
    --border: #4a4434;
    --accent: #f2b33d;
    --accent-text: #1d1a14;
    --focus: #7fb0ff;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
textarea { resize: vertical; }
input[type="checkbox"], input[type="range"] { width: auto; }
button {
  padding: .5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field { margin-bottom: .75rem; }
.help { color: var(--muted); font-size: .9rem; margin: .25rem 0 0; }

/* Sign-in */
#auth-screen { max-width: 32rem; margin: 0 auto; padding: 2rem 16px; }
#auth-screen .intro { color: var(--muted); }
#auth-status:not(:empty) {
  padding: .75rem; border-left: 4px solid var(--accent);
  background: var(--surface); white-space: pre-wrap;
}
#auth-screen section, #auth-screen details {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; margin-top: 1rem;
}
summary { cursor: pointer; font-weight: 700; font-size: 1.1rem; }
details[open] summary { margin-bottom: .75rem; }
details form + form { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Game */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .75rem 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar h1 { margin: 0; font-size: 1.3rem; }
#who-am-i { margin: 0; color: var(--muted); flex: 1; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; }

.game {
  display: grid; gap: 1rem; padding: 1rem 16px;
  grid-template-columns: minmax(0, 1fr) 18rem;
  grid-template-rows: auto 1fr;
  grid-template-areas: "chat map" "chat online";
  align-items: start;
}
.chat { grid-area: chat; }
.map { grid-area: map; }
.online { grid-area: online; }
@media (max-width: 760px) {
  .game { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chat" "map" "online"; }
}
#map-area {
  min-height: 5rem; padding: .75rem; border: 2px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted);
}
#map-area:focus-visible { border-style: solid; border-color: var(--focus); outline-offset: 2px; color: var(--text); }
#map-pad { margin-top: .5rem; }
.pad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; margin-top: .5rem; }
.pad button { padding: .6rem .4rem; }
.row { display: flex; flex-wrap: wrap; gap: 0 1rem; }
.row .field { flex: 1 1 12rem; }
#chat-form { margin-top: 1rem; }
.game section { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }

#history {
  list-style: none; margin: 0; padding: 0;
  height: 55vh; overflow-y: auto;
  border-top: 1px solid var(--border);
}
@media (max-width: 760px) { #history { height: 45vh; } }


/* Dialogs */
dialog {
  width: min(40rem, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 1.25rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
#server-dialog-title, #alert-title { white-space: pre-wrap; }
#alert-message, #story-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.buttons { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
/* Every list is a listbox of options. */
[role="listbox"] { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
[role="option"] { padding: .45rem .5rem; border-bottom: 1px solid var(--border); cursor: default; white-space: pre-wrap; overflow-wrap: anywhere; }
[role="option"][aria-selected="true"] { background: var(--bg); }
[role="option"]:focus-visible { outline-offset: -3px; }
.menu-items { max-height: 60vh; border-top: 1px solid var(--border); }
.menu-items [role="option"], .form-list [role="option"] { cursor: pointer; }
.form-list { max-height: 14rem; border: 1px solid var(--border); border-radius: 6px; }
.label { font-weight: 600; margin: 0 0 .25rem; }
.help-text { max-height: 65vh; overflow-y: auto; }
.help-text h3 { font-size: 1.05rem; margin: 1rem 0 .25rem; }
.help-text ul { padding-left: 1.25rem; }
#help-title:focus { outline: none; }
#online { max-height: 60vh; }
.check { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.check label { margin: 0; font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 6px; }

/* Layouts. Sketchbook is everything above. Blackboard is chat only. Canvas
   is the map filling the page, with the message box popping up over it when
   Slash or Backslash asks for it. */
body.layout-blackboard .map { display: none; }
body.layout-blackboard .game { grid-template-columns: minmax(0, 1fr) 18rem; grid-template-areas: "chat online"; grid-template-rows: auto; }
@media (max-width: 760px) {
  body.layout-blackboard .game { grid-template-columns: minmax(0, 1fr); grid-template-areas: "chat" "online"; }
}

body.layout-canvas .topbar,
body.layout-canvas .online,
body.layout-canvas #map-heading,
body.layout-canvas #chat-heading,
body.layout-canvas #history { display: none; }
body.layout-canvas .game { display: block; padding: 0; }
body.layout-canvas .map {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  border: 0; border-radius: 0; padding: 16px;
}
body.layout-canvas #map-area { flex: 1; font-size: 1.6rem; }
body.layout-canvas .chat { display: none; }
body.layout-canvas.chatting .chat {
  display: block; position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 5;
  box-shadow: 0 4px 24px rgb(0 0 0 / .35);
}
body.layout-canvas #chat-form { margin-top: 0; }
