
* { box-sizing: border-box; }

:root {
  --ink-900: #0e1116;
  --ink-800: #161b22;
  --ink-700: #20262f;
  --parchment: #f6f3ea;
  --parchment-rgb: 246, 243, 234;
  --civilian: #12b886;
  --civilian-light: #2dd4a7;
  --imposter: #e0212b;
  --imposter-light: #f2545b;
}

:root[data-theme="light"] {
  --ink-900: #f5f1e6;
  --ink-800: #ffffff;
  --ink-700: #ece4d1;
  --parchment: #201d17;
  --parchment-rgb: 32, 29, 23;
  --civilian: #0c9668;
  --civilian-light: #0a7a54;
  --imposter: #c21721;
  --imposter-light: #a5121a;
}

:root[data-theme="light"] .btn.ghost {
  border-color: rgba(32,29,23,.25);
}
:root[data-theme="light"] .tag {
  background: rgba(194,23,33,.08);
}
:root[data-theme="light"] .result-card,
:root[data-theme="light"] .pass-card {
  color: var(--parchment);
}

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 500;
  background: var(--ink-700);
  border: 1px solid rgba(var(--parchment-rgb),.15);
  color: var(--parchment);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink-900);
  color: var(--parchment);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  min-height: 100dvh;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.screen { display: none; animation: fadeIn .3s ease; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Hero ---------- */
.hero { text-align: center; margin-bottom: 24px; }
.tag {
  display: inline-block;
  border: 1px solid rgba(224,33,43,.4);
  background: rgba(224,33,43,.1);
  color: var(--imposter-light);
  font-size: 11px;
  letter-spacing: .15em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 999px;
}
.hero h1, 
.hero .g-title {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin: 14px 0 8px;
}
.accent-red { color: var(--imposter-light); }
.accent-teal { color: var(--civilian-light); }
.hero .sub { color: rgba(var(--parchment-rgb),.65); font-size: 15px; line-height: 1.5; margin: 0 auto; max-width: 380px; }

/* ---------- Cards ---------- */
.card {
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: rgba(var(--parchment-rgb),.55); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--ink-700);
  font-size: 15px;
}
.row:last-child { border-bottom: none; }
.row select {
  background: var(--ink-700);
  color: var(--parchment);
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}
.row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--civilian); }

/* ---------- Player list ---------- */
#player-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.player-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink-700);
  border-radius: 10px;
  padding: 10px 12px;
}
.player-chip .name { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.player-chip .dot { width: 10px; height: 10px; border-radius: 50%; }
.player-chip button {
  background: none;
  border: none;
  color: rgba(var(--parchment-rgb),.4);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.player-chip button:hover { color: var(--imposter-light); }

#add-player-form { display: flex; gap: 8px; }
#add-player-form input {
  flex: 1;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--parchment);
  font-size: 15px;
}
#add-player-form input:focus { outline: none; border-color: var(--civilian); }

.hint { color: rgba(var(--parchment-rgb),.45); font-size: 13px; margin: 8px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, opacity .2s ease;
  font-size: 15px;
}
.btn:active { transform: scale(.96); }
.btn.small { padding: 10px 16px; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; margin-top: 8px; }
.btn.primary { background: var(--civilian); color: white; box-shadow: 0 8px 24px rgba(18,184,134,.3); }
.btn.primary:hover { background: var(--civilian-light); }
.btn.ghost { background: transparent; border: 1px solid rgba(var(--parchment-rgb),.25); color: var(--parchment); }
.btn.ghost:hover { background: rgba(var(--parchment-rgb),.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- Pass screen ---------- */
.pass-card { text-align: center; padding: 60px 0 20px; }
.pass-label { color: rgba(var(--parchment-rgb),.5); text-transform: uppercase; letter-spacing: .1em; font-size: 12px; }
.pass-card h2 { font-size: 2rem; margin: 6px 0 20px; }
.pass-avatar { font-size: 64px; margin-bottom: 30px; }

/* ---------- Reveal screen ---------- */
.reveal-card {
  border-radius: 20px;
  padding: 60px 24px;
  text-align: center;
  margin: 30px 0;
  transition: background .3s ease;
}
.reveal-card.civilian { background: radial-gradient(circle at center, rgba(18,184,134,.18), transparent 70%); border: 1px solid rgba(18,184,134,.4); }
.reveal-card.imposter { background: radial-gradient(circle at center, rgba(224,33,43,.22), transparent 70%); border: 1px solid rgba(224,33,43,.5); animation: shake .5s; }
.reveal-card.blank { background: radial-gradient(circle at center, rgba(var(--parchment-rgb),.12), transparent 70%); border: 1px solid rgba(var(--parchment-rgb),.3); }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.reveal-role { letter-spacing: .1em; font-size: 13px; text-transform: uppercase; color: rgba(var(--parchment-rgb),.6); margin: 0 0 14px; }
.reveal-word { font-size: 2.6rem; font-weight: 900; word-break: break-word; }
.reveal-card.imposter .reveal-word { color: var(--imposter-light); }
.reveal-card.civilian .reveal-word { color: var(--civilian-light); }
.reveal-hint { margin-top: 14px; color: rgba(var(--parchment-rgb),.6); font-size: 14px; }

/* ---------- Clue round ---------- */
.round-banner { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.round-banner span:first-child { color: rgba(var(--parchment-rgb),.5); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.timer {
  font-family: "SFMono-Regular", Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--civilian-light);
}
.timer.urgent { color: var(--imposter-light); }

#clue-form, #online-clue-form { display: flex; gap: 8px; margin: 16px 0; }
#clue-input, #online-clue-input {
  flex: 1;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px;
  color: var(--parchment);
  font-size: 15px;
  min-width: 0;
}
#clue-input:focus, #online-clue-input:focus { outline: none; border-color: var(--civilian); }
.clue-submit-btn {
  padding: 0 22px;
  white-space: nowrap;
  flex-shrink: 0;
}
@media (max-width: 420px) {
  #clue-form, #online-clue-form { flex-wrap: wrap; }
  #clue-input, #online-clue-input { flex-basis: 100%; }
  .clue-submit-btn { flex: 1; padding: 12px 22px; }
}

.clue-board { display: flex; flex-direction: column; gap: 8px; }
.clue-entry {
  display: flex;
  justify-content: space-between;
  background: var(--ink-800);
  border: 1px solid var(--ink-700);
  border-radius: 10px;
  padding: 12px 14px;
}
.clue-entry .who { color: rgba(var(--parchment-rgb),.5); font-size: 13px; }
.clue-entry .what { font-weight: 700; }

/* ---------- Voting ---------- */
.vote-options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.vote-option {
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--parchment);
}
.vote-option:hover { border-color: var(--imposter); }
.vote-option:active { transform: scale(.97); }

/* ---------- Result ---------- */
.result-card { text-align: center; padding: 60px 20px 20px; }
.result-card h1, 
.result-card .g-title { font-size: 2.6rem; font-weight: 900; margin-bottom: 12px; }
.result-card.civilian h1, 
.result-card.civilian .g-title { color: var(--civilian-light); }
.result-card.imposter h1, 
.result-card.imposter .g-title { color: var(--imposter-light); }
#result-sub { font-size: 16px; color: rgba(var(--parchment-rgb),.75); margin-bottom: 6px; }
#result-word { font-size: 14px; color: rgba(var(--parchment-rgb),.5); }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }

/* ---------- Confetti canvas ---------- */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

.hero.small { margin-bottom: 16px; }
.hero.small h1, 
.hero.small .g-title { font-size: 1.6rem; margin: 0; }

.back-btn { margin-bottom: 14px; }

.mode-card { text-align: left; cursor: pointer; transition: border-color .15s ease, transform .1s ease; }
.mode-card:hover { border-color: var(--civilian); }
.mode-card:active { transform: scale(.98); }
.mode-card h2 { text-transform: none; letter-spacing: 0; font-size: 18px; color: var(--parchment); margin-bottom: 6px; }
.mode-card .btn { margin-top: 12px; pointer-events: none; }

.stepper { display: flex; align-items: center; gap: 12px; }
.stepper .btn.small { padding: 6px 14px; font-size: 18px; line-height: 1; }
.stepper span { font-weight: 700; font-size: 18px; min-width: 20px; text-align: center; }

.player-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink-700);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.player-edit-row .avatar { font-size: 20px; }
.player-edit-row input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--parchment);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 4px;
  border-bottom: 1px solid transparent;
}
.player-edit-row input:focus { outline: none; border-bottom-color: var(--civilian); }

.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1;
  background: var(--ink-700);
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--parchment);
  font-size: 13px;
  font-family: monospace;
}

.small-card { padding: 12px 16px; margin-bottom: 18px; font-size: 14px; }
.small-card .sc-role { color: rgba(var(--parchment-rgb),.5); text-transform: uppercase; font-size: 11px; letter-spacing: .08em; }
.small-card .sc-word { font-weight: 800; font-size: 18px; margin-top: 2px; }
.small-card.civilian .sc-word { color: var(--civilian-light); }
.small-card.imposter .sc-word { color: var(--imposter-light); }
.small-card.blank .sc-word { color: rgba(var(--parchment-rgb),.8); }

.phase-block { margin-top: 8px; }

#app input[type="text"]:not(.player-edit-row input) {
  width: 100%;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px;
  color: var(--parchment);
  font-size: 15px;
  margin-bottom: 8px;
}
#app input[type="text"]:focus { outline: none; border-color: var(--civilian); }


#app textarea {
  width: 100%;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px;
  color: var(--parchment);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
#app textarea:focus { outline: none; border-color: var(--civilian); }

#guess-word-block, #online-guess-word-block { margin: 10px 0 16px; }
#guess-word-form, #online-guess-word-form { display: flex; gap: 8px; }
#guess-word-input, #online-guess-word-input {
  flex: 1;
  min-width: 0;
  background: var(--ink-700);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px;
  color: var(--parchment);
  font-size: 15px;
}
#guess-word-input:focus, #online-guess-word-input:focus { outline: none; border-color: var(--imposter); }
#guess-word-form .btn.ghost, #online-guess-word-form .btn.ghost {
  padding: 0 20px;
  white-space: nowrap;
  flex-shrink: 0;
  border-color: rgba(224, 33, 43, .5);
}

.reveal-details {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(var(--parchment-rgb),.15);
  text-align: left;
  font-size: 14px;
  line-height: 1.6;
}
.reveal-details strong { color: var(--parchment); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.word-image {
  display: block;
  max-width: 100%;
  max-height: 220px;
  width: auto;
  margin: 14px auto 0;
  border-radius: 14px;
  object-fit: cover;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

.scoreboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}
.scoreboard-row .rank { width: 28px; font-weight: 700; color: rgba(var(--parchment-rgb),.5); }
.scoreboard-row .name { flex: 1; font-weight: 600; }
.scoreboard-row .pts { font-weight: 800; color: var(--civilian-light); }
.scoreboard h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(var(--parchment-rgb),.55);
}

/* ---------- Drawing pad ---------- */
.drawing-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.color-swatches { display: flex; gap: 8px; }
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-swatch.active { border-color: var(--parchment); }
.drawing-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 480 / 280;
  background: #fff;
  border-radius: 14px;
  touch-action: none;
  cursor: crosshair;
  margin-bottom: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.clue-drawing-thumb {
  max-width: 160px;
  max-height: 100px;
  border-radius: 8px;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.clue-entry.has-drawing { align-items: center; }

/* ---------- Leave button + toasts ---------- */
#leave-game-btn {
  position: fixed; left: 16px; top: 16px; z-index: 500;
  background: var(--ink-800); color: var(--parchment);
  border: 1px solid var(--ink-700); border-radius: 10px;
  padding: 8px 14px; font-size: 13.5px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
#leave-game-btn:hover { background: var(--ink-700); }

#leave-toast-stack {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 600; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
  width: calc(100% - 32px); max-width: 420px;
}
.leave-toast {
  background: var(--ink-800); color: var(--parchment);
  border: 1px solid var(--ink-700); border-left: 4px solid var(--civilian);
  border-radius: 10px; padding: 10px 16px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  animation: toast-in .2s ease-out;
  text-align: center;
}
.leave-toast.stopped { border-left-color: var(--imposter); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }


#chat-widget { position: fixed; right: 16px; bottom: 16px; z-index: 500; }
.chat-fab {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 22px;
  background: var(--civilian); color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  position: relative;
}
.chat-fab.inviting { animation: chat-bounce 1.1s ease-in-out infinite; }
@keyframes chat-bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-10px); }
  50% { transform: translateY(0); }
  65% { transform: translateY(-4px); }
  80% { transform: translateY(0); }
}
#chat-fab-label {
  display: none;
  position: absolute;
  right: 60px;
  bottom: 12px;
  white-space: nowrap;
  background: var(--civilian);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(0,0,0,.3);
  animation: chat-bounce 1.1s ease-in-out infinite;
}
#chat-fab-label.visible { display: block; }
#chat-fab-label::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 5px 0 5px 6px;
  border-style: solid;
  border-color: transparent transparent transparent var(--civilian);
}
@media (prefers-reduced-motion: reduce) {
  .chat-fab.inviting, #chat-fab-label { animation: none; }
}
.chat-badge {
  position: absolute; top: 2px; right: 4px; color: #ff5c5c; font-size: 22px; line-height: 1;
}
.chat-panel {
  display: none;
  flex-direction: column;
  position: absolute; right: 0; bottom: 64px;
  width: 300px; max-width: calc(100vw - 32px);
  height: 380px; max-height: 60vh;
  background: var(--ink-800); color: var(--parchment);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 10px 32px rgba(0,0,0,.45);
  border: 1px solid var(--ink-700);
}
#chat-panel.open { display: flex; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; font-weight: 600; font-size: 14px;
  color: var(--parchment);
  border-bottom: 1px solid var(--ink-700);
}
.chat-close { background: none; border: none; color: var(--parchment); font-size: 16px; cursor: pointer; opacity: .7; }
.chat-messages { flex: 1; overflow-y: auto; padding: 10px 12px; font-size: 13.5px; color: var(--parchment); }
.chat-msg { margin-bottom: 8px; line-height: 1.35; }
.chat-msg .chat-name { font-weight: 600; opacity: .85; }
.chat-msg.me .chat-name { color: var(--civilian); }
.chat-locked-note { text-align: center; padding: 10px 12px; margin: 0; font-size: 12.5px; color: rgba(var(--parchment-rgb),.75); }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--ink-700); }
.chat-form input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid rgba(var(--parchment-rgb),.2); background: var(--ink-900); color: var(--parchment);
}

