:root {
  --kahoot-red: #e21b3c;
  --kahoot-blue: #1368ce;
  --kahoot-yellow: #d89e00;
  --kahoot-green: #26890c;
  --kahoot-bg: #46178f;
  --text: #f5f0ff;
  --muted: #d4c4f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--kahoot-bg);
  color: var(--text);
  min-height: 100vh;
}

body.kahoot-play {
  background: linear-gradient(135deg, #46178f 0%, #2d0a5e 40%, #1a0533 100%);
}

.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100vh;
}

body.kahoot-play .wrap {
  max-width: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

body.kahoot-play .play-header {
  display: none;
}

.play-header h1 { font-size: 1.25rem; margin: 0 0 8px; }
.play-header .msg { margin: 0 0 12px; }

.card {
  background: rgba(45, 27, 78, 0.85);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

input, button, textarea, select {
  font: inherit;
  border-radius: 12px;
  border: none;
  padding: 14px 18px;
}

input { width: 100%; margin-bottom: 10px; }

button {
  cursor: pointer;
  background: linear-gradient(180deg, #8b5cf6, #6d28d9);
  color: #fff;
  font-weight: 700;
  width: 100%;
  margin-top: 8px;
  box-shadow: 0 4px 0 #4c1d95;
}

button:active { transform: translateY(2px); box-shadow: 0 2px 0 #4c1d95; }
button.secondary { background: #4b5563; box-shadow: 0 4px 0 #374151; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.msg { color: var(--muted); font-size: 0.95rem; }
.pin-big { font-size: 2.2rem; letter-spacing: 0.35em; text-align: center; font-weight: 800; }
nav a { color: #e9d5ff; margin-right: 12px; }

.host-join-box {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  text-align: center;
}

.host-qrcode {
  display: inline-block;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  margin: 8px auto 12px;
}

.host-join-url {
  word-break: break-all;
  font-size: 0.9rem;
  color: #fde047;
}

/* --- Kahoot question stage --- */
.kahoot-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  min-height: 100dvh;
  width: 100%;
}

/* 題目區：比答案醒目，水平＋垂直置中 */
.kahoot-question-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px 16px 10px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.12) 100%);
  border-bottom: 3px solid rgba(253, 224, 71, 0.45);
}

.kahoot-meta {
  margin: 0 0 8px;
  width: 100%;
  max-width: 920px;
  font-size: clamp(0.82rem, 3vw, 0.95rem);
  color: #e9d5ff;
  text-align: center;
  font-weight: 600;
}

.kahoot-q-label {
  margin: 0 0 8px;
  width: 100%;
  max-width: 920px;
  text-align: center;
  font-size: clamp(1rem, 3.5vw, 1.15rem);
  font-weight: 900;
  letter-spacing: 0.28em;
  padding-right: 0.28em; /* 字距補償，視覺置中 */
  color: #fde047;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.kahoot-qbar {
  background: #fff;
  color: #1a0a2e;
  padding: clamp(22px, 4vw, 28px) clamp(18px, 4vw, 24px);
  font-size: clamp(1.55rem, 7.5vw, 2.4rem);
  font-weight: 900;
  line-height: 1.45;
  min-height: clamp(120px, 30vh, 210px);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  word-break: break-word;
  border-radius: 14px;
  box-shadow:
    0 0 0 5px #fde047,
    0 0 28px rgba(253, 224, 71, 0.55),
    0 10px 32px rgba(0, 0, 0, 0.5);
  margin-left: auto;
  margin-right: auto;
  max-width: 920px;
  width: min(920px, calc(100% - 8px));
  box-sizing: border-box;
}

.kahoot-timer {
  width: 100%;
  max-width: 920px;
  text-align: center;
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffe066;
}

.kahoot-hint {
  width: 100%;
  max-width: 920px;
  text-align: center;
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  color: #c4b5fd;
  margin: 8px auto 4px;
  font-weight: 600;
}

.kahoot-grid {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  padding: 8px;
  min-height: 0;
  max-height: 46dvh;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  box-sizing: border-box;
}

@media (min-width: 600px) {
  .kahoot-grid {
    gap: 12px;
    padding: 12px 16px 16px;
  }
}

.kahoot-opt {
  position: relative;
  border: 3px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  padding: 20px 52px 20px 58px;
  min-height: 128px;
  color: #fff;
  font-weight: 800;
  line-height: 1.4;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

.kahoot-opt .opt-text {
  display: block;
  font-size: clamp(1.22rem, 5.8vw, 1.68rem);
  font-weight: 900;
  color: inherit;
  line-height: 1.35;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: color 0.15s ease, transform 0.15s ease;
}

.kahoot-opt:not(.selected):active { transform: scale(0.98); }

.kahoot-opt.red { background: var(--kahoot-red); }
.kahoot-opt.blue { background: var(--kahoot-blue); }
.kahoot-opt.yellow { background: var(--kahoot-yellow); }
.kahoot-opt.yellow .opt-text {
  color: #1a1a1a;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.5);
}
.kahoot-opt.green { background: var(--kahoot-green); }

.kahoot-opt .shape {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.kahoot-opt.yellow .shape { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.2)); }

/* 已選：粗白框、大字變色、大勾勾 */
.kahoot-opt.selected {
  border-color: #fff;
  outline: none;
  transform: scale(1.03);
  z-index: 1;
  box-shadow: 0 0 0 3px #fff, 0 8px 0 rgba(0, 0, 0, 0.4);
}

.kahoot-opt.selected .opt-text {
  color: #ffeb3b;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.55);
  transform: scale(1.02);
}

.kahoot-opt.yellow.selected .opt-text {
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
}

.kahoot-opt.selected::after {
  content: "✓";
  position: absolute;
  right: 12px;
  top: 12px;
  width: 44px;
  height: 44px;
  background: linear-gradient(180deg, #fff 0%, #e8e8e8 100%);
  color: #16a34a;
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  animation: check-pop 0.25s ease-out;
}

@keyframes check-pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* 選定後不可再點取消 */
.kahoot-opt.locked {
  cursor: default;
}

.kahoot-opt.locked:not(.selected) {
  cursor: pointer;
}

.kahoot-submit-wrap {
  padding: 12px 16px 20px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.kahoot-submit {
  font-size: 1.1rem;
  padding: 16px;
  border-radius: 14px;
  background: linear-gradient(180deg, #22c55e, #16a34a);
  box-shadow: 0 5px 0 #14532d;
}

/* 送出後回饋（避免畫面一片空白） */
.result-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  min-height: 50dvh;
}

.result-panel-inner {
  width: 100%;
  max-width: 420px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  border: 3px solid rgba(255, 255, 255, 0.25);
}

.result-panel.ok .result-panel-inner {
  border-color: #4ade80;
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.35);
}

.result-panel.bad .result-panel-inner {
  border-color: #f87171;
  box-shadow: 0 0 24px rgba(248, 113, 113, 0.25);
}

.result-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 8px;
}

.result-panel h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

.result-panel.ok h2 { color: #4ade80; }
.result-panel.bad h2 { color: #fca5a5; }

.result-panel #resultText {
  margin: 0 0 12px;
  font-size: 1.05rem;
  color: #e9d5ff;
}

.result-choices {
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  font-weight: 700;
  color: #fff;
  line-height: 1.5;
  margin: 0 0 12px;
  word-break: break-word;
}

.result-score {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fde047;
  margin: 0 0 16px;
}

.result-wait-hint {
  font-size: 0.95rem;
  color: #c4b5fd;
  margin: 0;
}

/* 老師控場：目前題目（僅題幹，置於按鈕上方） */
.host-live-question {
  margin: 14px 0 16px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 3px solid #fde047;
  background: #fff;
  color: #1a0a2e;
  box-shadow: 0 0 24px rgba(253, 224, 71, 0.45);
}

.host-live-meta {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 800;
  color: #5b21b6;
}

.host-live-label {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #7c3aed;
  text-transform: none;
}

.host-live-prompt {
  margin: 0;
  font-size: clamp(1.35rem, 4.5vw, 1.95rem);
  font-weight: 900;
  line-height: 1.45;
  color: #1a0a2e;
  word-break: break-word;
}

.host-final-lb {
  margin-top: 16px;
  border: 2px solid rgba(250, 204, 21, 0.45);
  background: linear-gradient(160deg, rgba(70, 23, 143, 0.95), rgba(26, 10, 51, 0.98));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.host-final-lb h2 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 1.65rem;
  color: #fde68a;
}

.host-final-sub {
  text-align: center;
  margin: 0 0 16px;
  color: #c4b5fd;
  font-size: 0.95rem;
}

.host-final-rows .lb-row {
  font-size: 1.35rem;
  padding: 18px 14px;
}

.host-boards-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.host-board-pre {
  white-space: pre-wrap;
  font-size: 12px;
  margin-top: 10px;
  color: var(--muted);
}

.lb-card {
  margin: 16px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 20px;
  padding: 20px;
}

.lb-card h2 {
  text-align: center;
  margin: 0 0 16px;
  font-size: 1.5rem;
}

.lb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 12px;
  margin: 8px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 1.1rem;
  font-weight: 600;
}

.lb-row.rank-1 { background: linear-gradient(90deg, rgba(250, 204, 21, 0.35), transparent); }
.lb-row.rank-2 { background: linear-gradient(90deg, rgba(192, 192, 192, 0.3), transparent); }
.lb-row.rank-3 { background: linear-gradient(90deg, rgba(205, 127, 50, 0.35), transparent); }

.reward-card {
  margin-top: 20px;
  padding: 20px 16px;
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(253, 224, 71, 0.2), rgba(74, 222, 128, 0.12));
  border: 2px solid rgba(253, 224, 71, 0.55);
  text-align: center;
}

.reward-card h3 {
  margin: 0 0 10px;
  font-size: 1.25rem;
  color: #fde047;
}

.reward-screenshot {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.35);
  border: 2px solid #fbbf24;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.4;
  animation: reward-pulse 1.8s ease-in-out infinite;
}

@keyframes reward-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(251, 191, 36, 0.15); }
}

.reward-desc {
  margin: 0 0 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #e9d5ff;
}

.reward-result {
  margin-top: 12px;
}

.reward-code-label {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: #c4b5fd;
}

.reward-code {
  margin: 0 0 12px;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #fff;
  word-break: break-all;
}

.reward-copy {
  width: auto;
  display: inline-block;
  margin: 0 0 12px;
  padding: 10px 20px;
}

.reward-steps {
  font-size: 0.88rem;
  line-height: 1.45;
  color: #e9d5ff;
  margin: 0 0 14px;
}

.reward-portal-btn {
  display: block;
  padding: 14px 18px;
  border-radius: 14px;
  background: linear-gradient(180deg, #8b5cf6, #6d28d9);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 4px 0 #4c1d95;
}

body.play-page .reward-card .kahoot-submit {
  margin-top: 0;
}

.wait-pulse {
  text-align: center;
  padding: 48px 20px;
  font-size: 1.2rem;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ============================================================
   學員答題 play.html — 手機版優先（直式、大按鈕、安全區）
   桌機／平板也以手機寬度置中，不拉寬成桌面版
   ============================================================ */
body.play-page {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body.play-page .wrap {
  max-width: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  min-height: 100dvh;
}

/* 桌機：維持手機直式寬度（約 iPhone 14） */
@media (min-width: 480px) {
  body.play-page {
    background: #12082a;
  }

  body.play-page .wrap {
    max-width: 430px;
    margin: 0 auto;
    box-shadow:
      0 0 0 1px rgba(255, 255, 255, 0.08),
      0 12px 48px rgba(0, 0, 0, 0.55);
  }

  body.play-page.kahoot-play {
    background: #12082a;
  }
}

/* 加入房間（登入後） */
body.play-page .play-header {
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

body.play-page .play-header h1 {
  font-size: 1.15rem;
  text-align: center;
  margin: 0 0 4px;
}

body.play-page .play-header .msg {
  text-align: center;
  font-size: 0.9rem;
  margin: 0;
}

body.play-page #joinCard.card {
  margin: 12px 16px 24px;
  margin-left: max(16px, env(safe-area-inset-left));
  margin-right: max(16px, env(safe-area-inset-right));
  border-radius: 20px;
}

body.play-page #joinCard input {
  font-size: 1.35rem;
  text-align: center;
  letter-spacing: 0.2em;
  padding: 18px;
  min-height: 52px;
}

body.play-page #joinCard button {
  font-size: 1.15rem;
  min-height: 52px;
  margin-top: 12px;
}

body.play-page .wait-pulse {
  padding: max(48px, 18vh) 20px;
  font-size: 1.1rem;
}

body.play-page.kahoot-play .play-header {
  display: none;
}

body.play-page.kahoot-play .wrap {
  min-height: 100dvh;
}

/* 答題全螢幕：上題目、中選項、下送出 */
body.play-page .kahoot-stage {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

body.play-page .kahoot-question-hero {
  flex: 0 0 auto;
  justify-content: flex-start;
  padding:
    max(8px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    8px
    max(12px, env(safe-area-inset-left));
  max-height: 42vh;
}

body.play-page .kahoot-meta {
  max-width: 100%;
  font-size: 0.8rem;
  margin-bottom: 6px;
}

body.play-page .kahoot-q-label {
  max-width: 100%;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

body.play-page .kahoot-qbar {
  width: 100%;
  max-width: 100%;
  min-height: 96px;
  max-height: 28vh;
  padding: 16px 14px;
  font-size: clamp(1.2rem, 5.2vw, 1.55rem);
  line-height: 1.4;
  border-radius: 12px;
  box-shadow:
    0 0 0 4px #fde047,
    0 6px 20px rgba(0, 0, 0, 0.45);
}

body.play-page .kahoot-hint {
  max-width: 100%;
  font-size: 0.78rem;
  margin: 6px 0 0;
  line-height: 1.35;
}

body.play-page .kahoot-grid {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-height: 38vh;
  max-height: none;
  gap: 6px;
  padding:
    4px
    max(10px, env(safe-area-inset-right))
    6px
    max(10px, env(safe-area-inset-left));
}

body.play-page .kahoot-opt {
  min-height: 76px;
  padding: 10px 40px 10px 44px;
  border-radius: 10px;
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
}

body.play-page .kahoot-opt .opt-text {
  font-size: clamp(0.8rem, 3.5vw, 0.95rem);
  text-align: center;
  line-height: 1.35;
}

body.play-page .kahoot-opt .shape {
  width: 28px;
  height: 28px;
  left: 10px;
}

body.play-page .kahoot-opt.selected::after {
  width: 36px;
  height: 36px;
  right: 8px;
  top: 8px;
  font-size: 22px;
}

body.play-page .kahoot-submit-wrap {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
  max-width: 100%;
  padding:
    8px
    max(12px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, transparent 0%, rgba(26, 5, 51, 0.92) 35%);
}

body.play-page .kahoot-submit {
  font-size: 1.15rem;
  min-height: 52px;
  padding: 14px;
  border-radius: 14px;
}

body.play-page .result-panel {
  min-height: 100dvh;
  padding:
    max(20px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

body.play-page .result-panel-inner {
  max-width: 100%;
  padding: 24px 18px;
}

body.play-page .result-panel h2 {
  font-size: 1.45rem;
}

body.play-page .lb-card {
  margin:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  border-radius: 16px;
}

body.play-page .lb-row {
  font-size: 1rem;
  padding: 16px 12px;
  min-height: 48px;
}

/* 橫拿手機或極矮螢幕：壓縮題目區、保留選項高度 */
@media (max-height: 520px) {
  body.play-page .kahoot-question-hero {
    max-height: 34vh;
    padding-top: 6px;
  }

  body.play-page .kahoot-qbar {
    min-height: 64px;
    max-height: 22vh;
    font-size: 1.05rem;
    padding: 10px 12px;
  }

  body.play-page .kahoot-grid {
    min-height: 48vh;
  }

  body.play-page .kahoot-opt {
    min-height: 64px;
  }
}

/* 極窄（舊款小螢幕） */
@media (max-width: 360px) {
  body.play-page .kahoot-opt {
    padding-left: 38px;
    padding-right: 36px;
  }

  body.play-page .kahoot-opt .shape {
    width: 24px;
    height: 24px;
    left: 8px;
  }
}
