:root {
  --bg: #0d0f0c;
  --fg: #c9d1c3;
  --dim: #5f6b5a;
  --frame: #4b5646;
  --x: #ffb000;
  --o: #4fd6e0;
  --accent: #7cff6b;
  --boom: #ff5a4f;
  --btn-bg: #1f3a5f;
  --btn-fg: #f2f5ef;
  --sel-bg: #c9d1c3;
  --sel-fg: #0d0f0c;
  --font: "JetBrains Mono", "IBM Plex Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px;
}

pre { margin: 0; font-family: var(--font); }

/* 47 columns must fit the viewport: a monospace glyph is about 0.6em wide. */
#screen, .banner {
  font-size: clamp(9px, calc((100vw - 32px) / 47 / 0.61), 18px);
  line-height: 1.2;
  user-select: none;
  outline: none;
  white-space: pre;
}
#screen { cursor: default; }
#screen [data-hit] { cursor: pointer; }
#screen.shake { animation: shake 0.25s linear; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 0); }
}
@media (prefers-reduced-motion: reduce) { #screen.shake { animation: none; } }

.c-frame, .c-mark, .c-dim, .c-used { color: var(--dim); }
.c-frame { color: var(--frame); }
.c-label { color: var(--fg); }
.c-x { color: var(--x); font-weight: 700; }
.c-o { color: var(--o); font-weight: 700; }
.c-moving { text-shadow: 0 0 6px currentColor; }
.c-src { text-decoration: underline; }
.c-sel, .c-cur { background: var(--sel-bg); color: var(--sel-fg); }
.c-recent { text-decoration: underline; color: var(--accent); }
.c-dst { color: var(--accent); font-weight: 700; animation: pulse 1s ease-in-out infinite; }
.c-boom { color: var(--boom); font-weight: 700; }
.c-die { color: var(--fg); }
.c-rolling { color: var(--x); }
.c-landed { color: #fff; font-weight: 700; }
.c-used { color: var(--dim); }
.c-btn { background: var(--btn-bg); color: var(--btn-fg); font-weight: 700; }
.c-btn.c-off { background: transparent; color: var(--dim); font-weight: 400; }
.c-turn { color: var(--x); font-weight: 700; }
.c-name { color: #fff; }
.c-warn { color: var(--boom); }
.c-score { color: var(--o); }
.c-status { color: #fff; font-weight: 700; }
.c-invite { color: var(--o); }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .c-dst { animation: none; } }

.banner { color: var(--x); margin-bottom: 24px; }

form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin: 12px 0;
}
label { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input {
  font: inherit;
  background: transparent;
  color: var(--fg);
  border: 0;
  border-bottom: 1px dashed var(--dim);
  padding: 4px 2px;
  min-width: 0;
}
input:focus { outline: none; border-bottom-color: var(--accent); }
button {
  font: inherit;
  font-weight: 700;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 0;
  padding: 4px 6px;
  cursor: pointer;
}
button:focus-visible, input:focus-visible { outline: 1px solid var(--accent); }

#invite {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 14px;
}
#invite input { flex: 1; color: var(--o); }

/* Board and chat side by side on wide screens, chat below the board on phones. */
.table {
  display: grid;
  gap: 16px;
}
@media (min-width: 900px) {
  .table {
    grid-template-columns: auto minmax(240px, 1fr);
    align-items: stretch;
  }
}

#chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 200px;
  max-height: 45vh;
  border: 1px dashed var(--frame);
  padding: 8px 10px;
  font-size: 13px;
}
@media (min-width: 900px) {
  #chat { max-height: none; }
}
.chat-title { color: var(--dim); text-align: center; margin-bottom: 6px; }
#chat-log {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-wrap: anywhere;
}
#chat-log li { margin: 2px 0; line-height: 1.35; }
#chat-log .time { color: var(--dim); }
#chat-log .who-x { color: var(--x); font-weight: 700; }
#chat-log .who-o { color: var(--o); font-weight: 700; }
#chat-log .who-spectator { color: var(--dim); font-style: italic; }
#chat-log .empty { color: var(--dim); }
#chat-form { margin: 8px 0 0; flex-wrap: nowrap; gap: 6px; }
#chat-form span { color: var(--accent); }
#chat-input { flex: 1; min-width: 0; }

#log-box { margin-top: 16px; font-size: 13px; color: var(--dim); }
#log-box summary { cursor: pointer; }
#log { max-height: 240px; overflow-y: auto; margin: 8px 0 0; padding-left: 3.5em; color: var(--fg); }

.hint { color: var(--dim); font-size: 13px; }
.hint a { color: var(--o); }
.hint code { color: var(--o); }
.error { color: var(--boom); min-height: 1.2em; }
