:root {
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --primary: #1d4ed8;
  --danger: #b91c1c;
  --success: #047857;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--ink);
  background: #1e44c7;
}

.shell {
  width: min(1320px, 96vw);
  margin: 14px auto;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.hidden { display: none !important; }

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions.vertical { flex-direction: column; }

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

button:hover { filter: brightness(1.03); }
button:active { transform: translateY(1px) scale(0.98); }

.primary { background: var(--primary); color: #fff; }
.secondary { background: #334155; color: #fff; }
.success { background: var(--success); color: #fff; }
.danger { background: var(--danger); color: #fff; }
.ghost { background: #e5e7eb; color: #111827; }

label { display: block; margin: 10px 0; font-weight: 600; }
input {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

.host-view {
  display: block;
  position: relative;
}

.stage-bg {
  position: relative;
  min-height: 86vh;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background-image: none;
  background-color: #1e44c7;
}

.host-stage {
  width: 100%;
  background-size: 100% 100%;
}

.host-menu-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  display: flex;
  justify-content: center;
}

.host-menu-toggle.is-open {
  background: rgba(29, 78, 216, 0.92);
  border-color: rgba(191, 219, 254, 0.9);
}

.host-menu {
  position: absolute;
  top: 64px;
  right: 14px;
  z-index: 25;
  width: min(290px, 86vw);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  max-height: calc(100vh - 84px);
  overflow: auto;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.host-info-modal {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.host-info-card {
  width: min(440px, 92vw);
  background: #fff;
  color: #111827;
  border-radius: 14px;
  border: 1px solid #d1d5db;
  padding: 16px;
  box-shadow: 0 16px 34px rgba(15, 23, 42, 0.3);
}

.host-info-card h3 {
  margin: 0 0 10px;
}

.host-menu-participants {
  margin-top: 10px;
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
}

.host-menu-participants h4 {
  margin: 0 0 8px;
}

.host-menu-participants ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: none;
  overflow: visible;
  padding-bottom: calc(42px + env(safe-area-inset-bottom));
}

.host-menu-participants li {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.host-top-left {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  width: min(980px, calc(100% - 340px));
  transform: none;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.host-view.question-mode .host-top-left {
  left: 50%;
  top: 22px;
  transform: translateX(-50%);
  width: min(1220px, calc(100% - 72px));
  text-align: center;
  text-shadow: none;
  max-height: none;
  overflow: visible;
  padding-bottom: 0;
}

.host-view.transition-mode .host-top-left {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(1100px, calc(100% - 72px));
  text-align: center;
}

.host-view.transition-mode #host-stage-title {
  margin: 0;
  font-size: clamp(54px, 6vw, 96px);
  line-height: 1.05;
}

.host-view.transition-mode #host-stage-message {
  margin-top: 18px;
  font-size: clamp(26px, 2.8vw, 44px);
  line-height: 1.25;
}

.host-view.transition-mode .highlight {
  display: none;
}

.host-answer-actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  gap: 14px;
}

.host-view .host-answer-actions {
  position: fixed;
  right: 26px;
  bottom: 22px;
  z-index: 60;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  width: min(320px, 30vw);
}

.host-view .host-answer-actions button {
  width: 100%;
}

.host-answer-actions button {
  font-size: clamp(22px, 1.8vw, 30px);
  padding: 14px 26px;
  border-radius: 14px;
  min-width: 220px;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.24);
}

.highlight {
  font-size: 34px;
  font-weight: 800;
  margin: 8px 0;
}

.question-box {
  margin-top: 12px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(241, 245, 249, 0.95));
  color: #111827;
  padding: 26px 28px;
  border-radius: 20px;
  border: 1px solid rgba(191, 219, 254, 0.9);
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.28);
  text-shadow: none;
}

.question-box ol {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

#host-question-prompt {
  margin: 0;
  font-size: clamp(44px, 4.6vw, 76px);
  line-height: 1.18;
  font-weight: 800;
}

#host-question-options,
#guest-question-options {
  margin-top: 14px;
  font-size: clamp(34px, 3vw, 50px);
  line-height: 1.25;
  font-weight: 700;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

#guest-question-options {
  font-size: clamp(20px, 4.4vw, 30px);
}

#host-question-options li,
#guest-question-options li {
  border: 1px solid #bfdbfe;
  background: #ffffff;
  border-radius: 14px;
  padding: 18px 20px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.option-label {
  font-size: 0.72em;
  font-weight: 900;
  color: #1d4ed8;
  align-self: flex-start;
}

.option-image {
  width: min(100%, 300px);
  max-height: 140px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
}

.option-text {
  font-size: 0.84em;
  line-height: 1.2;
  font-weight: 800;
  text-align: center;
}

.question-editor-card {
  width: min(980px, 96vw);
  max-height: min(92vh, 980px);
  overflow: auto;
}

.question-editor-list {
  display: grid;
  gap: 12px;
  margin: 10px 0 14px;
}

.question-editor-item {
  border: 1px solid #dbeafe;
  border-radius: 12px;
  padding: 12px;
  background: #f8fafc;
}

.question-editor-item h4 {
  margin: 0 0 8px;
}

.question-editor-item textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}

.question-option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.question-option-edit {
  border: 1px solid #dbeafe;
  border-radius: 10px;
  background: #fff;
  padding: 8px;
}

.question-option-preview {
  margin-top: 8px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
}

.question-option-preview img {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 8px;
}

.question-option-preview span {
  color: #64748b;
  font-size: 13px;
}

.qr-wrap {
  margin: 10px 0;
  text-align: center;
  background: #fbfbfb;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 10px;
}

.join-link {
  word-break: break-all;
  font-size: 12px;
}

.host-bottom-left {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  width: 260px;
}

.host-right-list {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: 280px;
  max-height: calc(100% - 32px);
  overflow: auto;
}

.host-right-list ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.host-right-list li {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.host-wrong-mark {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 24;
  font-size: clamp(140px, 22vw, 320px);
  font-weight: 900;
  color: rgba(220, 38, 38, 0.94);
  line-height: 1;
  text-shadow: 0 12px 28px rgba(127, 29, 29, 0.35);
  pointer-events: none;
}

.host-wrong-mark.animate {
  animation: wrong-pulse 760ms ease-in-out 1;
}

@keyframes wrong-pulse {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.25); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.86); }
}

.wheel-modal {
  position: absolute;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.wheel-modal.pinned {
  inset: 0;
  background: transparent;
  align-items: center;
  justify-content: center;
  padding: 0;
  pointer-events: none;
}

.wheel-wrap {
  position: relative;
  width: min(560px, 94vw);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #d1d5db;
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.wheel-modal.pinned .wheel-wrap {
  width: min(430px, 52vw);
  padding: 10px 12px 12px;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.3);
}

#wheel-canvas {
  width: min(520px, 88vw);
  height: min(520px, 88vw);
}

.wheel-modal.pinned #wheel-canvas {
  width: min(360px, 54vw);
  height: min(360px, 54vw);
}

.wheel-pointer {
  position: absolute;
  top: 50%;
  right: 2px;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 16px solid transparent;
  border-bottom: 16px solid transparent;
  border-right: 28px solid #dc2626;
  z-index: 10;
}

.wheel-pointer-name {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 11;
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 16px;
  font-weight: 700;
  max-width: min(48vw, 560px);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.wheel-label {
  margin: 8px 0 0;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: #b91c1c;
  border-radius: 12px;
  padding: 8px 12px;
  display: inline-block;
  border: 2px solid rgba(255, 255, 255, 0.85);
  text-shadow: none;
  max-width: min(86vw, 980px);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.2;
}

.wheel-modal.pinned .wheel-label {
  font-size: clamp(26px, 2.8vw, 40px);
  padding: 10px 16px;
  font-weight: 800;
}

.wheel-modal.pinned .wheel-pointer-name {
  font-size: 20px;
  padding: 8px 12px;
}

.guest-view .stage-overlay {
  align-items: flex-end;
  justify-content: flex-end;
}

.guest-view .stage-bg {
  background-image: none;
  background-color: #1e44c7;
}

.guest-card {
  width: min(420px, 92vw);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d1d5db;
  border-radius: 14px;
  padding: 14px;
  margin-inline: auto;
}

.guest-self-name {
  margin-top: -4px;
  font-weight: 700;
  color: #111827;
}

.guest-card.transition-mode {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: min(52vh, 420px);
}

.guest-card.transition-mode #guest-stage-title {
  margin: 0;
  font-size: clamp(42px, 9vw, 72px);
  line-height: 1.05;
}

.guest-card.transition-mode #guest-stage-message {
  margin-top: 16px;
  font-size: clamp(22px, 5.2vw, 38px);
  line-height: 1.25;
}

.guest-card.transition-mode #guest-self-name {
  margin-top: 14px;
}

body.guest-mode .shell {
  width: 100%;
  margin: 0;
}

body.guest-mode .guest-view .stage-bg {
  min-height: 100dvh;
  border-radius: 0;
  border: 0;
  background-image: none;
  background-color: #1e44c7;
}

body.guest-mode .guest-view .stage-overlay {
  min-height: 100dvh;
  justify-content: flex-start;
  align-items: center;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

body.guest-mode .guest-card {
  width: min(460px, calc(100vw - 32px));
}

@media (max-width: 980px) {
  .stage-bg { min-height: 110vh; background-size: cover; }
  .host-top-left { width: calc(100% - 32px); }
  .host-right-list {
    position: absolute;
    right: 10px;
    top: auto;
    bottom: 12px;
    width: calc(100% - 292px);
    max-height: 220px;
  }
  .host-bottom-left { width: 260px; }
  #host-question-options {
    grid-template-columns: 1fr;
  }
  #guest-question-options {
    grid-template-columns: 1fr;
  }
  .host-view .host-answer-actions {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: min(300px, calc(100vw - 28px));
  }
  .question-option-grid {
    grid-template-columns: 1fr;
  }
  .guest-view .stage-overlay {
    justify-content: center;
  }
}
