:root {
  --ink: #332c24;
  --text: #1d1d1f;
  --brown: #8a4b17;
  --red: #e03c2c;
  --paper: #fff;
  --c0: #e5484d; --c1: #1f6feb; --c2: #f2b705; --c3: #2f9e44;
  color: var(--text);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  background: #fff7e6;
}
* { box-sizing: border-box; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }

.screen {
  position: relative; min-height: 100vh; padding: 32px; overflow-x: hidden;
  background:
    repeating-linear-gradient(90deg, #ffffff8a 0 22px, #ffdead40 22px 44px),
    linear-gradient(120deg, #fff7e6, #fce6f0 45%, #e4f4ff);
}
@media (max-width: 640px) { .screen { padding: 16px; } }

.card {
  border: 2px solid var(--ink); border-radius: 8px; background: var(--paper);
  padding: 24px; box-shadow: 8px 8px var(--ink);
}
.eyebrow { color: var(--brown); font-weight: 700; margin-bottom: 4px; font-size: 14px; }
.muted { color: #6b6259; }
.error { color: #b3261e; font-weight: 700; }
.ok { color: #2f7d32; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border: 2px solid var(--ink); border-radius: 8px;
  font-weight: 800; background: #fff; color: var(--ink); box-shadow: 4px 4px var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px var(--ink); }
.btn.primary { background: var(--red); color: #fff; }
.btn.blue { background: var(--c1); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 14px; box-shadow: 3px 3px var(--ink); }
.btn.ghost { box-shadow: none; border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.danger { color: #b3261e; }

label { display: block; font-weight: 700; margin: 14px 0 6px; font-size: 15px; }
input[type=text], input[type=password], input:not([type]), textarea, select {
  width: 100%; padding: 12px 14px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; outline: none;
}
input:focus, textarea:focus, select:focus { box-shadow: 0 0 0 3px #f2b70566; }

/* 登入 */
.center { min-height: calc(100vh - 64px); display: grid; place-items: center; }
.login { width: min(420px, 100%); }
.login h1 { font-size: 32px; margin-bottom: 8px; }
.login .btn { margin-top: 22px; }
.login .msg { margin-top: 16px; min-height: 1.4em; }
.lock { font-size: 36px; line-height: 1; margin-bottom: 10px; }

/* 後台 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar h1 { font-size: clamp(28px, 5vw, 52px); }
.title-edit { cursor: pointer; }
.title-edit:hover { text-decoration: underline dotted; }
.title-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.title-form input { font-size: 24px; font-weight: 800; max-width: 420px; }
.account { position: relative; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; border: 2px solid var(--ink); font-size: 12px; font-weight: 800; background: #fff3c4; }
.panel { margin-top: 18px; }
.panel h2 { font-size: 22px; margin-bottom: 12px; }
.tabs { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.tab { font-size: 18px; padding: 12px 22px; }
.tab.active { background: var(--ink); color: #fff; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 500;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 8px; font-weight: 700;
  max-width: 90vw; box-shadow: 4px 4px #0004;
}
.toast.err { background: #b3261e; }

.sets { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin: 14px 0; }
.set-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; cursor: pointer; }
.set-item.active { background: #fff3c4; box-shadow: 4px 4px var(--ink); }
.set-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-actions { display: flex; gap: 4px; flex-shrink: 0; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.q-list { display: grid; gap: 14px; margin-top: 14px; }
.q-card { border: 2px solid var(--ink); border-radius: 8px; background: #fffdf8; padding: 16px; }
.q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.q-head strong { font-size: 18px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
@media (max-width: 640px) { .opts { grid-template-columns: 1fr; } }
.opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--ink); background: #fff; }
.opt input[type=text] { border: 0; padding: 6px; }
.opt input[type=text]:focus { box-shadow: none; }
.opt.correct { background: #d9f7d9; }
.shape { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; color: #fff; font-weight: 900; flex-shrink: 0; }
.s0 { background: var(--c0); } .s1 { background: var(--c1); } .s2 { background: var(--c2); color: var(--ink); } .s3 { background: var(--c3); }
.q-img { max-width: 240px; max-height: 160px; border-radius: 8px; border: 2px solid var(--ink); display: block; margin-top: 8px; }
.collapsed-note { padding: 20px; text-align: center; border: 2px dashed var(--brown); border-radius: 8px; color: var(--brown); font-weight: 800; background: #fffaf0; }
.sticky-save { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; margin-top: 16px; }

table.accounts { width: 100%; border-collapse: collapse; margin-top: 12px; }
table.accounts td, table.accounts th { padding: 10px 8px; border-bottom: 2px solid #332c2420; text-align: left; vertical-align: middle; }
.table-wrap { overflow-x: auto; }

/* 主持畫面（大螢幕） */
.stage { min-height: 100vh; }
.stage-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stage-top h1 { font-size: clamp(28px, 4.5vw, 56px); }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border: 2px solid var(--ink); border-radius: 8px; font-weight: 800; background: #fff; box-shadow: 5px 5px var(--ink); font-size: 20px; }
.lobby { display: grid; grid-template-columns: minmax(280px, 400px) 1fr; gap: 32px; align-items: start; }
@media (max-width: 900px) { .lobby { grid-template-columns: 1fr; } }
.qr-panel { text-align: center; }
.qr-panel img { width: 100%; max-width: 320px; aspect-ratio: 1; display: block; margin: 0 auto 12px; }
.qr-panel .code { font-size: 48px; font-weight: 900; letter-spacing: 6px; }
.qr-panel .url { overflow-wrap: anywhere; font-weight: 700; font-size: 14px; }
.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.name-grid span, .rank-row {
  border: 2px solid var(--ink); border-radius: 8px; background: #fff; padding: 12px 14px; font-size: 20px; font-weight: 800;
  box-shadow: 4px 4px #332c2438; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.name-grid span.pop { animation: pop .25s ease-out; }
.name-grid .more { border-style: dashed; color: var(--brown); background: #fffaf0; cursor: pointer; text-align: center; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.big-title { font-size: clamp(28px, 4vw, 52px); }
.tools { margin-top: 20px; border-style: dashed; box-shadow: none; }
.tools h3 { margin-bottom: 8px; }

.countdown { display: grid; place-items: center; min-height: 70vh; text-align: center; gap: 16px; }
.countdown .num { font-size: 180px; font-weight: 900; line-height: 1; animation: pop .4s; }
.countdown p { font-size: 32px; font-weight: 800; }

.question-view { display: grid; gap: 20px; }
.q-text { font-size: clamp(26px, 4vw, 54px); font-weight: 900; text-align: center; padding: 24px; }
.q-mid { display: grid; grid-template-columns: 140px 1fr 140px; gap: 16px; align-items: center; }
@media (max-width: 700px) { .q-mid { grid-template-columns: 1fr 1fr; } .q-mid .q-stage-img { grid-column: 1 / -1; order: -1; } }
.q-stage-img { text-align: center; }
.q-stage-img img { max-width: 100%; max-height: 38vh; border-radius: 8px; border: 2px solid var(--ink); background: #fff; }
.timer { width: 130px; height: 130px; border-radius: 50%; display: grid; place-items: center; font-size: 52px; font-weight: 900; border: 4px solid var(--ink); background: #fff; }
.answered { text-align: center; font-weight: 800; font-size: 22px; }
.answered b { display: block; font-size: 52px; }
.answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.answer-tile {
  display: flex; align-items: center; gap: 14px; padding: 22px; border-radius: 8px; border: 2px solid var(--ink);
  color: #fff; font-size: clamp(20px, 2.6vw, 34px); font-weight: 900; box-shadow: 5px 5px var(--ink); text-align: left;
}
.answer-tile.t0 { background: var(--c0); } .answer-tile.t1 { background: var(--c1); }
.answer-tile.t2 { background: var(--c2); color: var(--ink); } .answer-tile.t3 { background: var(--c3); }
.answer-tile.dim { opacity: .3; }
.answer-tile .ico { font-size: 1.2em; }

.reveal { display: grid; grid-template-columns: 1.1fr .9fr; gap: 28px; align-items: start; }
@media (max-width: 900px) { .reveal { grid-template-columns: 1fr; } }
.bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: end; height: 260px; margin: 18px 0 10px; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; cursor: pointer; }
.bar { width: 100%; border: 2px solid var(--ink); border-radius: 8px 8px 0 0; min-height: 8px; transition: height .6s ease-out; }
.bar-col .cnt { font-size: 26px; font-weight: 900; }
.bar-col .lab { font-size: 15px; font-weight: 800; text-align: center; }
.bar-col.right .lab::after { content: " ✓"; color: var(--c3); }
.rank-list { display: grid; gap: 10px; }
.rank-row { display: flex; justify-content: space-between; gap: 12px; animation: slideIn .35s ease-out backwards; }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } }
.rank-row .n { overflow: hidden; text-overflow: ellipsis; }

.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: end; margin: 30px auto; max-width: 900px; }
.podium .place { text-align: center; }
.podium .block { border: 2px solid var(--ink); border-radius: 8px 8px 0 0; box-shadow: 6px 6px var(--ink); display: grid; place-items: center; font-size: 56px; font-weight: 900; color: #fff; }
.podium .p1 .block { height: 240px; background: #f2b705; color: var(--ink); }
.podium .p2 .block { height: 180px; background: #9aa4b1; }
.podium .p3 .block { height: 130px; background: #c27c4a; }
.podium .who { font-size: clamp(20px, 2.5vw, 32px); font-weight: 900; margin-bottom: 4px; overflow-wrap: anywhere; }
.podium .pts { font-weight: 800; margin-bottom: 10px; }
.confetti { position: fixed; top: -20px; width: 10px; height: 16px; z-index: 50; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.modal-overlay { position: fixed; inset: 0; background: #0000007a; display: flex; align-items: center; justify-content: center; z-index: 300; padding: 16px; }
.modal-box { width: min(620px, 100%); max-height: 80vh; display: flex; flex-direction: column; gap: 14px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-body { overflow-y: auto; }
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.chip-grid span { padding: 8px 10px; border: 2px solid var(--ink); border-radius: 8px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 留言牆 */
.wall-layout { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .wall-layout { grid-template-columns: 1fr; } }
.wall-board { position: relative; min-height: 70vh; overflow: hidden; }
.msg-cards { columns: 3 260px; column-gap: 16px; }
.msg-card { break-inside: avoid; margin-bottom: 16px; border: 2px solid var(--ink); border-radius: 8px; padding: 16px; box-shadow: 5px 5px var(--ink); animation: pop .35s ease-out; position: relative; }
.msg-card p { font-size: 22px; font-weight: 800; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-card small { display: block; margin-top: 8px; font-weight: 700; color: #5a4f45; }
.msg-card .hide-btn { position: absolute; top: 6px; right: 6px; opacity: 0; }
.msg-card:hover .hide-btn { opacity: 1; }
.m0 { background: #fff3c4; } .m1 { background: #dff1ff; } .m2 { background: #ffe1ea; } .m3 { background: #e3f8e0; } .m4 { background: #f0e6ff; }
.danmaku { position: absolute; inset: 0; overflow: hidden; }
.danmaku .dm {
  position: absolute; left: 100%; white-space: nowrap; font-size: 34px; font-weight: 900; padding: 6px 16px;
  border: 2px solid var(--ink); border-radius: 99px; box-shadow: 4px 4px var(--ink); animation: fly linear forwards;
}
@keyframes fly { to { transform: translateX(calc(-100vw - 100%)); } }
.wall-side .qr-panel img { max-width: 240px; }
.fs-mode .wall-side .hide-list, .fs-mode .stage-top .controls { display: none; }
.empty { display: grid; place-items: center; min-height: 50vh; font-size: 26px; font-weight: 800; color: var(--brown); text-align: center; }

/* 玩家手機端 */
.phone { max-width: 520px; margin: 0 auto; }
.phone .card { margin-top: 12px; }
.phone-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; gap: 8px; }
.phone-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.phone-answers .answer-tile { min-height: 120px; justify-content: center; flex-direction: column; text-align: center; font-size: 20px; gap: 6px; }
.phone-answers .answer-tile .ico { font-size: 40px; }
.phone-answers .answer-tile.picked { outline: 5px solid var(--ink); outline-offset: 3px; }
.status-big { text-align: center; padding: 28px 12px; }
.status-big .emoji { font-size: 64px; }
.status-big h2 { font-size: 28px; margin: 8px 0; }
.status-big p { font-size: 18px; font-weight: 700; }
.result-ok { background: #d9f7d9; }
.result-bad { background: #ffe0dc; }
