:root {
  --bg: #eef3ea;
  --card: #ffffff;
  --ink: #22301f;
  --muted: #7c897b;
  --line: #dde6d8;
  --grass-deep: #2f7d3a;
  --grass-mid: #3c9a48;
  --grass-light: #4cb95c;
  --gold: #f2b632;
  --maroon: #732b23;
  --poison: #9b30b5;
  --shadow: 0 10px 30px rgba(40,60,35,.14);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.screen { padding: 24px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .82rem; margin-top: 10px; }
.error { color: #c0392b; font-weight: 600; min-height: 1.2em; margin-top: 8px; }

/* ---------- card ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  max-width: 460px;
}
.card.center { margin: 6vh auto 0; }

/* ---------- lobby ---------- */
.logo {
  font-size: 2.6rem;
  letter-spacing: .04em;
  color: var(--ink);
  font-weight: 800;
}
.logo span { color: var(--maroon); margin-left: .15em; }
.tagline { color: var(--muted); margin: 4px 0 18px; }

.how {
  background: #f4f8f1;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: .9rem;
  line-height: 1.5;
  margin-bottom: 18px;
}
.how p + p { margin-top: 6px; }
.poison-text { color: var(--poison); }

#player-rows { margin: 14px 0 6px; display: flex; flex-direction: column; gap: 8px; }
.prow {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f7faf5;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}
.prow .dot { width: 20px; height: 20px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 5px rgba(0,0,0,.18); }
.prow input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
  font-weight: 600;
}
.prow .rm {
  border: none; background: transparent; color: #c9d3c6; cursor: pointer;
  font-size: 1.1rem;
}
.prow .rm:hover { color: #c0392b; }

.controls { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- mode tabs ---------- */
.mode-tabs { display: flex; gap: 8px; margin: 14px 0 16px; background: #eef3e9; border-radius: 12px; padding: 5px; }
.mode-tabs .tab {
  flex: 1; border: none; background: transparent; padding: 9px; font-size: .9rem;
  border-radius: 9px; color: var(--muted); font-weight: 700;
}
.mode-tabs .tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 6px rgba(40,60,35,.12); }

/* ---------- online ---------- */
.online-join { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.online-join input, .code-input {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 1rem; font-family: inherit; color: var(--ink); background: #fff; outline: none;
}
.code-input { max-width: 120px; text-transform: uppercase; }
.controls input[type=text] { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 1rem; }
.controls .code-input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 1rem; width: 110px; }

.room-code { font-size: 1.4rem; font-weight: 800; margin: 8px 0 2px; }
.room-code b { color: var(--maroon); letter-spacing: .06em; }
.invite { font-size: .8rem; color: var(--muted); margin-bottom: 12px; word-break: break-all; }
.invite span { color: var(--ink); font-weight: 600; }
#room-players { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
#room-players li { display: flex; align-items: center; gap: 9px; font-size: .9rem; padding: 6px 8px; }
#room-players .dot { width: 15px; height: 15px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 4px rgba(0,0,0,.2); }
#room-players .hosttag { font-size: .68rem; color: var(--gold); font-weight: 800; margin-left: auto; }
#room-players .you { font-size: .68rem; color: var(--muted); font-weight: 700; margin-left: auto; }

.note-banner {
  background: #fff7e6; border: 1px solid #f2d795; color: #7a5b12;
  border-radius: 10px; padding: 8px 12px; font-size: .85rem; font-weight: 600; margin-top: 10px;
}
button {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 11px 16px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform .05s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--maroon); color: #fff; }
button.primary:hover { background: #5e221c; }
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: #f3f7f0; }
button.small { padding: 7px 12px; font-size: .85rem; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto 14px;
  gap: 12px;
}
.brand { font-weight: 800; font-size: 1.15rem; display:flex; align-items:center; gap:8px;}
.brand-pin { color: var(--gold); font-size: 1.3rem; }
.turn-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 999px; padding: 8px 16px;
  box-shadow: var(--shadow); font-weight: 700; font-size: .95rem;
}
.turn-chip .tball { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 -4px 6px rgba(0,0,0,.22); }
.turn-chip .again { color: var(--gold); font-size: .8rem; font-weight: 800; }
.room-badge { background: var(--maroon); color: #fff; font-weight: 800; font-size: .8rem; padding: 6px 12px; border-radius: 999px; letter-spacing: .04em; }

/* ---------- stage ---------- */
.stage { display: flex; gap: 18px; max-width: 1280px; margin: 0 auto; align-items: flex-start; }
.field-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
#field {
  width: 100%;
  aspect-ratio: 3 / 2;          /* logical field 1200x800 = 3:2 */
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.aim-hint, .ready-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(20,30,18,.78); color: #fff; padding: 7px 14px;
  border-radius: 999px; font-size: .85rem; pointer-events: none; white-space: nowrap;
}

/* ---------- side panel ---------- */
.panel { width: 300px; flex: none; display: flex; flex-direction: column; gap: 14px; }
.objective, .players-card, .log-card {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 16px;
}
.obj-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.obj-text { font-weight: 800; font-size: 1.15rem; margin-top: 3px; }
.obj-text.poison { color: var(--poison); }

.card-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
#players-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
#players-list li {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 9px; border: 1px solid transparent; font-size: .9rem;
}
#players-list li.turn { border-color: var(--gold); background: #fffaf0; font-weight: 700; }
#players-list li.elim { opacity: .45; }
#players-list .pdot { width: 15px; height: 15px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 4px rgba(0,0,0,.2); }
#players-list .pname { flex: 1; }
#players-list .pstage { font-size: .72rem; color: var(--muted); font-weight: 600; }
#players-list .pstage.poison { color: var(--poison); font-weight: 800; letter-spacing: .03em; }
#players-list li.elim .pname { text-decoration: line-through; }
.turn-arrow { color: var(--gold); font-weight: 800; font-size: 1rem; width: 14px; }

.log-card { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
#event-log {
  list-style: none; overflow-y: auto; max-height: 240px;
  font-size: .85rem; line-height: 1.45; display: flex; flex-direction: column; gap: 4px;
}
#event-log li { padding-left: 14px; position: relative; }
#event-log li::before { content: "•"; position: absolute; left: 2px; color: var(--muted); }
#event-log li.hot { color: var(--maroon); font-weight: 700; }
#event-log li.poison { color: var(--poison); font-weight: 700; }
#event-log li.win { color: #1e7a2e; font-weight: 800; font-size: .95rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  /* NOTE: .stage is align-items:flex-start, so in column direction .field-wrap
     has no definite width and the canvas (width:100%) collapses to 0x0 —
     the board disappears on phones. Stretch + width:100% fixes it. */
  .stage { flex-direction: column; align-items: stretch; }
  .field-wrap { width: 100%; }
  .panel { width: 100%; }
  .logo { font-size: 2rem; }
}