:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232733;
  --text: #e9ecf1;
  --muted: #9aa3b2;
  --accent: #f5a623;
  --accent-2: #4a90e2;
  --tile: #f4ecd8;
  --tile-text: #2a2622;
}

* { 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;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--panel-2);
  color: var(--text);
  transition: filter 0.15s ease;
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--accent); color: #1a1300; font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--panel-2); }

input, select {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--panel-2);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
}

/* --- Landing --- */
.landing {
  max-width: 420px;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 20px;
}
.landing h1 { font-size: 3rem; margin: 0 0 8px; letter-spacing: 1px; }
.tagline { color: var(--muted); margin-bottom: 32px; }
.landing .primary { font-size: 1.1rem; padding: 14px 28px; }
.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); margin: 28px 0;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--panel-2);
}
.join-form { display: flex; gap: 8px; }
.join-form input { flex: 1; }

/* --- Room header --- */
.room-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; border-bottom: 1px solid var(--panel-2);
}
.home-link { color: var(--accent); text-decoration: none; font-weight: 700; font-size: 1.3rem; }
.room-meta { display: flex; align-items: center; gap: 12px; }
.room-name { color: var(--muted); font-family: ui-monospace, monospace; }
.player-count { color: var(--text); font-size: 0.9rem; background: var(--panel-2); padding: 4px 10px; border-radius: 999px; }

/* --- Presence --- */
.presence {
  display: flex; flex-wrap: wrap; gap: 12px 20px; justify-content: space-between;
  align-items: center; background: var(--panel); border-radius: 12px;
  padding: 12px 16px; margin-bottom: 24px;
}
.presence-list { display: flex; flex-wrap: wrap; gap: 8px; }
.player-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--panel-2);
  font-size: 0.9rem;
}
.player-chip.me { outline: 1px solid var(--chip); }
.player-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--chip); flex: none; }
.player-name { color: var(--chip); font-weight: 600; }

.you-editor { display: flex; align-items: center; gap: 8px; }
.you-editor label { color: var(--muted); font-size: 0.9rem; }
.you-editor input { padding: 6px 10px; width: 140px; }
.swatches { display: flex; gap: 4px; }
.swatch {
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
}
.swatch:hover { filter: brightness(1.1); }
.swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* --- Room layout --- */
.room { max-width: 720px; margin: 0 auto; padding: 24px 20px 60px; }
.board-area { display: flex; flex-direction: column; align-items: center; gap: 20px; }

.board-wrap { position: relative; width: min(90vw, 480px); }
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  gap: 8px;
  width: 100%;
  touch-action: none; /* let drag-to-trace work without scrolling on mobile */
}
.board.blurred { filter: blur(12px); pointer-events: none; user-select: none; }
.board-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 16px; color: var(--text); font-weight: 600; font-size: 1.1rem;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); pointer-events: none;
}
.board-hint[hidden] { display: none; }
.tile {
  aspect-ratio: 1 / 1;
  background: var(--tile);
  color: var(--tile-text);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: clamp(1.2rem, 6vw, 2.2rem);
  text-transform: uppercase;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  user-select: none;
}
.tile.blank {
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.06);
}
.tile.sel {
  outline: 4px solid var(--sel, var(--accent));
  outline-offset: -4px;
  filter: brightness(1.05);
}

/* Word being traced */
.tracer {
  min-height: 2rem;
  font-size: 1.6rem; font-weight: 700; letter-spacing: 2px; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center;
}
.tracer.good { color: #7ed321; }
.tracer.bad { color: #e74c3c; }

.timer-area { text-align: center; }
.timer {
  font-size: 3rem; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.timer.running { color: var(--accent); }
.status { color: var(--accent-2); min-height: 1.4em; margin-top: 4px; }

/* --- Controls --- */
.controls {
  display: flex; flex-wrap: wrap; gap: 20px; justify-content: center;
  margin-top: 28px;
}
.control-group {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); padding: 12px; border-radius: 12px;
}
.control-group label { color: var(--muted); font-size: 0.9rem; }

.show-words { display: block; margin: 28px auto 0; font-size: 1.05rem; }
.show-words[hidden] { display: none; }

/* --- Words --- */
.words { margin-top: 32px; background: var(--panel); border-radius: 12px; padding: 18px; }
.words-header { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.words-header h2 { margin: 0; font-size: 1.2rem; }
.muted { color: var(--muted); font-weight: 400; }
#words-filter { min-width: 200px; }
.words-list {
  list-style: none; padding: 0; margin: 16px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 4px 12px;
  max-height: 50vh; overflow-y: auto;
}
.words-list li {
  font-family: ui-monospace, monospace; color: var(--text);
  padding: 2px 0; border-bottom: 1px solid var(--panel-2);
}

/* --- Your words (during a round) --- */
.my-words, .results { margin-top: 28px; background: var(--panel); border-radius: 12px; padding: 18px; }
.my-words h2, .results h2 { margin: 0 0 4px; font-size: 1.2rem; }
.hint-text { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.found-list {
  list-style: none; padding: 0; margin: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 2px 12px;
}
.found-list li {
  display: flex; justify-content: space-between; gap: 8px;
  font-family: ui-monospace, monospace; color: var(--text);
  padding: 2px 0; border-bottom: 1px solid var(--panel-2);
}
.found-list li .p { color: var(--muted); }
.found-list li.dup { text-decoration: line-through; color: var(--muted); }
.found-list li.dup .p { color: var(--muted); }

/* --- Results --- */
.results-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px; margin-top: 12px;
}
.result-card { background: var(--panel-2); border-radius: 10px; padding: 12px; border-top: 4px solid var(--c, var(--accent)); }
.result-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.result-name { font-weight: 700; color: var(--c, var(--text)); }
.result-score { font-size: 1.4rem; font-weight: 700; }
.result-card .found-list { grid-template-columns: 1fr; max-height: 40vh; overflow-y: auto; }
