:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1d2130;
  --line: #2b3040;
  --ink: #e7eaf3;
  --dim: #8b93a7;
  --red: #d9534f;
  --red-soft: #3a1f22;
  --blue: #3f7fd9;
  --blue-soft: #16233a;
  --gold: #e3b341;
  --green: #57b97f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1100px 600px at 50% -15%, #1a1f2d, var(--bg));
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  flex-wrap: wrap; padding: 18px 26px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo { font-size: 30px; color: var(--gold); line-height: 1; }
h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.tag { margin: 2px 0 0; color: var(--dim); font-size: 12.5px; }
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.controls label {
  display: flex; gap: 6px; align-items: center;
  font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .6px;
}
select, input[type="text"] {
  background: var(--panel-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px; font-family: inherit;
}
button {
  background: var(--gold); color: #1a1503; border: 0; border-radius: 8px;
  padding: 9px 15px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--dim); font-weight: 400; padding: 6px 9px; }
button.ghost:hover { color: var(--ink); }

/* ---------- score bar ---------- */
.scorebar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 26px; border-bottom: 1px solid var(--line); background: rgba(23,26,35,.6);
}
.player { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.player.active { color: #fff; }
.player.active b { text-shadow: 0 0 12px currentColor; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.red { background: var(--red); }
.dot.blue { background: var(--blue); }
.hex-count {
  font: 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px;
}
.turn { color: var(--gold); font-size: 13px; letter-spacing: .4px; }

/* ---------- layout ---------- */
main {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px;
  gap: 26px; padding: 22px 26px; align-items: start;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }

.boardwrap { position: relative; }
#board { width: 100%; height: auto; max-height: 72vh; display: block; overflow: visible; }
.hint { text-align: center; color: var(--dim); font-size: 12.5px; margin-top: 6px; }

/* ---------- hexes ---------- */
.hex { cursor: pointer; }
.hex polygon {
  fill: #eef2f6; stroke: #9ba8ba; stroke-width: 2;
  transition: fill .16s ease, stroke .16s ease;
}
.hex.owned-0 polygon { fill: #ffe4e6; stroke: #e11d48; stroke-width: 2.5; }
.hex.owned-1 polygon { fill: #e0f2fe; stroke: #0284c7; stroke-width: 2.5; }
.hex.own { cursor: default; }
.hex.enemy:hover polygon { stroke: var(--red); stroke-dasharray: 6 4; }
.hex:not(.taken):hover polygon { fill: #ffffff; stroke: var(--gold); }
.hex.selected polygon { stroke: var(--gold); stroke-width: 3.5; }
.crest-mono {
  font-size: 14px; font-weight: 700; text-anchor: middle; fill: #fff;
  letter-spacing: .6px; pointer-events: none;
  paint-order: stroke; stroke: rgba(0,0,0,.45); stroke-width: 2.5px;
}
.hex-label {
  fill: #0f172a; font-size: 13px; font-weight: 700; text-anchor: middle;
  pointer-events: none;
}
.hex-kind {
  fill: #475569; font-size: 9px; font-weight: 700; letter-spacing: 1.1px; text-anchor: middle;
  pointer-events: none; text-transform: uppercase;
}
.hex.flash polygon { animation: flash .55s ease; }
@keyframes flash {
  0% { stroke: var(--gold); stroke-width: 5; }
  100% { stroke-width: 2; }
}

/* ---------- claim panel ---------- */
.side { display: flex; flex-direction: column; gap: 16px; }
.claim, .panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
}
.claim-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.claim-hex { font-size: 15px; font-weight: 600; }
.claim-hex small { color: var(--dim); font-weight: 400; margin-left: 6px; font-size: 11px; text-transform: uppercase; }
.typeahead { position: relative; }
.typeahead input { width: 100%; padding: 11px 12px; font-size: 15px; }
#suggestions {
  list-style: none; margin: 6px 0 0; padding: 5px; position: absolute; z-index: 20; width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 16px 34px rgba(0,0,0,.5); max-height: 250px; overflow: auto;
}
#suggestions[hidden] { display: none; }
#suggestions li { padding: 8px 10px; border-radius: 7px; cursor: pointer; }
#suggestions li .label { font-size: 14px; }
#suggestions li .meta {
  float: right; color: var(--dim);
  font: 11px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}
#suggestions li.active { background: #2c3346; }
#suggestions li.none { color: var(--dim); cursor: default; font-size: 13px; }
.submit { width: 100%; margin-top: 10px; }
.claim-note { color: var(--dim); font-size: 12px; margin: 8px 0 0; min-height: 16px; }

.panel h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--dim); margin: 0 0 8px; font-weight: 600;
}
.panel h2 + h2, .message + h2 { margin-top: 16px; }
.message { margin: 0; font-size: 13.5px; }
.message.ok { color: var(--green); }
.message.bad { color: var(--red); }
.metrics { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; margin: 0; font-size: 12.5px; }
.metrics dt { color: var(--dim); }
.metrics dd { margin: 0; text-align: right; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.metrics dd.good { color: var(--green); }
.metrics dd.bad { color: var(--red); }

/* ---------- log ---------- */
.log { padding: 4px 26px 40px; }
.log h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .9px; color: var(--dim); }
#log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#log li {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--dim);
}
#log li.ok { border-left-color: var(--green); color: var(--ink); }
#log li.bad { border-left-color: var(--red); }
#log li .who { font-weight: 600; margin-right: 8px; }
#log li .who.red { color: var(--red); }
#log li .who.blue { color: var(--blue); }

/* ---------- answers panel ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h2 { margin: 0; }
button.small { padding: 5px 10px; font-size: 12px; }
.panel-note { color: var(--dim); font-size: 12px; margin: 10px 0 0; }
.answers { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 42vh; overflow: auto; }
.answers[hidden] { display: none; }
.answers li {
  border-left: 3px solid var(--line); padding: 6px 9px; border-radius: 6px;
  background: var(--panel-2);
}
.answers li.owned-0 { border-left-color: var(--red); }
.answers li.owned-1 { border-left-color: var(--blue); }
.answer-head { display: flex; align-items: center; gap: 7px; }
.swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }
.answer-hex { font-size: 13px; font-weight: 600; }
.answer-count { margin-left: auto; color: var(--dim); font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.answer-names { margin: 3px 0 0 16px; color: var(--dim); font-size: 12px; }

/* ---------- modals & overlays ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 18, 0.84);
  backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  max-width: 440px; width: 100%; padding: 24px 28px; box-shadow: 0 20px 40px rgba(0,0,0,.6);
}
.modal-brand { text-align: center; margin-bottom: 22px; }
.modal-brand .logo { font-size: 38px; color: var(--gold); }
.modal-brand h2 { margin: 8px 0 4px; font-size: 20px; }
.mode-options { display: flex; flex-direction: column; gap: 12px; }
.mode-card {
  display: flex; align-items: center; gap: 16px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 16px;
  cursor: pointer; text-align: left; transition: transform .15s, border-color .15s, background .15s;
  color: var(--ink); font-weight: normal;
}
.mode-card:hover {
  transform: translateY(-2px); border-color: var(--gold); background: #232838;
}
.mode-card.primary {
  border-color: rgba(227, 179, 65, 0.45);
}
.mode-icon { font-size: 28px; flex: 0 0 auto; }
.mode-info h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; color: #fff; }
.mode-info p { margin: 0; font-size: 12.5px; color: var(--dim); }

.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.room-status { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; font-size: 14px; color: var(--gold); }
.pulse-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--gold);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}
.share-box { display: flex; gap: 8px; margin-bottom: 12px; }
.share-box input { flex: 1; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.modal-note { font-size: 12.5px; color: var(--dim); margin: 0; line-height: 1.4; }

.player .badge-role {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--line); border-radius: 4px; padding: 2px 5px; margin-left: 4px;
}
