:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --text: #1e1f22;
  --muted: #6b6f76;
  --line: #dcdad3;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --error: #b3261e;
  --light-sq: #eeeed2;
  --dark-sq: #769656;
  --pick: #f6f669;
  --mark: rgba(20, 20, 20, 0.22);
  --typed: #1e1f22;
  --wrong: #b3261e;
  --todo: #9a9ca1;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181b;
    --panel: #212226;
    --text: #e8e6e1;
    --muted: #9a9ca1;
    --line: #34363b;
    --accent: #5fb38a;
    --accent-text: #0e1a14;
    --error: #ff8a80;
    --light-sq: #b8b49b;
    --dark-sq: #5d7a48;
    --typed: #e8e6e1;
    --wrong: #ff8a80;
    --todo: #6b6f76;
  }
}
:root[data-theme="dark"] {
  --bg: #17181b; --panel: #212226; --text: #e8e6e1; --muted: #9a9ca1; --line: #34363b;
  --accent: #5fb38a; --accent-text: #0e1a14; --error: #ff8a80; --light-sq: #b8b49b;
  --dark-sq: #5d7a48; --typed: #e8e6e1; --wrong: #ff8a80; --todo: #6b6f76;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 1.3rem; margin: 0; }
.muted { color: var(--muted); }
.status { min-height: 1.4em; color: var(--muted); }
.error { color: var(--error); }
button, input { font: inherit; }
button {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px;
  padding: 0.45em 0.9em; cursor: pointer;
}
a.button {                                  /* (a link that looks like one: the home card's Open your nimlog) */
  display: inline-block; background: var(--accent); color: var(--accent-text); border-radius: 6px;
  padding: 0.45em 0.9em; text-decoration: none;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
button:disabled { opacity: 0.5; cursor: default; }
input {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.45em 0.6em; min-width: 0;
}

.card {
  max-width: 420px; margin: 12vh auto 0; padding: 24px 16px;
}
.card form { display: grid; gap: 8px; margin-top: 16px; }

#session { max-width: 1100px; margin: 0 auto; padding: 12px 16px; }
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.pill { border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 0.85rem; color: var(--muted); }
.pill.off { color: var(--error); border-color: var(--error); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
@media (max-width: 760px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.play, .chat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.seats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.seat { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 0.9rem; }
.seat.you { border-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.chat { display: flex; flex-direction: column; height: min(70vh, 640px); }
#messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#messages li { padding: 3px 0; overflow-wrap: anywhere; }
#messages .who { font-weight: 600; margin-right: 6px; }
#chat-form { display: flex; gap: 6px; margin-top: 8px; }
#chat-form input { flex: 1; }

/* chess */
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); width: min(100%, 480px);
  aspect-ratio: 1; border: 1px solid var(--line); user-select: none;
}
.sq {
  display: flex; align-items: center; justify-content: center; position: relative;
  font-size: clamp(22px, 6vw, 44px); line-height: 1; cursor: pointer; color: #111; min-height: 0; overflow: hidden;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.pick, .sq.last { box-shadow: inset 0 0 0 3px var(--pick); }
.sq.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: var(--mark);
}
.piece.w { color: #fff; text-shadow: 0 0 2px #000, 0 0 1px #000; }
.piece.b { color: #111; }
.moves { font-family: ui-monospace, monospace; font-size: 0.9rem; margin: 8px 0; overflow-wrap: anywhere; }
.chess-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.clocks { font-family: ui-monospace, monospace; }
.promo { display: flex; gap: 6px; margin: 8px 0; }

/* tic-tac-toe */
.ttt { display: grid; grid-template-columns: repeat(3, 72px); gap: 6px; }
.ttt button {
  width: 72px; height: 72px; font-size: 2rem; background: var(--bg); color: var(--text);
  border: 1px solid var(--line);
}

/* typing */
.race-text { font-family: ui-monospace, monospace; font-size: 1.2rem; line-height: 1.7; white-space: pre-wrap; outline: none; padding: 8px; border-radius: 6px; border: 1px solid var(--line); }
.race-text:focus { border-color: var(--accent); }
.race-text .ok { color: var(--typed); }
.race-text .bad { color: var(--wrong); text-decoration: underline; }
.race-text .todo { color: var(--todo); }
.race-text .cur { border-left: 2px solid var(--accent); margin-left: -2px; }
.race-board { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 0.95rem; }
.race-board td, .race-board th { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); }
.big { font-size: 1.6rem; font-weight: 600; }

canvas.retro { width: min(100%, 720px); image-rendering: pixelated; background: #000; border-radius: 6px; }
.small { font-size: .85em; } #gpl { margin: 8px 16px; }

/* a read link: the document */
#reader { max-width: 46rem; margin: 2rem auto; padding: 0 16px; }
#filler { max-width: 34rem; margin: 2rem auto; padding: 0 16px; }
#form-fields { display: grid; gap: .9rem; margin-top: 1rem; }
#form-fields label { display: grid; gap: .25rem; }
#form-fields .choices { display: flex; flex-wrap: wrap; gap: .5rem 1rem; }
#form-fields .choices label, #form-fields label.check { display: flex; align-items: center; gap: .4rem; }
#form-fields .help { font-size: .85em; }
#form-fields input:not([type=checkbox]), #form-fields select, #form-fields textarea { width: 100%; box-sizing: border-box; }
#reader header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
#reader h1 { overflow-wrap: anywhere; }
.doc { line-height: 1.6; overflow-wrap: anywhere; }
.doc pre { background: var(--panel); border: 1px solid var(--line); padding: 0.75rem; overflow-x: auto; }
.doc code { font-size: 0.92em; }
.doc img { max-width: 100%; }
.doc blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 1rem; color: var(--muted); }
.doc table { border-collapse: collapse; display: block; overflow-x: auto; }
.doc td, .doc th { border: 1px solid var(--line); padding: 0.25rem 0.5rem; }
.doc a[data-wiki] { color: var(--accent); text-decoration: none; cursor: default; }
.doc article.blk { border-bottom: 1px solid var(--line); padding: 0.5rem 0; }
.doc article.blk header { color: var(--muted); font-size: 0.9em; }
.doc article.blk header time { margin-left: 0.5rem; }
