:root {
  --bg: #1b1e24;
  --panel: #23272f;
  --text: #e8e6e3;
  --muted: #9aa0a8;
  --accent: #4f8a5b;
  --accent-hover: #5d9d6a;
  --danger: #b4553f;
  --border: #333a45;
  --w: #f2efe6;
  --b: #3a3f4a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.tagline {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--accent);
  border: none;
  border-radius: 7px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

button.ghost:hover:not(:disabled) {
  background: var(--panel);
}

button.danger {
  background: var(--danger);
}

button.ready {
  outline: 2px solid var(--accent-hover);
  outline-offset: 1px;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}

.error {
  color: #e8a33d;
  min-height: 1.2em;
}

/* ---- home ---- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}

.panel label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--muted);
  width: 100%;
}

.panel input {
  width: 100%;
}

/* ---- room header ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.room-code {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
}

.link-input {
  width: 300px;
  max-width: 40vw;
}

.banner {
  margin: 0 0 0.9rem;
  padding: 0.6rem 0.85rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  font-size: 0.95rem;
  min-height: 1.2em;
}

/* ---- layout ---- */

.layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.board-col {
  flex: 1 1 520px;
  min-width: 300px;
}

.sidebar {
  flex: 1 1 280px;
  min-width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ---- player bars / clocks ---- */

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-variant-numeric: tabular-nums;
  transition: background 0.2s ease;
}

.player-bar.active {
  background: #2c3831;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.player-bar.red .player-clock {
  color: #e0685a;
  animation: pulse 1s infinite;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}

.player-name.dim,
.player-clock.dim {
  color: var(--muted);
  font-weight: 400;
}

.dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  display: inline-block;
}

.dot.w {
  background: var(--w);
  border: 1px solid var(--border);
}

.dot.b {
  background: var(--b);
}

.player-clock {
  font-size: 1.05rem;
  font-weight: 700;
}

.turn {
  text-align: center;
  margin-top: 0.5rem;
  font-weight: 600;
  color: var(--muted);
  min-height: 1.4em;
}

.turn.active {
  color: var(--text);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* ---- lobby ---- */

.tc-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.tc-row label {
  font-size: 0.9rem;
  color: var(--muted);
}

.tc-custom {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.tc-custom input {
  width: 3.5rem;
}

.participants {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.participant {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
}

.participant.me {
  border-color: var(--accent);
}

.p-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.p-name {
  font-weight: 600;
}

.p-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.p-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.p-actions button {
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}

.lobby-actions {
  margin-top: 0.25rem;
}

/* ---- game ---- */

.result {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.7rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.move-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 0.15rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

.move-list li {
  display: contents;
}

.move-list .num {
  color: var(--muted);
}

.move-list .ply {
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
}

.move-list .ply.current {
  background: var(--accent);
  color: #fff;
}

.history-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.game-actions {
  display: flex;
  gap: 0.5rem;
}

.game-actions button {
  flex: 1;
}

/* ---- activity log ---- */

.activity {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.activity li {
  display: flex;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.atime {
  color: #5d6370;
  flex-shrink: 0;
}

@media (max-width: 760px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
  }
  .link-input {
    width: 100%;
  }
}
