:root {
  --bg: #16110c;
  --bg-2: #211910;
  --panel: #2a2016;
  --panel-2: #33281c;
  --line: #4a3b29;
  --text: #f3e9d8;
  --muted: #b8a88f;
  --gold: #ffd04a;
  --gold-dim: #b58f2c;
  --miner: #ffd04a;
  --saboteur: #ff5e5e;
  --good: #7bd66a;
  --bad: #ff6b5b;
  --cell-empty: #1d1610;
  --focus: #ffe38a;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -200px, #3a2a17 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
}

h1, h2, .brand, .turn-number { font-family: "Lilita One", "Nunito", sans-serif; font-weight: 400; letter-spacing: .02em; }

button, input, label { font: inherit; color: inherit; }

.top {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px clamp(16px, 4vw, 32px) 8px;
}
.brand { font-size: 26px; color: var(--gold); text-decoration: none; }
.brand span { color: var(--text); }
.meta { color: var(--muted); font-size: 14px; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "story story" "stage side";
  gap: 16px 24px;
  padding: 8px clamp(16px, 4vw, 32px) 24px;
  max-width: 1280px;
  margin: 0 auto;
}
.app[hidden] { display: none; }

.story { grid-area: story; }
.stage { grid-area: stage; min-width: 0; }
.side { grid-area: side; min-width: 0; }

.headline-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.headline-row h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); color: var(--gold); text-shadow: 0 2px 0 #00000080; }
.result { margin: 4px 0 0; color: var(--muted); }

.tension { display: flex; gap: 3px; align-items: center; }
.tension .pip { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.tension .pip.on { background: var(--saboteur); box-shadow: 0 0 8px #ff5e5e99; }
.tension .label { margin-left: 6px; font-size: 13px; color: var(--muted); }

/* board */
.board-wrap {
  background: linear-gradient(#2b2015, #1f170f);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: clamp(6px, 1.5vw, 14px);
  box-shadow: inset 0 0 40px #00000080;
  overflow: hidden;
}
.board {
  display: grid;
  gap: clamp(1px, .3vw, 3px);
  margin: 0 auto;
  max-width: 100%;
}
.cell {
  position: relative;
  aspect-ratio: 115 / 145;
  border-radius: 6%;
  background: var(--cell-empty);
  overflow: hidden;
}
.cell.crystal::after {
  content: "";
  position: absolute;
  inset: 32% 30%;
  background: radial-gradient(circle at 40% 35%, #c9f3ff, #4fb8e6 60%, #1f6f99);
  clip-path: polygon(50% 0, 100% 40%, 75% 100%, 25% 100%, 0 40%);
  opacity: .9;
}

.card {
  position: absolute;
  inset: 0;
  border-radius: 6%;
  overflow: hidden;
}
.card img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.card .bg.flip-x { transform: scaleX(-1); }
.card .bg.flip-y { transform: scaleY(-1); }
.card .bg.flip-xy { transform: scale(-1, -1); }
.card .fg.rot { transform: rotate(180deg); }
.card .tag {
  position: absolute;
  left: 4%; bottom: 3%;
  font-size: clamp(7px, 1vw, 11px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}
.card.goal-peek::after {
  content: attr(data-peek);
  position: absolute;
  inset: auto 0 0 0;
  padding: 2px 0;
  background: #000a;
  text-align: center;
  font-size: clamp(7px, 1vw, 11px);
  font-weight: 800;
  color: var(--gold);
}

.cell.new .card { animation: drop .45s cubic-bezier(.2, .9, .3, 1.3); }
.cell.new { box-shadow: 0 0 0 2px var(--gold), 0 0 14px #ffd04a99; z-index: 1; }
.cell.flip .card { animation: flip .6s ease-out; }
.cell.boom { animation: boom .5s ease-out; box-shadow: 0 0 0 2px var(--bad), 0 0 18px #ff5e5eaa; z-index: 1; }
.cell.peek { box-shadow: 0 0 0 2px #8fd3ff, 0 0 14px #8fd3ffaa; z-index: 1; }
.cell.win { box-shadow: 0 0 0 2px var(--gold), 0 0 20px var(--gold); }

@keyframes drop { from { transform: translateY(-30%) scale(1.25); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes flip { 0% { transform: rotateY(90deg); } 100% { transform: none; } }
@keyframes boom { 0%, 100% { transform: none; } 25% { transform: translateX(-6%) rotate(-3deg); } 50% { transform: translateX(6%) rotate(3deg); } 75% { transform: translateX(-3%); } }

/* the turn being shown */
.turn-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
  min-height: 62px;
}
.turn-card { position: relative; width: 46px; flex: none; aspect-ratio: 115 / 145; }
.turn-card:empty { visibility: hidden; }
.turn-number { font-size: 15px; color: var(--gold); }
.turn-caption { font-size: 17px; font-weight: 600; }
.turn-caption .who { font-weight: 800; }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.controls button {
  min-width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 18px;
}
.controls button:hover { background: var(--panel-2); }
.controls button:focus-visible, .highlights button:focus-visible, .xray input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.controls .play { background: var(--gold); color: #2a1c05; border-color: var(--gold-dim); min-width: 56px; }
.controls .play:hover { background: #ffdd70; }
.controls .speed { font-size: 15px; font-weight: 800; }
#scrub { flex: 1 1 160px; min-width: 120px; accent-color: var(--gold); height: 44px; }

.chart { margin: 16px 0 0; }
.chart figcaption { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
#chart { width: 100%; height: 120px; display: block; cursor: pointer; }
#chart .area { fill: #ffd04a22; }
#chart .line { fill: none; stroke: var(--gold); stroke-width: 2; vector-effect: non-scaling-stroke; }
#chart .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
#chart .axis { fill: var(--muted); font-size: 10px; }
#chart .now { stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#chart .mark { stroke: #16110c; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
#chart .blocked { fill: #ff5e5e1f; }

/* players */
.side h2 { font-size: 20px; margin: 0 0 8px; color: var(--gold); }
.side-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.xray { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; cursor: pointer; }
.players, .highlights { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 8px; }

.player {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.player.active { border-color: var(--gold); box-shadow: 0 0 12px #ffd04a55; }
.player.winner { background: linear-gradient(90deg, #4a3a12, var(--panel) 70%); }
.player-top { display: flex; align-items: center; gap: 8px; }
.seat {
  flex: none;
  font-weight: 800;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
}
.player-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role { margin-left: auto; font-size: 12px; font-weight: 800; padding: 1px 8px; border-radius: 999px; flex: none; }
.role.miner { background: #ffd04a26; color: var(--miner); }
.role.saboteur { background: #ff5e5e26; color: var(--saboteur); }
/* quick chat, a speech bubble like the game's */
.emote {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  max-width: 45%;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  background: #fff6e0;
  color: #2a1c05;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  animation: pop .3s cubic-bezier(.2, .9, .3, 1.4);
}
.emote-icon {
  width: 14px;
  height: 14px;
  flex: none;
  -webkit-mask: center / contain no-repeat;
  mask: center / contain no-repeat;
}
@keyframes pop { from { transform: scale(0); } to { transform: none; } }
.player-sub { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.tools { display: flex; gap: 4px; }
.tool { font-size: 11px; font-weight: 800; padding: 0 6px; border-radius: 6px; background: #ff5e5e33; color: var(--bad); }
.badge { font-size: 11px; font-weight: 800; padding: 0 6px; border-radius: 6px; background: #ffd04a33; color: var(--gold); }
.gold { margin-left: auto; color: var(--gold); font-weight: 800; }
.hand { display: flex; gap: 3px; margin-top: 6px; }
.hand .mini { position: relative; width: 26px; aspect-ratio: 115 / 145; border-radius: 3px; overflow: hidden; flex: none; }
.hand .mini.played { outline: 2px solid var(--gold); }

/* turning points */
.highlights button {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  align-items: start;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
}
.highlights button:hover { background: var(--panel-2); }
.highlights button.current { border-color: var(--gold); }
.highlights .icon { font-size: 20px; grid-row: span 2; line-height: 1.2; }
.highlights .when { font-size: 12px; color: var(--muted); }
.highlights .what { font-weight: 600; }

.message {
  max-width: 520px;
  margin: 12vh auto;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}
.message[hidden] { display: none; }
.message h1 { color: var(--gold); }
.message a { color: var(--gold); }

.drop {
  border: 2px dashed var(--line);
  border-radius: 16px;
  padding: 28px 16px;
  margin-top: 16px;
}
.drop.over { border-color: var(--gold); background: #ffd04a11; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 24px; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "story" "stage" "side"; }
}

@media (max-width: 480px) {
  .controls button { min-width: 40px; height: 40px; }
  .turn-caption { font-size: 15px; }
  .hand .mini { width: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .cell.new .card, .cell.flip .card, .cell.boom, .emote { animation: none; }
}
