/* ==========================================================================
   破冰搶答遊戲 — 共用樣式（Kahoot 式活潑高彩度）
   玩家手機頁與主持人大螢幕共用同一份
   ========================================================================== */

:root {
  --bg-1: #2d1b69;
  --bg-2: #1f1147;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-solid: #2a1a5e;
  --text: #ffffff;
  --text-soft: rgba(255, 255, 255, 0.72);

  /* 四個選項固定配色（順序＝題庫 options 的順序） */
  --c0: #e21b3c; /* 紅 ▲ */
  --c1: #1368ce; /* 藍 ◆ */
  --c2: #d89e00; /* 黃 ● */
  --c3: #26890c; /* 綠 ■ */

  --ok: #26890c;
  --bad: #e21b3c;
  --gold: #ffc93c;
  --silver: #c9d1e0;
  --bronze: #d98b4a;

  --radius: 16px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  /* 全部使用裝置內建字型，不下載任何外部字型 */
  font-family: 'PingFang TC', 'Noto Sans TC', 'Noto Sans CJK TC', 'Microsoft JhengHei',
    system-ui, -apple-system, 'Heiti TC', sans-serif;
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-weight: 500;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- 畫面切換 */

.screen {
  display: none;
  min-height: 100dvh;
  padding: 20px;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

.center {
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ---------------------------------------------------------------- 通用元件 */

h1,
h2,
h3 {
  margin: 0;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.title {
  font-size: clamp(28px, 7vw, 44px);
  line-height: 1.2;
}

.subtitle {
  color: var(--text-soft);
  font-size: clamp(15px, 4vw, 19px);
  margin-top: 10px;
}

.card {
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  padding: 24px;
  backdrop-filter: blur(6px);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 16px 28px;
  font-family: inherit;
  font-size: 19px;
  font-weight: 900;
  color: #fff;
  background: #46178f;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.12);
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #26890c;
  font-size: 22px;
  padding: 18px 44px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.28);
  box-shadow: none;
  font-size: 16px;
  padding: 12px 20px;
}

.btn-danger {
  background: #b3122c;
}

input[type='text'],
input[type='password'] {
  width: 100%;
  padding: 18px 20px;
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  color: #1f1147;
  background: #fff;
  border: 4px solid transparent;
  border-radius: 12px;
  outline: none;
}

input[type='text']:focus,
input[type='password']:focus {
  border-color: var(--gold);
}

.error-msg {
  min-height: 26px;
  margin-top: 12px;
  color: #ff9db0;
  font-weight: 700;
  font-size: 16px;
}

.pill {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 15px;
  font-weight: 700;
}

/* ---------------------------------------------------------------- 頂部列 */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.qnum {
  font-size: clamp(15px, 4vw, 22px);
  font-weight: 900;
  color: var(--text-soft);
}

.timer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 68px;
  padding: 0 10px;
  border-radius: 999px;
  background: #fff;
  color: #1f1147;
  font-size: 34px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.timer.urgent {
  background: var(--bad);
  color: #fff;
  animation: pulse 0.7s ease-in-out infinite;
}

.timer.paused {
  background: var(--gold);
  color: #1f1147;
  animation: none;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.14);
  }
}

/* ---------------------------------------------------------------- 題目 */

.question-text {
  font-size: clamp(24px, 5.5vw, 40px);
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
  padding: 22px 18px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

/* ---------------------------------------------------------------- 四色選項 */

.options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 110px;
  padding: 16px 18px;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: clamp(17px, 3.6vw, 26px);
  font-weight: 900;
  text-align: left;
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.2s ease, filter 0.2s ease;
}

.option:active:not(:disabled) {
  transform: translateY(3px);
}

.option:disabled {
  cursor: not-allowed;
}

.option .shape {
  flex: 0 0 auto;
  font-size: 1.5em;
  line-height: 1;
}

.option .label {
  flex: 1 1 auto;
  word-break: break-word;
}

.opt-0 {
  background: var(--c0);
}
.opt-1 {
  background: var(--c1);
}
.opt-2 {
  background: var(--c2);
}
.opt-3 {
  background: var(--c3);
}

/* 公布答案時：正解放大、其他淡出 */
.option.is-correct {
  outline: 5px solid #fff;
  outline-offset: -5px;
  transform: scale(1.02);
}

.option.is-dimmed {
  opacity: 0.32;
  filter: grayscale(0.5);
}

.option .check {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 26px;
}

/* 玩家自己選的那一個 */
.option.is-mine::after {
  content: '你的選擇';
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.9;
}

/* ---------------------------------------------------------------- 作答分佈長條圖 */

.dist {
  display: grid;
  gap: 14px;
  margin-top: 8px;
}

.dist-row {
  display: grid;
  grid-template-columns: minmax(140px, 26%) 1fr auto;
  align-items: center;
  gap: 14px;
  font-size: clamp(15px, 2.4vw, 24px);
  font-weight: 900;
}

.dist-name {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dist-track {
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

.dist-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.dist-count {
  min-width: 96px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dist-row.wrong {
  opacity: 0.55;
}

/* ---------------------------------------------------------------- 排行榜 */

.rank-list {
  display: grid;
  gap: 10px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.rank-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  font-size: clamp(17px, 2.4vw, 26px);
  font-weight: 900;
  animation: slideIn 0.4s ease backwards;
}

.rank-row .rank-no {
  font-size: 1.1em;
  color: var(--text-soft);
  text-align: center;
}

.rank-row .rank-name {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.rank-row .rank-score {
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

/* 名次升降標記 */
.rank-change {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.5em;
  font-weight: 900;
  letter-spacing: 0.5px;
  line-height: 1.6;
}

.rank-change.up {
  background: rgba(38, 137, 12, 0.9);
  color: #fff;
}

.rank-change.down {
  background: rgba(226, 27, 60, 0.85);
  color: #fff;
}

.rank-change.same {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.55);
}

.rank-change:empty {
  display: none;
}

.rank-row.top1 {
  background: linear-gradient(90deg, rgba(255, 201, 60, 0.32), rgba(255, 255, 255, 0.08));
}
.rank-row.top2 {
  background: linear-gradient(90deg, rgba(201, 209, 224, 0.26), rgba(255, 255, 255, 0.08));
}
.rank-row.top3 {
  background: linear-gradient(90deg, rgba(217, 139, 74, 0.26), rgba(255, 255, 255, 0.08));
}

.rank-row.is-me {
  outline: 3px solid var(--gold);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------------------------------------------------------- 頒獎台 */

.podium {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: clamp(10px, 2vw, 28px);
  width: 100%;
  max-width: 900px;
  margin: 26px auto 30px;
}

.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: riseUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.podium-slot .medal {
  font-size: clamp(34px, 6vw, 60px);
  line-height: 1;
}

.podium-slot .pname {
  margin-top: 6px;
  font-size: clamp(17px, 2.6vw, 30px);
  font-weight: 900;
  text-align: center;
  word-break: break-word;
}

.podium-slot .pscore {
  font-size: clamp(15px, 2.2vw, 24px);
  font-weight: 900;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.podium-slot .block {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 12px;
  border-radius: 14px 14px 0 0;
  font-size: clamp(30px, 5vw, 56px);
  font-weight: 900;
  color: rgba(31, 17, 71, 0.75);
}

.podium-slot.p1 .block {
  height: clamp(130px, 20vh, 210px);
  background: linear-gradient(180deg, var(--gold), #e0a800);
}
.podium-slot.p2 .block {
  height: clamp(95px, 15vh, 160px);
  background: linear-gradient(180deg, var(--silver), #9aa5b8);
}
.podium-slot.p3 .block {
  height: clamp(70px, 11vh, 120px);
  background: linear-gradient(180deg, var(--bronze), #b06f33);
}

.podium-slot.p1 {
  order: 2;
  animation-delay: 0.5s;
}
.podium-slot.p2 {
  order: 1;
  animation-delay: 0.15s;
}
.podium-slot.p3 {
  order: 3;
  animation-delay: 0.3s;
}

@keyframes riseUp {
  from {
    opacity: 0;
    transform: translateY(60px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------------------------------------------------------------- 連線狀態 */

.conn-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  padding: 10px;
  text-align: center;
  font-weight: 900;
  font-size: 15px;
  background: var(--gold);
  color: #1f1147;
  transform: translateY(-100%);
  transition: transform 0.25s ease;
}

.conn-banner.show {
  transform: none;
}

/* ---------------------------------------------------------------- 選項進場：由上而下依序跳出 */

.option.enter {
  animation: optionIn 0.34s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

@keyframes optionIn {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* 答對／答錯時的整頁回饋 */
.result-pop {
  animation: resultPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes resultPop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.shake {
  animation: shake 0.42s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-11px);
  }
  40% {
    transform: translateX(9px);
  }
  60% {
    transform: translateX(-6px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* ---------------------------------------------------------------- 動畫小工具 */

.fade-in {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
  0% {
    content: '';
  }
  25% {
    content: '.';
  }
  50% {
    content: '..';
  }
  75% {
    content: '...';
  }
}
