:root {
  --ink: #13151f;
  --paper: #fff9ed;
  --muted: #657087;
  --line: #e3dacb;
  --primary: #16223d;
  --cream: #fff3d5;
  --red: #e54842;
  --blue: #2775d1;
  --green: #1e9b68;
  --yellow: #f2bd2a;
  --black: #1b1d24;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(22, 34, 61, 0.88), rgba(22, 34, 61, 0.16)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.12) 0 2px, transparent 2px 18px),
    #f0483e;
  padding: 18px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  color: white;
  background: var(--primary);
  padding: 13px 16px;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.secondary {
  color: var(--primary);
  background: #ece5d9;
}

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

button.danger {
  background: var(--red);
}

button.icon-button {
  width: 48px;
  padding: 0;
}

button.hidden,
.hidden {
  display: none !important;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffcf5;
  color: var(--ink);
}

label {
  display: grid;
  gap: 7px;
  color: #35415a;
  font-size: 0.9rem;
  font-weight: 700;
}

.lucide {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  stroke-width: 2.4;
}

.label-title,
.kicker,
.backend-box summary,
.qr-card span,
.team-picker p {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.app-shell {
  width: min(880px, 100%);
  margin: 0 auto;
}

.setup-view,
.lobby-screen,
.game-view {
  display: grid;
  gap: 16px;
}

.brand-block {
  min-height: 145px;
  display: grid;
  align-content: end;
  color: white;
}

.kicker {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1;
}

h1 {
  font-size: clamp(3rem, 10vw, 5.8rem);
  letter-spacing: 0;
}

h2 {
  font-size: 2rem;
}

.subtitle {
  width: min(460px, 100%);
  margin: 10px 0 0;
  font-size: 1.05rem;
  color: #fff2dc;
}

.privacy-note {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,249,237,0.5);
  border-radius: 50%;
  background: rgba(19,21,31,0.54);
  color: #fff7e8;
  box-shadow: 0 10px 30px rgba(18, 21, 31, 0.22);
  backdrop-filter: blur(7px);
}

.privacy-note:hover,
.privacy-note:focus-visible,
.privacy-note.is-open {
  background: rgba(19,21,31,0.82);
  outline: 2px solid rgba(255,249,237,0.62);
  outline-offset: 3px;
}

.privacy-text {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: min(320px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid rgba(255,249,237,0.44);
  border-radius: 12px;
  background: rgba(19,21,31,0.92);
  color: #fff7e8;
  font-size: 0.83rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.privacy-note.is-open .privacy-text {
  opacity: 1;
  transform: translateY(0);
}

.info-dot {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 1000;
  line-height: 1;
}

.setup-card,
.lobby-card,
.table-band,
.question-stage,
.manual-panel,
.result {
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 18px 50px rgba(18, 21, 31, 0.22);
}

.setup-card {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.lobby-card {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.field-grid,
.team-row,
.button-row,
.game-header {
  display: grid;
  gap: 10px;
}

.join-lobby-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid rgba(39,117,209,0.22);
  border-radius: 8px;
  background: linear-gradient(110deg, rgba(39,117,209,0.12), rgba(255,253,250,0.86));
}

.join-lobby-box button {
  min-width: 144px;
}

.team-row {
  grid-template-columns: 1fr 48px;
  align-items: center;
}

.backend-box {
  padding: 12px;
  border: 1px dashed #c8c2b8;
  border-radius: 8px;
  background: #e9e4dc;
  opacity: 0.82;
}

.backend-box summary {
  cursor: pointer;
  font-weight: 900;
  color: #656b76;
}

.backend-unavailable {
  margin: 8px 0 12px;
  color: #656b76;
  font-weight: 800;
}

.backend-box input:disabled {
  background: #d7d2ca;
  border-color: #bbb4aa;
  color: #777;
  cursor: not-allowed;
}

.invite-box {
  display: grid;
  gap: 16px;
  align-items: center;
  justify-items: stretch;
}

.qr-card {
  width: 178px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  padding: 10px;
  display: grid;
  justify-items: center;
  gap: 7px;
}

.qr-card.raw-qr {
  width: 100%;
  min-height: 310px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 12px 0 0;
  box-shadow: none;
  align-content: center;
}

.qr-card canvas {
  width: 152px;
  height: 152px;
}

.qr-card span {
  color: #35415a;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.lobby-status {
  margin: 0;
  color: #35415a;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 9px;
}

.lobby-status.loading::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 3px solid rgba(22, 34, 61, 0.18);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

body.guest-lobby .lobby-grid {
  grid-template-columns: 1fr;
}

.lobby-players {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lobby-players span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdfa;
  padding: 8px 12px 8px 10px;
  color: #28364e;
  font-weight: 900;
  display: inline-grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 1px 7px;
}

.lobby-players .lucide {
  grid-row: span 2;
  color: var(--red);
}

.lobby-players span.unassigned {
  border-color: var(--red);
}

.lobby-players span.self {
  border-color: var(--green);
  background:
    linear-gradient(110deg, rgba(30,155,104,0.2), rgba(255,253,250,0.96) 58%),
    #fffdfa;
  box-shadow: 0 0 0 0 rgba(30,155,104,0.28);
  animation: self-pill-fade 2.6s ease-in-out infinite;
}

.lobby-players span.self .lucide {
  color: var(--green);
}

@keyframes self-pill-fade {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(30,155,104,0.28);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(30,155,104,0.12);
  }
}

.lobby-players small {
  color: var(--muted);
  font-size: 0.72rem;
}

.lobby-name-field {
  padding: 10px;
  border: 1px solid rgba(30,155,104,0.24);
  border-radius: 8px;
  background: linear-gradient(110deg, rgba(30,155,104,0.14), rgba(255,253,250,0.86));
}

.team-picker {
  display: grid;
  gap: 8px;
}

.team-picker p {
  margin: 0;
  color: #35415a;
  font-weight: 900;
}

.team-choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
}

.team-choice {
  color: var(--primary);
  background: #fffdfa;
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px;
  text-align: left;
  align-items: center;
  justify-content: stretch;
}

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

.team-choice span {
  grid-column: 2;
  font-size: 0.8rem;
  font-weight: 700;
  opacity: 0.82;
}

.team-choice .lucide {
  grid-row: span 2;
}

.teams-list {
  display: grid;
  gap: 10px;
}

.game-header {
  grid-template-columns: 1fr auto;
  align-items: end;
  color: white;
  min-height: 96px;
}

.phase-pill {
  min-width: 92px;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.45);
  border-radius: 999px;
  padding: 9px 12px;
  font-weight: 900;
  text-transform: capitalize;
  background: rgba(255,255,255,0.12);
}

.music-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 40;
  min-height: 42px;
  padding: 9px 12px;
  color: var(--primary);
  background: rgba(255,249,237,0.92);
  white-space: nowrap;
  box-shadow: 0 12px 30px rgba(18, 21, 31, 0.22);
}

.table-band {
  padding: 12px;
}

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

.score-line {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  background: #fffdfa;
}

.score-line.active {
  border-color: var(--red);
  box-shadow: inset 0 -4px 0 var(--red);
}

.score-line span {
  grid-row: span 2;
  grid-column: 3;
  font-size: 1.45rem;
  font-weight: 900;
}

.score-line .lucide {
  grid-row: span 2;
  color: var(--red);
}

.score-line small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.question-stage {
  min-height: 188px;
  padding: 18px;
  display: grid;
  grid-template-columns: 1fr 96px;
  align-items: center;
  gap: 14px;
}

.question {
  margin: 0;
  font-size: clamp(1.8rem, 7vw, 3.3rem);
  line-height: 1.04;
  font-weight: 900;
}

.timer {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  margin: 0;
  font-weight: 900;
  font-size: 1.35rem;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.color-tile {
  min-height: 76px;
  display: grid;
  place-items: center;
  gap: 6px;
  text-transform: capitalize;
}

.color-tile span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.42);
}

.color-tile.red { background: var(--red); }
.color-tile.blue { background: var(--blue); }
.color-tile.green { background: var(--green); }
.color-tile.yellow { background: var(--yellow); color: var(--ink); }
.color-tile.black { background: var(--black); }

.button-stack {
  display: grid;
  gap: 10px;
}

.status,
.transcript {
  min-height: 24px;
  margin: 0;
  color: white;
  font-weight: 800;
}

.status.waiting {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.status.waiting::before {
  content: "";
  width: 19px;
  height: 19px;
  border: 3px solid rgba(255,255,255,0.24);
  border-top-color: #fff9ed;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.transcript {
  font-weight: 600;
  color: #fff1d5;
  border: 0;
  resize: none;
  background: transparent;
  outline: none;
}

.transcript[readonly] {
  cursor: default;
}

.transcript.editable {
  cursor: text;
}

.manual-panel,
.result {
  padding: 14px;
}

.result {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px;
}

.result .lucide {
  grid-row: span 2;
  color: var(--red);
}

.result strong {
  font-size: 1.3rem;
}

.winner {
  background: var(--cream);
}

@media (min-width: 720px) {
  .field-grid,
  .button-row {
    grid-template-columns: 1fr 1fr;
  }

  .button-row {
    align-items: end;
  }
}

@media (max-width: 620px) {
  body {
    padding: 12px;
  }

  .game-header {
    min-height: 82px;
    grid-template-columns: 1fr auto;
  }

  .music-toggle {
    top: 12px;
    right: 12px;
    width: auto;
  }

  .question-stage {
    grid-template-columns: 1fr;
  }

  .timer {
    width: 84px;
    justify-self: end;
  }

  .color-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .join-lobby-box {
    grid-template-columns: 1fr;
  }

  .invite-box {
    grid-template-columns: 1fr;
  }

  .qr-card {
    width: 100%;
  }
}

.lobby-hero {
  min-height: 150px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 14px;
  color: white;
}

.lobby-hero .kicker {
  color: rgba(255,255,255,0.82);
}

.lobby-hero h2 {
  width: fit-content;
  min-width: 0;
  text-align: left;
  font-size: clamp(3rem, 13vw, 6.5rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.lobby-grid .card {
  height: 100%;
}

#lobbyLinkInput {
  min-height: 62px;
  resize: none;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
  font-size: 0.86rem;
}

.qr-card canvas,
.qr-card .styled-qr,
.qr-card .qr-fallback {
  width: min(292px, 84vw);
  height: min(292px, 84vw);
  max-width: 100%;
  display: block;
  margin: 0 auto;
}

.qr-card .qr-fallback {
  object-fit: contain;
}

.qr-card .styled-qr canvas,
.qr-card .styled-qr svg {
  width: 100% !important;
  height: 100% !important;
  border-radius: 22px;
  display: block;
}

.qr-card canvas[hidden],
.qr-card .styled-qr[hidden],
.qr-card .qr-fallback[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .lobby-hero {
    grid-template-columns: 1fr;
    min-height: 122px;
  }

  .lobby-hero .secondary {
    width: 100%;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(229, 72, 66, 0.88), rgba(22, 34, 61, 0.96)),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.12) 0 2px, transparent 2px 18px);
  color: white;
}

.countdown-overlay span {
  font-size: clamp(8rem, 42vw, 20rem);
  line-height: 0.85;
  font-weight: 950;
  text-shadow: 0 18px 60px rgba(0,0,0,0.32);
}

.countdown-overlay span.countdown-pop {
  animation: countdown-pop 0.72s ease both;
}

@keyframes countdown-pop {
  0% { transform: scale(0.58); opacity: 0; }
  25% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(0.92); opacity: 1; }
}

.mic-stage {
  position: sticky;
  bottom: 18px;
  min-height: 126px;
  display: grid;
  place-items: center;
  z-index: 5;
  pointer-events: none;
}

.mic-pulse {
  position: absolute;
  width: 112px;
  height: 112px;
  border-radius: 999px;
  background: rgba(229, 72, 66, 0.24);
  box-shadow: 0 0 0 18px rgba(229, 72, 66, 0.1);
  transition: transform 90ms linear;
}

.mic-orb {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--red);
  box-shadow: 0 20px 50px rgba(18, 21, 31, 0.28);
}

.mic-orb .lucide {
  width: 34px;
  height: 34px;
}

.mic-stage.listening .mic-orb {
  animation: mic-breathe 1.2s ease-in-out infinite;
}

@keyframes mic-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.transcript.active {
  min-height: 82px;
  border: 1px solid rgba(255,255,255,0.34);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255,249,237,0.94);
  color: var(--primary);
  box-shadow: 0 16px 42px rgba(18, 21, 31, 0.2);
}

.transcript.active::placeholder {
  color: var(--muted);
}

.transcript-list {
  display: grid;
  gap: 10px;
}

.contribution-card {
  border: 1px solid rgba(255,255,255,0.34);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255,249,237,0.95);
  box-shadow: 0 16px 42px rgba(18, 21, 31, 0.2);
}

.contribution-card.other {
  background: rgba(236,229,217,0.9);
  border-color: rgba(22,34,61,0.14);
}

.contribution-card.speaking {
  box-shadow: 0 0 0 3px rgba(229, 72, 66, 0.22), 0 16px 42px rgba(18, 21, 31, 0.2);
}

.contribution-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--primary);
  font-weight: 900;
}

.contribution-head span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.contribution-head small {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.contribution-input {
  min-height: 72px;
  border-color: rgba(22,34,61,0.12);
  background: #fffdfa;
  color: var(--primary);
  resize: vertical;
}

.contribution-card.other .contribution-input {
  background: #e7e1d7;
  color: #5b6578;
}

.contribution-input[readonly] {
  cursor: default;
}

.contribution-input.editable {
  cursor: text;
  border-color: var(--red);
  background: #fffdfa;
}

.game-view.recording-focus {
  min-height: calc(100vh - 36px);
  align-content: center;
  gap: 18px;
}

.game-view.recording-focus .game-header,
.game-view.recording-focus .table-band,
.game-view.recording-focus .color-grid,
.game-view.recording-focus #actions,
.game-view.recording-focus .status,
.game-view.recording-focus .manual-panel,
.game-view.recording-focus .result {
  display: none !important;
}

.game-view.recording-focus .question-stage {
  min-height: auto;
  grid-template-columns: minmax(0, 1fr) 108px;
  padding: 22px;
  text-align: center;
}

.game-view.recording-focus .timer {
  display: grid;
  width: 108px;
  justify-self: center;
  box-shadow: 0 16px 42px rgba(18, 21, 31, 0.24);
}

.game-view.recording-focus .question {
  font-size: clamp(2.3rem, 10vw, 5rem);
}

.game-view.recording-focus .mic-stage {
  position: relative;
  bottom: auto;
  min-height: 150px;
}

.game-view.recording-focus .end-round-btn:not(.hidden) {
  display: inline-flex;
  justify-self: center;
  width: min(320px, 100%);
}

.game-view.recording-focus .transcript.active {
  min-height: 152px;
  font-size: clamp(1.1rem, 4.5vw, 1.75rem);
  line-height: 1.25;
}

.game-view.recording-focus .transcript-list {
  width: 100%;
}

.game-view.recording-focus .transcript-list:not(.hidden) {
  display: grid !important;
}

.game-view.recording-focus .contribution-input {
  min-height: 104px;
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  line-height: 1.25;
}

@media (max-width: 620px) {
  .game-view.recording-focus .question-stage {
    grid-template-columns: 1fr;
  }
}

.qr-unavailable {
  width: 292px;
  min-height: 292px;
  display: grid;
  place-items: center;
  padding: 18px;
  border: 2px dashed rgba(19,21,31,0.22);
  border-radius: 16px;
  background: rgba(255,249,237,0.78);
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}
