/* 魔法試煉之塔 —— 乾淨的底、留白建立層次，顏色只留給五大學院 */

:root {
  --ink:      #16151d;
  --ink-2:    #4c4a5c;
  --ink-3:    #86849a;
  --line:     #e4e2ec;
  --line-2:   #efeef4;
  --bg:       #fbfaf8;
  --surface:  #ffffff;
  --accent:   #3b2f63;
  --accent-w: #f1eef8;
  --ok:       #3f7a5c;
  --warn:     #9a5b2a;
  --danger:   #9b3b3b;
  --radius:   11px;
  --shadow:   0 1px 2px rgba(22, 21, 29, .04), 0 10px 28px -18px rgba(22, 21, 29, .28);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
body { line-height: 1.6; }

.wrap { max-width: 900px; margin: 0 auto; padding: 36px 24px 80px; }
.wrap-wide { max-width: 1200px; }

/* ---------- 標題 ---------- */
.eyebrow {
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 10px; font-weight: 600;
}
h1 { font-size: 29px; line-height: 1.3; margin: 0 0 8px; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 700; }
.lede { color: var(--ink-2); margin: 0 0 30px; font-size: 15px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px;
}
.card-title {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 16px;
}
.card-title h2 { margin: 0; }

/* ---------- 按鈕 ---------- */
button, .btn {
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 16px; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  white-space: nowrap;
}
button:hover, .btn:hover { background: var(--line-2); }
button:disabled { opacity: .4; cursor: not-allowed; }
button:disabled:hover { background: var(--surface); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #2f2551; border-color: #2f2551; }
.btn-lg { font-size: 16px; padding: 14px 28px; border-radius: 9px; }
.btn-danger { color: var(--danger); border-color: #e8d9d9; }
.btn-danger:hover { background: #fbf3f3; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 表單 ---------- */
input:not([type="checkbox"]):not([type="radio"]), select {
  font-family: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, button:focus-visible, .opt:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label.row { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.field { margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.code-input {
  font-size: 30px !important; font-weight: 700; letter-spacing: .38em;
  text-align: center; padding: 14px 12px !important; font-variant-numeric: tabular-nums;
}

/* ---------- 步驟導引 ---------- */
.stepper {
  display: flex; flex-wrap: wrap; gap: 6px;
  list-style: none; margin: 0 0 18px; padding: 0;
}
.stepper li {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-3);
  padding: 6px 14px 6px 7px; border-radius: 999px; background: var(--line-2);
}
.stepper .dotnum {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: #fff; color: var(--ink-3); font-size: 11px; font-weight: 800; flex: none;
}
.stepper li.done { color: var(--ok); background: #f1f7f4; }
.stepper li.done .dotnum { background: var(--ok); color: #fff; }
.stepper li.at { color: #fff; background: var(--accent); }
.stepper li.at .dotnum { background: #fff; color: var(--accent); }

.nowcard { border-color: #d8d3e6; box-shadow: var(--shadow); padding: 24px; }
.nowbody { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; }
.nowmain { flex: 1 1 340px; }
.nowmain h2 { font-size: 21px; line-height: 1.35; margin: 0 0 8px; }
.nowtodo { font-size: 15px; color: var(--ink-2); line-height: 1.7; margin: 0 0 18px; }
.nowside { flex: 0 0 220px; display: flex; flex-direction: column; gap: 10px; }
.sidebox {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 11px 13px; font-size: 13px; line-height: 1.5;
}
.sidelabel {
  display: block; font-size: 10px; letter-spacing: .1em;
  color: var(--ink-3); font-weight: 700; margin-bottom: 3px;
}
.sidebox b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- 狀態 ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.pill.live { color: var(--ok); border-color: #cfe2d7; background: #f4f9f6; }
.pill.hold { color: var(--warn); border-color: #ecdcc9; background: #fbf6f0; }

.roomcode {
  font-size: 44px; font-weight: 800; letter-spacing: .16em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.urlchip {
  font-family: inherit; font-size: 14px; font-weight: 700;
  background: var(--accent-w); color: var(--accent);
  padding: 4px 10px; border-radius: 6px;
}
.bigurl {
  font-size: clamp(19px, 2.3vw, 28px); font-weight: 800;
  color: var(--accent); line-height: 1.25; word-break: break-all;
}

/* ---------- 試煉題目 ---------- */
.quest-head {
  display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; flex-wrap: wrap;
}
.quest-no {
  font-size: 11px; font-weight: 800; letter-spacing: .12em; color: var(--accent);
  background: var(--accent-w); padding: 4px 10px; border-radius: 999px;
}
.quest-title { font-size: 21px; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.quest-scene { color: var(--ink-2); font-size: 15px; margin: 8px 0 18px; line-height: 1.7; }

.opts { display: flex; flex-direction: column; gap: 9px; }
.opt {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  font-family: inherit; font-size: 15.5px; font-weight: 500; line-height: 1.5;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); cursor: pointer; white-space: normal;
  transition: transform .14s cubic-bezier(.34,1.56,.64,1), background .12s, border-color .12s, color .12s;
}
.opt:hover { border-color: var(--ink-3); }
.opt:active { transform: scale(.985); }
/* 選項左邊的圈圈只是「選了沒」的指示，不放 A~E */
.opt .mark {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--line); background: transparent;
  transition: border-color .12s ease, background .12s ease;
}
/* 星盤震盪那一頁的圈圈是學院徽記，要看得到 */
.opt .mark.house {
  width: 30px; height: 30px; border: 0; font-size: 16px;
}
.opt .otext { flex: 1; }
.opt .ohint { display: block; font-size: 12.5px; color: var(--ink-3); font-weight: 500; margin-top: 2px; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-w); font-weight: 700; }
.opt[aria-pressed="true"] .mark { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt[aria-pressed="true"] .mark:not(.house)::after {
  content: '✓'; font-size: 14px; font-weight: 800; line-height: 1;
}
.opt[aria-pressed="true"] .ohint { color: var(--ink-2); }

/* 進度點 */
.progress { display: flex; align-items: center; gap: 8px; margin-bottom: 22px; }
.progress .seg { height: 4px; flex: 1; border-radius: 999px; background: var(--line); }
.progress .seg.on { background: var(--accent); }
.progress .label {
  font-size: 12px; font-weight: 700; color: var(--ink-3); letter-spacing: .06em; flex: none;
}

/* ---------- 能量槽 ---------- */
.gauges { display: flex; flex-direction: column; gap: 14px; }
.gauge { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; }
.gauge .who { display: flex; align-items: center; gap: 9px; min-width: 132px; }
.gauge .sigil {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  font-size: 17px; flex: none;
}
.gauge .hname { font-weight: 700; font-size: 14.5px; line-height: 1.25; }
.gauge .htrait { font-size: 11.5px; color: var(--ink-3); font-weight: 600; }
.cells { display: flex; gap: 4px; flex-wrap: wrap; }
.cell {
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--line-2);
  transition: background .3s ease, border-color .3s ease, transform .3s cubic-bezier(.34,1.56,.64,1);
}
.cell.on { transform: scale(1); }
.cell.over { border-style: dashed; }
.gauge .tally {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 14px;
  color: var(--ink-2); min-width: 46px; text-align: right;
}
.gauge.full .tally { color: var(--ok); }

/* ---------- 名冊表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; letter-spacing: .1em; color: var(--ink-3);
  font-weight: 700; padding: 0 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 7px 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; width: 48px; color: var(--ink-3); }
tr.sim td { color: var(--ink-3); font-style: italic; }
td select { font-size: 13px; padding: 5px 8px; }
td button { padding: 3px 8px; font-size: 12px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px;
  border: 1px solid transparent;
}
.tag.rank2 { color: var(--warn); background: #fbf6f0; border-color: #ecdcc9; }
.tag.lock  { color: var(--accent); background: var(--accent-w); border-color: #ddd6ee; }
.answers {
  font-variant-numeric: tabular-nums; letter-spacing: .18em;
  font-weight: 700; color: var(--ink-3); font-size: 13px;
}
.scroll { max-height: 460px; overflow-y: auto; margin: 0 -8px; }

/* ---------- 揭曉卡 ---------- */
.reveal {
  text-align: center; padding: 34px 24px 30px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface);
}
.reveal .sigil-big {
  width: 92px; height: 92px; border-radius: 26px; margin: 0 auto 18px;
  display: grid; place-items: center; font-size: 46px;
}
.reveal .hname-big { font-size: 32px; font-weight: 800; letter-spacing: -.01em; margin: 0 0 6px; }
.reveal .motto { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.reveal .blurb { color: var(--ink-2); font-size: 14.5px; margin: 0 auto; max-width: 30em; }
.mates { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 20px; }
.mates span {
  font-size: 14px; padding: 6px 13px; border-radius: 999px; font-weight: 600;
}
.mates span.me { outline: 2px solid currentColor; outline-offset: -2px; }

.done-mark {
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--accent-w); color: var(--accent);
  display: grid; place-items: center; font-size: 30px; margin: 0 auto 18px;
}

/* ---------- 投影模式 ---------- */
body.display { background: #fff; }
.display-wrap { height: 100vh; display: flex; flex-direction: column; padding: 26px 40px 20px; overflow: hidden; }
.display-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex: none; }
.display-head h1 { font-size: 23px; margin: 0; }
.display-body { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.display-foot {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--ink-3); font-size: 14px; padding-top: 12px; flex: none;
}
.joinbig { text-align: center; margin: auto; padding: 0 24px; max-width: 100%; }
.joinbig .roomcode { font-size: clamp(72px, 14vh, 132px); }
.joinbig .url { font-size: clamp(18px, 2.4vh, 26px); color: var(--ink-2); margin: 14px 0 0; font-weight: 700; }
.display .joinbig .eyebrow { font-size: 16px; letter-spacing: .12em; margin-bottom: 16px; }

.board { display: flex; gap: 18px; height: 100%; align-items: stretch; }
.col {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface);
}
.col-head { padding: 14px 12px 12px; text-align: center; color: #fff; flex: none; }
.col-head .emoji { font-size: clamp(24px, 3.4vh, 38px); line-height: 1; }
.col-head .nm { font-weight: 800; font-size: clamp(16px, 2.4vh, 26px); margin-top: 4px; }
.col-head .cap { font-size: clamp(11px, 1.5vh, 14px); opacity: .85; font-weight: 600; }
.col-body { flex: 1 1 0; min-height: 0; padding: 9px 7px; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.slot {
  border-radius: 9px; text-align: center; flex: 1 1 0; min-height: 0;
  display: grid; place-items: center;
  /* --slotfs 由 display.html 依最長的名字算出來，長名字自動縮，短名字放到最大 */
  font-size: clamp(15px, var(--slotfs, 3vh), 44px);
  font-weight: 800; letter-spacing: -.01em;
  padding: 0 6px; overflow: hidden; white-space: nowrap;
  border: 1px dashed var(--line); color: var(--ink-3);
}
.slot.filled { border-style: solid; border-color: transparent; }

/* ---------- 學生網址分享卡 ---------- */
.sharecard {
  border-color: #d8d3e6;
  display: grid; grid-template-columns: 1fr auto; gap: 16px 24px; align-items: center;
}
.sharemain { min-width: 0; }
.sharecard .bigurl { margin-top: 4px; }
.shareacts { justify-content: flex-end; }
.sharewarn {
  grid-column: 1 / -1; margin: 4px 0 0;
  font-size: 13px; line-height: 1.6; color: #7d4a22;
  background: #fdf9f4; border: 1px solid #ecdcc9; border-radius: 8px; padding: 10px 14px;
}
.sharewarn b { font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .sharecard { grid-template-columns: 1fr; }
  .shareacts { justify-content: flex-start; }
}

/* 第一次使用的三件事 */
.firstrun { border-left: 3px solid var(--accent); }
.checklist { margin: 0; padding-left: 22px; font-size: 14.5px; color: var(--ink-2); line-height: 1.8; }
.checklist li { margin-bottom: 9px; }
.checklist li:last-child { margin-bottom: 0; }
.checklist b { color: var(--ink); }

/* ---------- 雜項 ---------- */
.notice {
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 8px;
  padding: 14px 16px; font-size: 14px; color: var(--ink-2); margin-bottom: 18px;
}
.notice.err { border-left-color: var(--danger); color: #7e3232; background: #fcf7f7; }
.notice.warn { border-left-color: var(--warn); color: #7d4a22; background: #fdf9f4; }
.center { text-align: center; }
.hide { display: none !important; }
.spacer { flex: 1; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

.teacher-entry { text-align: center; margin: 48px 0 0; }
.teacher-entry a {
  font-size: 12px; color: var(--ink-3); text-decoration: none;
  letter-spacing: .06em; padding: 6px 10px; border-radius: 6px;
}
.teacher-entry a:hover { color: var(--ink-2); background: var(--line-2); }

.manual { margin-top: 16px; border-top: 1px solid var(--line-2); padding-top: 14px; }
.manual > summary { cursor: pointer; font-size: 12px; color: var(--ink-3); font-weight: 600; list-style: none; }
.manual > summary::-webkit-details-marker { display: none; }
.manual > summary::before { content: '▸ '; }
.manual[open] > summary::before { content: '▾ '; }

details.card > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '＋'; color: var(--ink-3); font-size: 15px; }
details.card[open] > summary::after { content: '－'; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 14px);
  max-width: min(520px, calc(100vw - 32px));
  background: #7e3232; color: #fff; font-size: 14px; font-weight: 600; line-height: 1.5;
  padding: 12px 18px; border-radius: 9px;
  box-shadow: 0 8px 28px -10px rgba(22, 21, 29, .5);
  opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #2f5c48; }

.bar {
  position: sticky; bottom: 0; background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  padding: 13px 24px; margin: 24px -24px -80px;
}
.bar-inner {
  max-width: 900px; margin: 0 auto; width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}

@media (max-width: 720px) {
  .nowside { flex: 1 1 100%; flex-direction: row; }
  .sidebox { flex: 1; }
}
@media (max-width: 620px) {
  .wrap { padding: 24px 16px 80px; }
  h1 { font-size: 23px; }
  .quest-title { font-size: 19px; }
  .bar { margin: 24px -16px -80px; padding: 12px 16px; }
  .roomcode { font-size: 38px; }
  .field-row { flex-direction: column; gap: 0; }
  .gauge { grid-template-columns: 1fr auto; }
  .gauge .who { grid-column: 1 / -1; }
}

/* ---------- 動畫 ---------- */
@keyframes pop { 0% { transform: scale(1); } 38% { transform: scale(1.16); } 100% { transform: scale(1); } }
.pop { animation: pop .42s cubic-bezier(.34, 1.56, .64, 1); }

/* 刻意不用 opacity：分頁在背景時 CSS 動畫不會前進，
   凍在 0% 的話徽記就整個消失 —— 揭曉的那一刻不能空白。 */
@keyframes popIn {
  0% { transform: scale(.4) rotate(-10deg); }
  60% { transform: scale(1.1) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}
.pop-in { animation: popIn .6s cubic-bezier(.34, 1.56, .64, 1); }

@keyframes riseIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.rise-in > * { animation: riseIn .38s ease; }

@keyframes pulseDot { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.7); } }
.pill.live::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; animation: pulseDot 1.4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .pop, .pop-in, .rise-in > *, .pill.live::before { animation: none !important; }
  .opt, .cell { transition: none; }
}

/* ---------- 紙本冒險卡（列印） ---------- */
/* 5 題 x 5 個選項 = 25 行，A5 塞得很剛好：
   「我選」的格子挪到題目同一行，選項壓成 7.5pt，才不會溢出到第二頁。 */
.sheet {
  width: 148mm; height: 210mm; margin: 0 auto 10mm; padding: 7mm 9mm;
  background: #fff; border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sheet h2 { font-size: 12pt; text-align: center; margin: 0 0 1mm; }
.sheet .sub { text-align: center; font-size: 7pt; color: var(--ink-2); margin: 0 0 2mm; }
.sheet .idline { display: flex; gap: 6mm; font-size: 8.5pt; margin-bottom: 2.5mm; }
.sheet .idline span { flex: 1; border-bottom: 1px solid var(--ink); padding-bottom: .8mm; }
.sheet .q { margin-bottom: 1mm; }
.sheet .qhead { display: flex; align-items: center; gap: 3mm; }
.sheet .qhead b { font-size: 9pt; flex: 1; }
.sheet .qhead .pick { font-size: 7.5pt; color: var(--ink-2); flex: none; }
.sheet .box {
  width: 9mm; height: 6mm; border: 1px solid var(--ink); border-radius: 1.2mm; flex: none;
}
.sheet .q ul {
  margin: .8mm 0 0; padding: 0; list-style: none;
  font-size: 7.5pt; line-height: 1.24;
}
.sheet .q ul b { display: inline-block; width: 4.2mm; }
.sheet .tally-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 1.5mm; margin: 1.5mm 0 2mm;
  text-align: center; font-size: 8pt;
}
.sheet .tally-grid div { border: 1px solid var(--ink); border-radius: 1.2mm; padding: 1mm 0; }
.sheet .tally-grid div b { display: block; height: 5mm; }
.sheet .foot { margin-top: auto; }
@media print {
  body { background: #fff; }
  .noprint { display: none !important; }
  .sheet { border: 0; margin: 0; page-break-after: always; }
  .wrap { padding: 0; max-width: none; }
}
