@font-face {
  font-family: 'Cubic11';
  src: url('fonts/Cubic_11.woff2') format('woff2');
  font-display: swap;
}
:root {
  --ink: #2b2235;
  --paper: #fff8ec;
  --paper-2: #ffeccf;
  --accent: #ef5f6b;
  --accent-2: #ff8f97;
  --ok: #4caf6a;
  --muted: #7a6f86;
  --shadow: 0 4px 0 rgba(43, 34, 53, 0.35);
  --font: 'Cubic11', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3e7d3a; color: var(--ink); font-family: var(--font); font-size: 16px; }
[hidden] { display: none !important; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; image-rendering: pixelated; touch-action: none; }
button, input { font-family: inherit; font-size: inherit; color: inherit; }
code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: rgba(43,34,53,.08); padding: 1px 4px; word-break: break-all; }

/* ---------- 共用元件 ---------- */
.panel {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 -4px 0 var(--paper-2);
  padding: 20px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: #fff; border: 3px solid var(--ink); border-radius: 6px;
  padding: 8px 14px; cursor: pointer; box-shadow: 0 3px 0 var(--ink);
  text-decoration: none; line-height: 1.2; white-space: nowrap;
  transition: transform .06s, box-shadow .06s;
}
.btn:hover { background: #fff3dc; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #f4737e; }
.btn.danger { background: #ffe1e1; }
.btn.small { padding: 4px 10px; font-size: 14px; border-width: 2px; box-shadow: 0 2px 0 var(--ink); }
.btn.big { padding: 12px 28px; font-size: 20px; }
.btn.on { background: #ffd23f; }
input[type=text], input:not([type]), input[type=url], input[type=password] {
  width: 100%; padding: 9px 10px; border: 3px solid var(--ink); border-radius: 6px; background: #fff; outline: none;
}
input:focus { border-color: var(--accent); }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
label input { margin-top: 4px; color: var(--ink); font-size: 16px; }
.err { color: var(--accent); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.6; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.stack { display: grid; gap: 8px; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 18px 0 8px; font-size: 16px; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; padding: 16px; }
.overlay.dim { background: rgba(43, 34, 53, .45); }
.dialog { width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.dialog.wide { width: min(760px, 100%); }
.dialog.narrow { width: min(340px, 100%); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }

/* ---------- 進場 ---------- */
#join { background: radial-gradient(circle at 50% 40%, rgba(255,248,236,.25), rgba(43,34,53,.55)); }
.join-panel { width: min(560px, 100%); text-align: center; }
.join-panel h1 { margin: 0 0 4px; font-size: 30px; color: var(--accent); text-shadow: 3px 3px 0 #ffd6da; letter-spacing: 2px; }
.sub { margin: 0 0 18px; color: var(--muted); }
.join-body { display: flex; gap: 20px; align-items: center; text-align: left; margin-bottom: 18px; }
#preview { width: 128px; height: 160px; image-rendering: pixelated; background: #b9e59d; border: 3px solid var(--ink); border-radius: 6px; flex: none; }
.join-form { flex: 1; min-width: 0; }
.picker { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.picker > span { width: 36px; font-size: 14px; color: var(--muted); flex: none; }
.swatches, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border: 3px solid var(--ink); border-radius: 4px; cursor: pointer; padding: 0; }
.swatch.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip { border: 2px solid var(--ink); border-radius: 4px; background: #fff; padding: 3px 8px; cursor: pointer; font-size: 14px; }
.chip.sel { background: var(--accent); color: #fff; }
@media (max-width: 520px) {
  .join-body { flex-direction: column; }
  #preview { width: 96px; height: 120px; }
}

/* ---------- HUD ---------- */
#hud { position: fixed; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; gap: 8px; pointer-events: none; z-index: 10; }
#hud > div { display: flex; gap: 8px; flex-wrap: wrap; pointer-events: auto; align-items: flex-start; }
.hud-right { justify-content: flex-end; }
.pill { background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 4px 12px; font-size: 14px; box-shadow: 0 2px 0 var(--ink); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emote-bar { position: fixed; top: 52px; right: 10px; display: flex; gap: 4px; background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; padding: 4px; z-index: 11; box-shadow: 0 2px 0 var(--ink); }
.emote-bar button { font-size: 22px; background: none; border: none; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.emote-bar button:hover { background: var(--paper-2); }
.banner {
  position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 12;
  background: #fff6c2; border: 3px solid var(--ink); border-radius: 6px; padding: 8px 10px 8px 14px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; white-space: nowrap; max-width: calc(100vw - 20px);
  animation: bob 1.4s ease-in-out infinite;
}
#presBannerTitle { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; display: inline-block; vertical-align: bottom; }
@keyframes bob { 50% { transform: translate(-50%, -3px); } }
#help { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); white-space: nowrap; z-index: 5; pointer-events: none; }
#chatLog { position: fixed; left: 10px; bottom: 64px; width: min(360px, 70vw); display: flex; flex-direction: column; gap: 3px; z-index: 6; pointer-events: none; }
#chatLog div { background: rgba(43, 34, 53, .72); color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 14px; width: fit-content; max-width: 100%; word-break: break-word; transition: opacity 1s; }
#chatLog div.old { opacity: 0; }
#chatLog b { color: #ffd23f; font-weight: normal; }
#chatLog b.admin { color: #ff9fbf; }
#chatForm { position: fixed; left: 10px; bottom: 28px; width: min(420px, calc(100vw - 20px)); z-index: 20; }
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 6px; font-size: 15px; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

/* ---------- 手機 ---------- */
#touchUI { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
#stick { position: absolute; left: 24px; bottom: 40px; width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,.25); border: 3px solid rgba(43,34,53,.5); pointer-events: auto; touch-action: none; }
#knob { position: absolute; left: 35px; top: 35px; width: 44px; height: 44px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); }
#touchA { position: absolute; right: 28px; bottom: 60px; width: 72px; height: 72px; border-radius: 50%; font-size: 26px; pointer-events: auto; background: #ffd23f; }
#touchChat { position: absolute; right: 112px; bottom: 40px; width: 52px; height: 52px; border-radius: 50%; pointer-events: auto; }

/* ---------- 簡報視窗 ---------- */
.pres-modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 0; background: rgba(43,34,53,.55); }
.pres-win { width: min(90vw, calc((90vh - 46px) * 16 / 9)); display: flex; flex-direction: column; background: var(--ink); border: 3px solid var(--ink); border-radius: 8px; box-shadow: 0 6px 0 rgba(0,0,0,.35); overflow: hidden; }
.pres-head { display: flex; align-items: center; gap: 10px; padding: 4px 8px; min-height: 40px; background: var(--paper); flex-wrap: wrap; }
.pres-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 120px; min-width: 0; }
.pres-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.pres-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.pres-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #11121c; overflow: hidden; }
.pres-frame { position: absolute; transform-origin: 0 0; width: 1280px; height: 720px; background: #fff; }
.pres-frame iframe { width: 1280px; height: 720px; border: 0; display: block; background: #fff; }
.pres-mirror { position: absolute; inset: 0; background: #fff; overflow: hidden; }
.pres-mirror .replayer-wrapper { position: relative; }
.pres-mirror iframe { border: 0; display: block; }
.pres-shield { position: absolute; inset: 0; cursor: default; }
.pres-shield.laser-mode { cursor: crosshair; }
.laser { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: radial-gradient(circle, #fff 0 15%, #ff2d2d 30%, rgba(255,45,45,.5) 55%, rgba(255,45,45,0) 72%); pointer-events: none; }
.pres-pill { position: fixed; right: 12px; bottom: 12px; z-index: 25; animation: pop .25s ease-out; }
body:not(.is-admin) .admin-only { display: none; }

/* ---------- NPC / 成果牆 ---------- */
.npc-talk { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 6px; }
#npcFace { width: 64px; height: 80px; image-rendering: pixelated; background: #f7cfdd; border: 3px solid var(--ink); border-radius: 6px; flex: none; }
.npc-text p { margin: 6px 0 0; line-height: 1.6; min-height: 3.2em; }
.assign-name { background: var(--paper-2); border-radius: 4px; padding: 6px 10px; font-size: 14px; }
.wall-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.card { background: #fff; border: 3px solid var(--ink); border-radius: 6px; padding: 10px 12px; box-shadow: 0 3px 0 var(--ink); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card:nth-child(4n+1) { background: #fff6c2; } .card:nth-child(4n+2) { background: #e2f1ff; }
.card:nth-child(4n+3) { background: #ffe3ec; } .card:nth-child(4n) { background: #e3f7dd; }
.card .who { font-size: 13px; color: var(--muted); }
.card .ttl { font-size: 17px; overflow-wrap: anywhere; }
.card .note { font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.card a { color: #3a63c9; font-size: 13px; overflow-wrap: anywhere; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; grid-column: 1 / -1; }

/* ---------- 講師面板 ---------- */
.admin-panel {
  position: fixed; top: 52px; right: 10px; bottom: 10px; width: min(380px, calc(100vw - 20px)); z-index: 40;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 6px; box-shadow: var(--shadow);
  padding: 14px; overflow: auto;
}
.tabs { display: flex; gap: 6px; border-bottom: 3px solid var(--ink); margin-bottom: 10px; }
.tab { background: var(--paper-2); border: 3px solid var(--ink); border-bottom: none; border-radius: 6px 6px 0 0; padding: 6px 14px; cursor: pointer; margin-bottom: -3px; }
.tab.active { background: var(--paper); }
.now-box { background: #fff; border: 2px dashed var(--ink); border-radius: 6px; padding: 10px; font-size: 14px; line-height: 1.6; }
.now-box .row-wrap { margin-top: 8px; }
.list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.list .item { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--ink); border-radius: 4px; padding: 6px 8px; font-size: 14px; }
.list .item .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item a { color: #3a63c9; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); margin-top: 14px; }
hr { border: none; border-top: 2px dashed rgba(43,34,53,.3); margin: 16px 0; }
