:root {
  --bg: #3d348b;
  --bg2: #7678ed;
  --card: #fffaf0;
  --ink: #2b2d42;
  --pink: #ff4d6d;
  --yellow: #f7b801;
  --green: #2a9d8f;
  --red: #d62828;
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Comic Neue", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg), var(--bg2)) fixed;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 14px 48px;
}

h1, h2, h3 { margin: 0 0 10px; line-height: 1.15; }
h1 { color: #fff; text-align: center; font-size: 1.7rem; text-shadow: 2px 2px 0 var(--pink); }
.subtitle { color: #fff; text-align: center; opacity: .9; margin-top: -4px; }

.card {
  background: var(--card);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
}

.loading { color: #fff; text-align: center; margin-top: 40vh; font-size: 1.4rem; }

button, .btn {
  font: inherit;
  font-weight: bold;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  background: var(--yellow);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  margin: 4px 4px 4px 0;
}
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: #fff; }
button.danger { background: var(--pink); color: #fff; }
button.ok { background: #80ed99; }
button.small { padding: 4px 10px; font-size: .9rem; }
button.link { background: none; border: none; box-shadow: none; text-decoration: underline; color: inherit; padding: 4px; }

input, select {
  font: inherit;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  background: #fff;
}
label { display: block; font-weight: bold; margin: 10px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 120px; }

.code-input {
  text-transform: uppercase;
  letter-spacing: .4em;
  text-align: center;
  font-size: 1.8rem;
  font-family: "Courier New", monospace;
  font-weight: bold;
}
.code {
  font-family: "Courier New", monospace;
  font-weight: bold;
  letter-spacing: .25em;
  background: var(--ink);
  color: var(--yellow);
  padding: 2px 8px;
  border-radius: 6px;
}
.code.big { font-size: 2rem; display: inline-block; padding: 6px 14px; }

.error { color: var(--red); font-weight: bold; min-height: 1.2em; }
.muted { opacity: .7; font-size: .92rem; }
.center { text-align: center; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  border: 2px solid var(--ink);
  font-size: 1.1rem;
  flex: none;
}
.badge.big { width: 3.4em; height: 3.4em; font-size: 1.6rem; }

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: .8rem;
  border: 2px solid var(--ink);
  background: #fff;
}
.tag.out { background: #adb5bd; }
.tag.me { background: var(--yellow); }

.players { list-style: none; padding: 0; margin: 0; }
.players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 2px dashed rgba(43,45,66,.2);
}
.players li:last-child { border-bottom: none; }
.players li.eliminated { opacity: .55; }
.players li.selectable { cursor: pointer; border-radius: 12px; }
.players li.selectable:hover { background: #fff1c1; }
.players li.selected { background: #ffe066; }
.players .who { flex: 1; min-width: 0; }
.players .who small { display: block; opacity: .7; }
.cakes { font-weight: bold; white-space: nowrap; }

.tabs { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }
.tabs button { background: #fff; }
.tabs button.active { background: var(--yellow); }

.story img {
  width: 100%;
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  background: #fff;
  display: block;
}
.typewriter {
  min-height: 9.5em;
  font-family: "Courier New", monospace;
  font-size: 1.05rem;
  line-height: 1.45;
  white-space: pre-wrap;
  margin: 12px 0;
}
.typewriter .caret {
  display: inline-block;
  width: .6em;
  background: var(--ink);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.role { text-align: center; }
.role.thief { background: #ffccd5; }
.role.accomplice { background: #e0c3fc; }
.role.detective { background: #caf0f8; }
.role.eliminated { background: #dee2e6; }
.role .emoji { font-size: 3.2rem; }
.role.hidden-role .secret { filter: blur(10px); user-select: none; }

.alert { border-color: var(--pink); background: #fff0f3; }
.win { text-align: center; font-size: 1.2rem; }

.log { list-style: none; padding: 0; margin: 0; max-height: 260px; overflow: auto; font-size: .92rem; }
.log li { padding: 4px 0; border-bottom: 1px dotted rgba(0,0,0,.2); }
.log li.private { color: #6a4c93; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 60, .85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal[hidden] { display: none; }
.modal .card { max-width: 420px; width: 100%; text-align: center; max-height: 95vh; overflow: auto; }
.modal canvas { width: 100%; max-width: 320px; height: auto; border-radius: 12px; }
.url { word-break: break-all; font-size: .8rem; }

.mode { color: #fff; text-align: center; font-size: .8rem; opacity: .8; }

.spec { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; background: #111; color: #9fef9f; padding: 10px; border-radius: 8px; overflow: auto; white-space: pre; margin: 6px 0 0; }
#spec-log { max-height: 50vh; }
