:root {
  --ink: #172033;
  --muted: #647086;
  --panel: #ffffff;
  --line: #d8dfeb;
  --primary: #1d6f8f;
  --primary-dark: #124b61;
  --accent: #e3a21a;
  --win: #168a54;
  --soft: #eef8fb;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(29, 111, 143, 0.15), transparent 34%),
    linear-gradient(315deg, rgba(227, 162, 26, 0.16), transparent 38%),
    #f5f8fb;
  font-family: Arial, Helvetica, sans-serif;
}

.game {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.topbar,
.section-heading,
.header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

#contextLabel,
.section-heading p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  color: white;
  background: var(--primary);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

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

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#startButton {
  background: var(--win);
}

#resetButton {
  background: #64748b;
}

.hud {
  display: grid;
  grid-template-areas:
    "phase phase"
    "question timer";
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.meter,
.action-panel,
.players-panel,
.result-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 30px rgba(23, 32, 51, 0.08);
}

.meter {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
}

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

.meter strong {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-phase {
  grid-area: phase;
  grid-column: 1 / -1;
  border-color: var(--primary-dark);
  border-left: 6px solid var(--accent);
  background: linear-gradient(135deg, rgba(18, 75, 97, 0.96), rgba(29, 111, 143, 0.9));
}

.hud > .meter:not(.meter-phase):not(.meter-timer) {
  grid-area: question;
}

.meter-timer {
  grid-area: timer;
}

.meter-phase span {
  color: #f8d477;
}

.meter-phase strong {
  color: white;
  font-size: 22px;
}

.meter-timer.urgent strong {
  color: #b4232a;
}

.table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 14px;
  align-items: start;
}

.table.solo {
  grid-template-columns: 1fr;
}

.action-panel,
.players-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.actions,
.setup-form,
.question-row,
.choice-fields,
.setup-actions {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.setup-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.setup-global label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.setup-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.question-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.question-row-head,
.choice-field-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.question-row-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  background: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.question-summary {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-toggle {
  flex: 0 0 auto;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: white;
  font: inherit;
}

.choice-field-row input {
  flex: 1 1 0;
}

.choice-field-row button,
.remove-question-button {
  flex: 0 0 auto;
  min-width: 38px;
  background: #b4232a;
}

.panel-button {
  color: var(--primary);
  background: white;
  border: 1px solid var(--primary);
}

.text-link {
  justify-self: start;
  min-height: 28px;
  padding: 0;
  color: var(--primary);
  background: transparent;
  font-size: 13px;
  text-align: left;
}

.text-link:hover,
.text-link:focus-visible {
  color: var(--primary-dark);
  text-decoration: underline;
  outline: 0;
}

.add-question-link {
  justify-self: end;
}

.save-setup-button {
  background: var(--win);
}

.game-page-button {
  background: var(--primary-dark);
}

.question-prompt {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 20px;
  font-weight: 900;
  line-height: 1.3;
}

.game-title {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.2;
}

.choice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  color: var(--ink);
  background: var(--soft);
  text-align: left;
}

.choice.selected {
  color: white;
  background: var(--primary);
}

.choice span {
  color: inherit;
  font-size: 13px;
  opacity: 0.78;
}

.notice,
.reveal-choice {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  line-height: 1.45;
}

.reveal-choice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.reveal-choice.majority {
  border-left: 6px solid var(--win);
  background: #f0fdf4;
}

.players {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 7px;
}

.player,
.final-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
}

.player.answered {
  border-left-color: var(--win);
}

.player.eliminated {
  color: #8b96a8;
  background: #eef2f7;
  border-left-color: #b4232a;
}

.player.eliminated strong {
  text-decoration: line-through;
}

.player.current {
  border-color: var(--accent);
  background: #fff8df;
}

.player strong,
.final-item strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player span,
.final-item span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.48);
}

.result-box {
  display: grid;
  gap: 14px;
  width: min(92vw, 560px);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  border: 2px solid var(--accent);
}

.rank-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

.rank-dialog .result-box {
  margin: auto;
  width: min(92vw, 440px);
  border-color: var(--primary);
}

.rank-dialog #resultMessage {
  font-size: clamp(26px, 5vmin, 38px);
}

#resultMessage {
  font-size: clamp(30px, 7vmin, 52px);
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
}

.final-list {
  display: grid;
  gap: 8px;
}

.top-rank-list {
  display: grid;
  gap: 12px;
}

.top-rank-list > strong {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.top-rank-list ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.top-rank-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 8px 18px rgba(30, 41, 59, 0.08);
  animation: rank-pop 220ms ease both;
  animation-delay: calc((var(--rank-order, 1) - 1) * 45ms);
}

.top-rank-item.rank-1 {
  --rank-order: 1;
  border-color: var(--accent);
  background: #fff8df;
}

.top-rank-item.rank-2 {
  --rank-order: 2;
}

.top-rank-item.rank-3 {
  --rank-order: 3;
}

.top-rank-item.rank-4 {
  --rank-order: 4;
}

.top-rank-item.rank-5 {
  --rank-order: 5;
}

.rank-badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: white;
  background: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@keyframes rank-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions button {
  flex: 1;
}

.result-actions .secondary {
  background: #64748b;
}

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

@media (max-width: 620px) {
  .game {
    padding: 10px 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 24px;
  }
}
