:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --ink: #17202a;
  --muted: #637083;
  --line: #d7dee7;
  --accent: #0f766e;
  --accent-2: #b42318;
  --good: #0f766e;
  --wolf: #a61b1b;
  --warn: #9a6700;
  --shadow: 0 16px 48px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

.startup-error {
  max-width: 560px;
  margin: 15vh auto;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.startup-error p {
  margin: 12px 0 18px;
  color: var(--muted);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #aab5c4;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 32px);
  background: rgba(244, 246, 248, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.05;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 24px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 32px) 32px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.setup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: min(320px, 100%);
}

.icon-button {
  width: 44px;
  min-width: 44px;
  border-radius: 50%;
  font-weight: 800;
}

.icon-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.room-panel,
.player-panel,
.voice-device-panel,
.privacy-monitor-panel,
.all-players-panel,
.day-panel,
.log-panel {
  grid-column: 2;
}

.setup-panel,
.game-panel {
  grid-column: 1;
}

.room-share {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
  align-items: end;
}

.room-share label {
  color: var(--muted);
  font-size: 13px;
}

.online-status {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.online-status.connected {
  color: var(--accent);
}

.online-status.error {
  color: var(--accent-2);
}

.seat-join-links {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.seat-join-links button {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 700;
}

.seat-join-links button.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.qr-card {
  display: grid;
  place-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 8px;
  text-align: center;
}

.qr-card p {
  color: var(--muted);
  font-size: 13px;
}

body.seat-client-mode .layout {
  display: block;
  max-width: 640px;
  margin: 0 auto;
}

body.seat-client-mode .topbar {
  position: static;
}

body.seat-client-mode .room-panel,
body.seat-client-mode .setup-panel,
body.seat-client-mode .game-panel,
body.seat-client-mode .voice-device-panel,
body.seat-client-mode .privacy-monitor-panel,
body.seat-client-mode .all-players-panel,
body.seat-client-mode .day-panel,
body.seat-client-mode .log-panel {
  display: none;
}

body.lobby-client-mode .layout {
  display: block;
  max-width: 640px;
  margin: 0 auto;
}

body.lobby-client-mode .room-panel,
body.lobby-client-mode .setup-panel,
body.lobby-client-mode .game-panel,
body.lobby-client-mode .voice-device-panel,
body.lobby-client-mode .privacy-monitor-panel,
body.lobby-client-mode .all-players-panel,
body.lobby-client-mode .day-panel,
body.lobby-client-mode .log-panel {
  display: none;
}

body.host-seat-client-mode .player-panel {
  display: none;
}

body.host-seat-client-mode .voice-device-panel {
  display: block;
}

body.seat-client-mode .player-panel {
  display: block;
  margin-bottom: 16px;
}

body.seat-client-mode .viewer-tools select {
  opacity: 0.72;
}

body.host-seat-client-mode .player-panel {
  display: none;
}

body.host-seat-client-mode .voice-device-panel {
  display: block;
  margin-bottom: 16px;
}

.lobby-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.lobby-seat-button {
  min-height: 54px;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.lobby-seat-button.taken {
  background: var(--surface-2);
  color: var(--muted);
}

.seat-status-line {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.seat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.seat-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.seat-title {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
}

.role-badge {
  color: #fff;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 12px;
}

.role-badge.good {
  background: var(--good);
}

.role-badge.wolf {
  background: var(--wolf);
}

.alive-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.alive-toggle input {
  width: auto;
  min-height: auto;
}

.viewer-tools {
  display: grid;
  gap: 8px;
  min-width: 180px;
}

.phase-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
}

.phase-card .eyebrow,
.phase-card p {
  color: #cbd5e1;
}

.phase-meter {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.timer {
  width: 92px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  text-align: center;
  font-size: 28px;
  font-weight: 900;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 999px;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: #2dd4bf;
  transition: width 0.25s ease;
}

.phase-controls {
  display: grid;
  gap: 10px;
}

.choice-grid,
.host-actions,
.vote-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.choice-grid button.selected,
.vote-grid button.selected {
  border-color: var(--accent);
  background: #ccfbf1;
}

.host-actions {
  margin-top: 12px;
}

.private-view {
  min-height: 170px;
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 8px;
}

.private-view .secret {
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
}

.secret-result {
  padding: 12px;
  border-radius: 8px;
  background: #fef7c3;
  border: 1px solid #f7d95c;
  color: #713f12;
  font-weight: 900;
}

.all-private-views {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mini-private-card {
  display: grid;
  gap: 8px;
  min-height: 150px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}

.mini-private-card .choice-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mini-private-card button,
.mini-private-card select {
  min-height: 34px;
  font-size: 12px;
}

.mini-private-head {
  display: grid;
  gap: 2px;
}

.mini-private-head span,
.mini-private-card p {
  color: var(--muted);
}

.mini-private-card .secret {
  padding: 8px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  font-weight: 800;
}

.mini-private-card.dead-player {
  opacity: 0.55;
}

.split-phone {
  display: grid;
  gap: 10px;
  padding: 10px;
  background: #111827;
  border-radius: 8px;
}

.split-half {
  display: grid;
  gap: 8px;
  min-height: 180px;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
}

.split-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-view {
  min-height: 120px;
  padding: 10px;
}

.public-host {
  background: #f8fafc;
}

.public-host-view {
  display: grid;
  gap: 10px;
}

.public-host-section {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.public-host-section h4 {
  font-size: 14px;
}

.public-host-section p {
  font-size: 13px;
}

.public-host-button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.public-host-button-grid button {
  min-height: 38px;
}

.public-host-button-grid .primary-button {
  width: 100%;
}

.public-host-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.public-host-row span,
.public-host-view p {
  color: var(--muted);
}

.privacy-monitor {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #1f2937;
  color: #fff;
  border-radius: 8px;
}

.monitor-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.monitor-row span {
  color: #cbd5e1;
  font-size: 13px;
}

.monitor-row strong {
  font-size: 13px;
}

.privacy-monitor p {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.45;
}

.day-board {
  display: grid;
  gap: 12px;
}

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

.day-status-grid span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.sheriff-flow {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.sheriff-flow h3 {
  font-size: 18px;
}

.sheriff-flow p {
  color: var(--muted);
  font-size: 14px;
}

.speech-order {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.speaker-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 700;
}

.speaker-chip.current-speaker {
  border-color: var(--accent);
  background: #ccfbf1;
  color: #115e59;
}

.sheriff-votes {
  padding-top: 4px;
}

.day-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.day-row label {
  color: var(--muted);
  font-size: 13px;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-left: 22px;
}

.log-list li {
  color: var(--muted);
  line-height: 1.45;
}

.result-banner {
  padding: 12px;
  border-radius: 8px;
  background: #ecfdf3;
  border: 1px solid #abefc6;
  color: #067647;
  font-weight: 800;
}

.post-game-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #f8fafc;
}

.post-game-panel h4 {
  margin: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.night-timer {
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-weight: 800;
}

.hidden-feedback {
  display: none;
}

.danger-banner {
  background: #fef3f2;
  border-color: #fecdca;
  color: #b42318;
}

.self-destruct-zone {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fef3f2;
}

.self-destruct-zone p {
  margin: 0;
  color: #b42318;
  font-size: 13px;
}

.danger-button {
  border-color: #d92d20;
  background: #d92d20;
  color: #fff;
  font-weight: 800;
}

.danger-button:disabled {
  border-color: #fecdca;
  background: #fff;
  color: #b42318;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .room-panel,
  .player-panel,
  .voice-device-panel,
  .privacy-monitor-panel,
  .all-players-panel,
  .day-panel,
  .log-panel,
  .setup-panel,
  .game-panel {
    grid-column: 1;
  }

  .seat-grid,
  .all-private-views {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .panel-head,
  .phase-meter {
    flex-direction: column;
    align-items: stretch;
  }

  .seat-grid,
  .all-private-views,
  .choice-grid,
  .host-actions,
  .public-host-button-grid,
  .day-status-grid,
  .vote-grid,
  .room-share {
    grid-template-columns: 1fr;
  }

  .timer {
    width: 100%;
  }
}
