/* ============================================================
   MgolfSystem — 數位互動系統 樣式表
   ============================================================ */

:root {
  --ink: #16211c;
  --ink-2: #3b4a43;
  --muted: #6b7770;
  --line: #d8dfda;
  --line-soft: #e9eeeb;
  --bg: #f2f4f1;
  --surface: #ffffff;
  --green: #1e6f4c;
  --green-dark: #17573c;
  --green-soft: #e4f0ea;
  --red: #b93a2f;
  --red-soft: #fae7e5;
  --amber: #b3701a;
  --amber-soft: #fbeedb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 33, 28, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
p { margin: 0; }

.wrap { max-width: 900px; margin: 0 auto; padding: 20px 16px 64px; }
.wrap-narrow { max-width: 420px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap-wide { max-width: 1600px; margin: 0 auto; padding: 20px 20px 40px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }

.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }
.mt-s { margin-top: 8px; }
.mt-m { margin-top: 16px; }
.mt-l { margin-top: 24px; }
.mb-xs { margin-bottom: 4px; }
.mt-xs { margin-top: 4px; }
.input-error { border-color: var(--red) !important; background: var(--red-soft); }
.field-err { color: var(--red); font-size: 0.8rem; margin: 4px 0 0; display: none; }
.field-err.show { display: block; }
.mb-s { margin-bottom: 8px; }
.mb-m { margin-bottom: 16px; }

.label { font-size: 0.8rem; color: var(--muted); }
.hint { font-size: 0.78rem; color: var(--muted); }
.small { font-size: 0.85rem; }
.muted { color: var(--muted); }
.mono-num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* button/.btn 統一設了 display:inline-flex，會蓋掉瀏覽器對 [hidden] 屬性
   預設的 display:none，導致 hidden 的按鈕還是會顯示出來，這裡加回來 */
[hidden] { display: none !important; }

button, .btn {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--ink-2); }
button:disabled { opacity: 0.38; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--green-dark); border-color: var(--green-dark); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-lg { padding: 16px; font-size: 1.05rem; font-weight: 600; }
.btn-tall { padding: 22px 14px; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"], select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
select:disabled, input:disabled { background: var(--line-soft); color: var(--muted); }

.pill {
  display: inline-block;
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
}
.pill-live { background: var(--green-soft); color: var(--green-dark); }
.pill-ready { background: var(--amber-soft); color: var(--amber); }
.pill-done { background: var(--line-soft); color: var(--muted); }

.banner {
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 0.82rem;
  padding: 8px 14px;
  text-align: center;
}

/* ---------- 頁首 ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* ---------- 頁尾：開發者資訊 + 版本號 ---------- */

.app-footer {
  max-width: 1600px;
  margin: 32px auto 0;
  padding: 14px 16px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.7;
}
.app-footer a { color: var(--green-dark); }
.footer-version { font-variant-numeric: tabular-nums; }

/* ---------- 驗證碼登入：4 格輸入 + 數字鍵盤（學員端掃 QR 後輸入場次驗證碼） ---------- */

.code-boxes { display: flex; gap: 10px; margin-bottom: 22px; }
.code-box {
  flex: 1;
  aspect-ratio: 7 / 8;
  border: 2px solid var(--line);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.1rem; font-weight: 700;
  color: var(--green-dark);
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  transition: border-color .12s;
}
.code-box.active { border-color: var(--green); background: var(--surface); }
.code-box.filled { background: var(--surface); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  aspect-ratio: 3 / 4; /* 3 欄 4 列，整個鍵盤維持這個比例，每列高度就自動等於每欄寬度 */
  gap: 10px;
  margin-bottom: 20px;
}
.keypad button {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}
.keypad button:active { background: var(--green-soft); border-color: var(--green); }
.keypad .key-0 { grid-column: 1 / 3; }
.keypad .key-del { font-size: 1.1rem; color: var(--muted); }
.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand { font-weight: 600; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
}

/* ---------- 統計卡 ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat-value { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---------- 出題控制 ---------- */

.qkey-display {
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--green);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.answer-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  flex-wrap: wrap;
}
.answer-bar select { width: 76px; font-weight: 600; }
.ctrl-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

/* 答題流程狀態色塊：待開放作答／作答中／準備對答案。
   跟題號放在同一列、貼右對齊，字級依比例縮小，寬度依文字內容自動縮放 */
.phase-banner {
  padding: 5px 14px;
  border-radius: 5px;
  text-align: center;
  font-size: 0.87rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.phase-wait { background: var(--line-soft); color: var(--ink-2); }
.phase-answering { background: var(--amber-soft); color: var(--amber); }
.phase-locked { background: var(--green-soft); color: var(--green-dark); }

/* ---------- 學員手機作答 ---------- */

.phone-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
}
#ringWrap { display: flex; justify-content: center; }
#ringWrap:empty { display: none; }
.countdown-ring {
  width: 108px; height: 108px;
  border-radius: 50%;
  border: 4px solid var(--amber);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-bottom: 16px;
}

/* 右上角累計比分徽章：兩行字（SCORE 小標＋兩碼分數）整體高度對齊左邊隊名／題號區塊 */
.score-badge { text-align: right; }
.score-label {
  font-size: 0.82rem; font-weight: 700; color: var(--muted); letter-spacing: 0.28em; margin: 0 0 2px;
}
.score-num {
  font-size: 2.6rem; font-weight: 700; color: var(--green); letter-spacing: -0.02em;
  line-height: 1.1; margin: 0; font-variant-numeric: tabular-nums;
}
.score-num.neg { color: var(--red); }

/* 選完答案、按下鎖定前的再次確認卡片 */
.confirm-box {
  border: 2px solid var(--green); border-radius: 12px; padding: 16px; text-align: center;
  background: var(--green-soft); margin-bottom: 4px;
}
.confirm-box .picked-label { font-size: 0.82rem; color: var(--muted); margin: 0 0 4px; }
.confirm-box .picked-val { font-size: 2.2rem; font-weight: 700; color: var(--green-dark); margin: 0; }
.countdown-ring.urgent { border-color: var(--red); animation: pulse 1s ease-in-out infinite; }
.countdown-num { font-size: 2.5rem; font-weight: 700; line-height: 1; color: var(--amber); font-variant-numeric: tabular-nums; }
.countdown-ring.urgent .countdown-num { color: var(--red); }
.countdown-cap { font-size: 0.66rem; color: var(--muted); }
@keyframes pulse { 50% { transform: scale(1.04); } }

.opt-list { display: flex; flex-direction: column; gap: 12px; }
.opt-btn {
  width: 100%;
  padding: 18px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.opt-btn.selected {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.opt-btn.correct { background: var(--green); border-color: var(--green); color: #fff; }
.opt-btn.wrong { background: var(--red); border-color: var(--red); color: #fff; }
.opt-btn.dim { opacity: 0.35; }

/* 選答狀態（凹桿）提示條 */
.notice {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 14px;
}
.notice-ok { background: var(--green-soft); color: var(--green-dark); }
.notice-warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- 監控板 ---------- */

.monitor-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.monitor-qkey { font-size: 2rem; font-weight: 700; color: var(--green); font-variant-numeric: tabular-nums; }

.group-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.group-cell {
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
  min-height: 96px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
}
.group-cell .g-no { font-size: 0.72rem; opacity: 0.85; white-space: nowrap; }
.group-cell .g-name { font-size: 1.05rem; font-weight: 600; white-space: nowrap; }
.group-cell .g-pick { font-size: 3.4rem; font-weight: 700; line-height: 1; margin-top: 4px; color: #fff; }
.cell-waiting { background: var(--line-soft); color: var(--ink-2); }
.cell-pending { background: var(--red-soft); color: var(--red); }
.cell-done { background: var(--green-soft); color: var(--green-dark); }
.cell-correct { background: var(--green); color: #fff; }
.cell-wrong { background: var(--red); color: #fff; }

/* ---------- 總覽表 ---------- */

.table-scroll { overflow-x: auto; }
table.overview { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.88rem; }

/* 最右邊的累計總分欄位固定不動，左右捲動時仍留在原位 */
table.overview th.col-total,
table.overview td.col-total {
  position: sticky;
  right: 0;
  z-index: 3;
  background: var(--surface);
  border-left: 2px solid var(--ink-2);
  min-width: 68px;
  box-shadow: -6px 0 8px -6px rgba(22, 33, 28, 0.22);
}
table.overview thead th.col-total { background: var(--green-soft); color: var(--green-dark); }
table.overview td.col-total { font-size: 1.05rem; }
table.overview th, table.overview td { padding: 6px 6px; text-align: center; }
table.overview th { font-weight: 600; color: var(--muted); font-size: 0.8rem; }
table.overview .col-group { text-align: left; min-width: 116px; }
table.overview tbody td { border-top: 1px solid var(--line-soft); }
table.overview .qgroup-end { border-right: 2px solid var(--line); }
table.overview .row-correct td { border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.8rem; }
.tbl-gno { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }
.tbl-tname { font-size: 0.92rem; font-weight: 600; white-space: nowrap; }
.score-cell { font-weight: 700; font-variant-numeric: tabular-nums; }

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

.podium { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.podium-item { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; }
.podium-item.first { border: 2px solid var(--green); background: var(--green-soft); }
.podium-rank { font-size: 0.78rem; color: var(--muted); }
.podium-name { font-size: 1.15rem; font-weight: 700; margin: 4px 0; }
.podium-score { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- 場次列表 ---------- */

.session-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top-width: 0;
  padding: 13px 16px;
  flex-wrap: wrap;
}
.session-row:first-of-type { border-top-width: 1px; border-radius: var(--radius) var(--radius) 0 0; }
.session-row:last-of-type { border-radius: 0 0 var(--radius) var(--radius); }
.session-row .s-main { flex: 2 1 200px; min-width: 160px; }
.session-row .s-meta { flex: 1 1 90px; font-size: 0.85rem; color: var(--ink-2); }

/* ---------- QR 卡片列印 ---------- */

.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.qr-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  break-inside: avoid;
}
.qr-card img, .qr-card canvas { width: 100%; max-width: 160px; height: auto; }
.qr-card .qr-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }

  /* 各組登入QR列印：橫式、4欄x2列，每頁固定8個。
     卡片之間「不留白邊」（gap:0），改用卡片本身的虛線邊框當作裁切線——
     四欄／兩列都用 1fr 等分寬高，所以每一份的寬度、高度一定完全一樣，
     印出來後只要沿虛線裁：直的裁 3 刀、橫的裁 1 刀（井字型），就能剪出
     8 份大小相同的卡片，不用再目測留白正中間剪。 */
  @page { size: landscape; margin: 10mm; }
  .qr-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 0;
  }
  .qr-card {
    border: 1px dashed #999;
    border-radius: 0;
    box-sizing: border-box;
    padding: 8mm 5mm;
  }
  .qr-grid .qr-card:nth-child(8n) { break-after: page; }
}

/* ---------- 響應式 ---------- */

@media (max-width: 640px) {
  .wrap, .wrap-wide { padding: 14px 12px 48px; }
  .group-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
  .group-cell .g-pick { font-size: 2.4rem; }
  .qkey-display { font-size: 2.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
