:root {
  color-scheme: dark;
  --bg: #111;
  --panel: #181818;
  --panel-2: #202020;
  --text: #f4f4f4;
  --muted: #a6a6a6;
  --line: #303030;
  --accent: #d33838;
  --blue: #4c8dff;
  --green: #39b46f;
  --bubble: #262626;
  --own: #1f4e3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.shell {
  min-height: 100vh;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto auto auto auto 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.phase {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.05;
}

h2 {
  font-size: 15px;
}

.timer {
  min-width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
}

.media-panel {
  width: 100%;
  aspect-ratio: 16 / 7;
  overflow: hidden;
  border-radius: 8px;
  background: #070707;
}

.phase-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.role-panel,
.players-panel,
.action-panel,
.chat-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.role-panel {
  padding: 10px;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.role-badge.mafia {
  background: #5a1616;
  color: #ffdada;
}

.role-badge.detective {
  background: #17345f;
  color: #d8e7ff;
}

.role-badge.doctor {
  background: #16442b;
  color: #d8ffe8;
}

.role-badge.citizen {
  background: #3a3a3a;
  color: #f0f0f0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 10px 12px 6px;
  color: var(--muted);
}

.players {
  display: grid;
  gap: 6px;
  padding: 0 10px 10px;
}

.player-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px;
  border-radius: 8px;
  background: var(--panel-2);
}

.player-row.dead {
  opacity: 0.35;
}

.player-row.dead .player-name {
  text-decoration: line-through;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #333;
  color: #fff;
  font-weight: 800;
}

.player-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-role {
  color: var(--muted);
  font-size: 12px;
}

.action-panel {
  padding-bottom: 10px;
}

.vote-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 10px;
}

.vote-card {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  display: grid;
  gap: 6px;
  justify-items: center;
  align-content: center;
}

.vote-card:active {
  transform: translateY(1px);
}

.chat-panel {
  min-height: 260px;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.messages {
  padding: 10px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  max-width: 84%;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bubble);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.bubble.own {
  align-self: flex-end;
  background: var(--own);
}

.bubble-name {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #0d0d0d;
}

.chat-form button {
  min-width: 82px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.chat-form.disabled {
  opacity: 0.45;
}

.chat-form.disabled input,
.chat-form.disabled button {
  pointer-events: none;
}

@media (min-width: 760px) {
  .shell {
    max-width: 920px;
    margin: 0 auto;
    grid-template-columns: 1fr 320px;
    grid-template-rows: auto auto auto 1fr;
  }

  .topbar,
  .media-panel,
  .role-panel,
  .chat-panel {
    grid-column: 1;
  }

  .players-panel,
  .action-panel {
    grid-column: 2;
  }

  .players-panel {
    grid-row: 2 / span 2;
  }

  .action-panel {
    grid-row: 4;
    align-self: start;
  }

  .chat-panel {
    min-height: 420px;
  }
}
