/* ============================================================
   Buzzers — shared styles for landing, host, display, player
   ============================================================ */

.error {
  color: #ffb4b4;
  background: rgba(220, 38, 38, 0.15);
  border: 1px solid rgba(220, 38, 38, 0.45);
  border-radius: 8px;
  padding: 8px 12px;
}

/* ---- Landing: ported from wheeloffortune's room-picker / role-grid ---- */

.landing .role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 24px 0;
}
.landing .role-card {
  display: block;
  padding: 24px 18px;
  text-decoration: none;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 0.15s, filter 0.15s;
  text-align: center;
}
.landing .role-card:hover { transform: translateY(-2px); filter: brightness(1.1); }
.landing .role-card p { color: var(--dim); margin: 6px 0 0; font-size: 0.9rem; }
.landing .role-icon {
  width: 56px; height: 56px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #211a04;
  font-size: 1.6rem; font-weight: 700;
  border-radius: 10px;
  margin: 0 auto 12px;
}

.room-picker {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  margin: 24px 0 36px;
  text-align: left;
}
.room-active {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.room-active .label { color: var(--dim); font-size: 0.9rem; }
.room-active code {
  font-size: 1.25rem;
  font-weight: 700;
  padding: 3px 10px;
  background: rgba(255, 255, 255, 0.08);
  letter-spacing: 0.05em;
}
.room-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}
.room-form label {
  flex: 1 1 140px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--dim);
}
.room-form input {
  width: 100%;
  padding: 8px 10px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.room-form > button { flex-shrink: 0; }
@media (max-width: 480px) {
  .room-form { flex-direction: column; align-items: stretch; }
  .room-form > button { width: 100%; }
}
.room-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--dim);
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.room-list {
  list-style: none;
  padding: 4px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.room-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.room-list li.empty { justify-content: center; color: var(--dim); font-style: italic; }
.room-list li.active { outline: 2px solid var(--accent); }
.room-list .room-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.room-list .room-info .code {
  font-weight: 700;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  letter-spacing: 0.05em;
}
.room-list .room-info .meta { color: var(--dim); font-size: 0.8rem; }
button.small { padding: 4px 10px; font-size: 0.8rem; flex-shrink: 0; }
button.ghost.small { background: transparent; color: var(--dim); border: 1px solid var(--border); }

/* ---------- Host page ---------- */

.host-controls .controls { gap: 12px; }
.host-controls button.big { min-width: 140px; }

.phase-tag {
  display: inline-block;
  margin: 10px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}
.phase-tag.phase-armed  { background: rgba(31, 160, 51, 0.25); color: #9df2a7; }
.phase-tag.phase-locked { background: rgba(230, 182, 19, 0.25); color: #fff2a8; }
.phase-tag.phase-idle   { background: rgba(255, 255, 255, 0.08); color: var(--dim); }

.chip {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  margin-right: 8px;
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
  vertical-align: middle;
}

.current-buzz {
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1.4rem;
}
.current-buzz.empty { color: var(--dim); font-style: italic; font-size: 1rem; }

.buzz-order {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.buzz-order li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.buzz-order li.empty { color: var(--dim); font-style: italic; }
.buzz-order .rank {
  display: inline-block;
  min-width: 1.6em;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-weight: 700;
  padding: 0 4px;
}
.buzz-order .who { flex: 1; }

.player-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.player-list li.empty { color: var(--dim); font-style: italic; }
.player-list .who { flex: 1; }
.player-list .tag.out {
  background: rgba(220, 38, 38, 0.25);
  color: #ffb4b4;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.1em;
}
button.ghost.small { padding: 3px 8px; font-size: 0.85rem; }

.share-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 640px) {
  .share-row { grid-template-columns: 1fr; }
}
.share-qr img {
  display: block;
  width: 220px;
  height: 220px;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
}
.share-qr code { word-break: break-all; }

/* ---------- Display page ---------- */

.display-body {
  margin: 0;
  background: #063a6b;
  color: #fff;
  min-height: 100vh;
  overflow: hidden;
}
.display-stage {
  --buzz-color: #fff;
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 24px;
  transition: background-color 0.3s ease;
}
.display-stage.phase-armed  { background: radial-gradient(circle at 50% 40%, #0f6b2a, #053418); }
.display-stage.phase-locked { background: radial-gradient(circle at 50% 40%, var(--buzz-color), #000); }
.display-stage.phase-idle   { background: radial-gradient(circle at 50% 40%, #0b4a86, #031933); }

.display-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.room-chip, .phase-chip {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.9rem;
}
.room-chip strong { font-size: 1.2rem; letter-spacing: 0.2em; }

.display-main {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.display-block h1 {
  font-size: clamp(5rem, 15vw, 14rem);
  margin: 0;
  line-height: 1;
  text-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
}
.display-block p { font-size: clamp(1.2rem, 3vw, 2rem); opacity: 0.85; }
.who-prefix { letter-spacing: 0.25em; opacity: 0.8; font-size: clamp(1rem, 2.5vw, 1.8rem); }

.display-stage.phase-locked .display-block h1 {
  animation: buzzPop 0.6s ease-out;
}
@keyframes buzzPop {
  0% { transform: scale(0.6); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.display-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}
.join-help { display: flex; gap: 12px; align-items: center; }
.small-qr {
  width: 110px;
  height: 110px;
  background: #fff;
  border-radius: 8px;
  padding: 6px;
}
.join-help code { background: rgba(0, 0, 0, 0.35); padding: 2px 6px; border-radius: 4px; }

.display-buzz-order {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.display-buzz-order li {
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
}

/* ---------- Player page ---------- */

.player-body {
  margin: 0;
  background: #063a6b;
  color: #fff;
  overflow: hidden;
  /* dvh keeps the layout from jumping when mobile browser chrome shows/hides */
  height: 100dvh;
  height: 100vh;
}
.player-page {
  max-width: 540px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 10px;
}
.player-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.player-menu-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 1.2rem;
  padding: 0;
}

/* Join step — only visible before the user has tapped Join. */
.player-join-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow-y: auto;
}
.player-join-panel h1 { margin: 0; font-size: 1.4rem; }
.player-join-panel[hidden] { display: none; }
.player-buzz-panel[hidden] { display: none; }
.full { width: 100%; }

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.color-chip {
  aspect-ratio: 1 / 1;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), inset 0 2px 6px rgba(255, 255, 255, 0.35);
}
.color-chip.selected {
  border-color: #ffffff;
  transform: scale(1.05);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.55), inset 0 2px 6px rgba(255, 255, 255, 0.35);
}
.color-chip.taken {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

/* Buzz step — once joined, the button owns the screen. */
.player-buzz-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  flex: 1;
  min-height: 0;
}
.me-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1rem;
  margin: 0;
  flex-shrink: 0;
}
.me-tag .chip { width: 18px; height: 18px; margin: 0; }
.me-tag .me-name { font-weight: 700; }
.me-tag .me-status { color: rgba(255, 255, 255, 0.75); }

.buzz-btn {
  --my-color: #666;
  /* Keep it a perfect circle: one dimension drives, aspect-ratio locks the
     other. Takes the smaller of 85 vw / 70 vh so it fits portrait and
     landscape without becoming an oval. */
  width: min(85vw, 70vh, 560px);
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 50%;
  border: none;
  font-size: clamp(3rem, 16vw, 6rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
  letter-spacing: 0.08em;
  cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #a8a8a8, #4a4a4a 60%, #1a1a1a 100%);
  box-shadow:
    0 14px 30px rgba(0, 0, 0, 0.55),
    inset 0 6px 10px rgba(255, 255, 255, 0.25),
    inset 0 -14px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.2s ease;
  /* Suppress tap-highlight flash and iOS callout. */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
.buzz-btn:disabled { cursor: not-allowed; }
.buzz-btn.armed {
  background: radial-gradient(circle at 35% 30%,
    color-mix(in srgb, var(--my-color) 20%, #ffffff),
    var(--my-color) 55%,
    color-mix(in srgb, var(--my-color) 40%, #000) 100%);
  animation: buzzPulse 1.2s ease-in-out infinite;
}
.buzz-btn.mine {
  background: radial-gradient(circle at 35% 30%, #fff, #eaeaea 55%, #a8a8a8 100%);
  color: #222;
  text-shadow: none;
  animation: none;
}
.buzz-btn.locked:not(.mine):not(:disabled) {
  background: radial-gradient(circle at 35% 30%, #6a6a6a, #3a3a3a 60%, #121212 100%);
}
.buzz-btn:active:not(:disabled) {
  transform: translateY(3px) scale(0.98);
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.55),
    inset 0 6px 10px rgba(255, 255, 255, 0.25),
    inset 0 -8px 20px rgba(0, 0, 0, 0.45);
}
@keyframes buzzPulse {
  0%, 100% { box-shadow: 0 14px 30px rgba(0, 0, 0, 0.55),
    inset 0 6px 10px rgba(255, 255, 255, 0.25),
    inset 0 -14px 24px rgba(0, 0, 0, 0.35),
    0 0 0 0 rgba(255, 255, 255, 0.35); }
  50% { box-shadow: 0 14px 30px rgba(0, 0, 0, 0.55),
    inset 0 6px 10px rgba(255, 255, 255, 0.25),
    inset 0 -14px 24px rgba(0, 0, 0, 0.35),
    0 0 0 18px rgba(255, 255, 255, 0); }
}

/* Settings pop-up invoked from the gear button. `display: flex` overrides
   the browser's default `[hidden] { display: none }`, so we re-assert it. */
.menu-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.menu-sheet[hidden] { display: none; }
.menu-sheet button { padding: 14px 16px; font-size: 1rem; }

/* Match ghost buttons' visibility on the darker player/display bodies. */
.player-body .ghost,
.display-body .ghost { color: rgba(255, 255, 255, 0.85); border-color: rgba(255, 255, 255, 0.25); }

/* ---------- Host mobile sizing ---------- */

@media (max-width: 640px) {
  main.page { padding: 16px 12px 32px; }
  main.page > h1 { font-size: 1.6rem; }
  .host-controls .controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .host-controls .controls > button { width: 100%; min-width: 0; }
  .host-controls .controls > button.primary { grid-column: 1 / -1; }
  .buzz-order li, .player-list li { font-size: 0.95rem; }
  .current-buzz { font-size: 1.2rem; }
  .share-qr img { width: 180px; height: 180px; }
}
