:root {
  --bg: #13131c;
  --panel: #1d1d2b;
  --panel2: #272739;
  --text: #ececf4;
  --muted: #9a9ab0;
  --accent: #7c5cff;
  --danger: #ff5470;
  --ok: #3ddc84;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
.dim { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0; }

button {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid #3a3a52;
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.97); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
button.primary.on {
  background: var(--ok);
  border-color: var(--ok);
  color: #10241a;
}

input {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--panel2);
  border: 1px solid #3a3a52;
  border-radius: var(--radius);
  padding: 12px 14px;
  width: 100%;
}
input::placeholder { color: var(--muted); }

/* ---------- join & lobby ---------- */

.view {
  min-height: 100vh;
  min-height: 100dvh;
}

#view-join, #view-lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.card {
  background: var(--panel);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.card.narrow { width: 100%; max-width: 380px; text-align: center; }

h1 { margin: 0 0 4px; font-size: 2rem; }
h1 em { color: var(--accent); font-style: normal; }
.tagline { color: var(--muted); margin: 0 0 20px; }

#join-form { display: flex; flex-direction: column; gap: 10px; }
.code-row { display: flex; gap: 8px; }
.code-row input { text-transform: uppercase; letter-spacing: 2px; flex: 1; }
.code-row button { flex: 0 0 52px; }

.browse { margin-top: 20px; text-align: left; }
.browse h3 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}
#room-list { display: flex; flex-direction: column; gap: 6px; }
#room-list p { margin: 0; font-size: 0.9rem; }
.room-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
}
.room-entry b { letter-spacing: 2px; }
.room-entry .dim { font-size: 0.85rem; }

#lobby-settings {
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 4px 14px;
  margin-bottom: 16px;
  text-align: left;
}
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}
.setting input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.setting select {
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #3a3a52;
  border-radius: 8px;
  padding: 6px 10px;
}
.setting input:disabled, .setting select:disabled { opacity: 0.55; }

.howto { text-align: left; margin-top: 20px; color: var(--muted); }
.howto summary { cursor: pointer; color: var(--text); }
.howto ul { padding-left: 20px; }
.howto li { margin: 6px 0; }

#view-lobby h2 { margin: 0; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; }
#lobby-code {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 6px;
  margin: 4px 0 12px;
}
#btn-share { width: 100%; margin-bottom: 16px; }
#lobby-players { list-style: none; padding: 0; margin: 0 0 12px; }
#lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 6px;
  text-align: left;
}
#lobby-players .check { margin-left: auto; }
#btn-ready { width: 100%; margin-bottom: 8px; }
#btn-leave { width: 100%; background: transparent; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: 0 0 14px;
  display: inline-block;
}

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

#view-game {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#game-top {
  flex: none;
  padding: 8px 44px 4px;
  text-align: center;
  position: relative;
}
#btn-leave-game {
  position: absolute;
  right: 6px;
  top: 6px;
  padding: 4px 8px;
  min-height: 0;
  background: transparent;
  border: none;
  font-size: 1.1rem;
}
#word-banner { font-size: 1rem; }
#word-banner b { color: var(--accent); }
#word-banner.impostor b { color: var(--danger); }
#turn-banner { font-size: 0.85rem; color: var(--muted); min-height: 1.2em; }
#turn-banner.me { color: var(--ok); font-weight: 600; }

#game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#canvas-wrap {
  flex: none;
  height: min(72vw, 44dvh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
#cv {
  background: #fff;
  border-radius: 8px;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
#cv.drawable { cursor: crosshair; box-shadow: 0 0 0 3px var(--ok); }

#side {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 8px 8px;
}

#vote-status {
  flex: none;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 2px 4px;
}

#players-strip {
  flex: none;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 8px;
}
.chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 38px;
  font-size: 0.85rem;
  border-radius: 999px;
  position: relative;
}
.chip .dot { width: 10px; height: 10px; flex-basis: 10px; }
.chip.turn { box-shadow: 0 0 0 2px var(--ok); }
.chip.myvote { box-shadow: 0 0 0 2px var(--danger); }
.chip.turn.myvote { box-shadow: 0 0 0 2px var(--ok), 0 0 0 4px var(--danger); }
.chip.dead { opacity: 0.45; text-decoration: line-through; }
.chip.spec { opacity: 0.65; border-style: dashed; }
.chip.me { font-weight: 700; }
.chip .badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
}
.chip .voted-mark { color: var(--ok); font-size: 0.75rem; }

#chat-log {
  flex: 1;
  min-height: 50px;
  overflow-y: auto;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 0.9rem;
}
.msg { margin: 3px 0; overflow-wrap: anywhere; }
.msg.system { color: var(--muted); font-style: italic; }
.msg.deadmsg { opacity: 0.6; }

#chat-form { flex: none; display: flex; gap: 6px; margin-top: 6px; }
#chat-form input { flex: 1; }
#chat-form button { flex: 0 0 52px; }

/* ---------- overlay ---------- */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
#overlay .card { max-width: 360px; width: 100%; text-align: center; }
#overlay h2 { margin: 0 0 8px; }
#ov-buttons, #ov-cancel { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
#ov-buttons.hidden, #ov-cancel.hidden { display: none; }

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  #game-main { flex-direction: row; padding: 8px 16px 16px; gap: 16px; }
  #canvas-wrap { flex: 1; height: auto; min-width: 0; }
  #side { flex: 0 0 340px; padding: 0; }
  #players-strip { flex-wrap: wrap; overflow-x: visible; }
  #game-top { padding-top: 12px; }
  #word-banner { font-size: 1.2rem; }
}
