:root {
  --paper: #efe6d2;
  --paper2: #f7f1e3;
  --ink: #1d1a17;
  --ink2: #4a443c;
  --ink3: #8a8070;
  --red: #a8322a;
  --gold: #b8923a;
  --jade: #5d7a8c;
  --font: "Kaiti TC", "BiauKai", "DFKai-SB", "LXGW WenKai TC", serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--font); -webkit-user-select: none; user-select: none; touch-action: none; }
button { font-family: inherit; cursor: pointer; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; }

/* 宣紙紋理與暈邊 */
.paper-grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 5; mix-blend-mode: multiply; opacity: .5;
  background:
    radial-gradient(ellipse at center, transparent 50%, rgba(50, 38, 25, .5) 100%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .28  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); font-size: 28px; letter-spacing: .3em; z-index: 50; }

/* 印章 */
.seal { display: inline-block; background: var(--red); color: var(--paper2); padding: 4px 10px; border-radius: 4px; font-weight: 700; letter-spacing: .15em; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); transform: rotate(-2deg); }
.seal.big { font-size: 22px; padding: 8px 14px; }

/* 標題畫面 */
#title { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: rgba(239, 230, 210, .78); backdrop-filter: blur(2px); }
.title-wrap { display: flex; gap: 40px; align-items: center; padding: 16px; max-width: 760px; }
.vtitle { writing-mode: vertical-rl; font-size: clamp(64px, 12vw, 120px); margin: 0; letter-spacing: .2em; line-height: 1; text-shadow: 3px 3px 0 rgba(0, 0, 0, .08); }
.title-side { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.subtitle { font-size: 20px; margin: 0; color: var(--ink2); }
.group-pick p { margin: 6px 0; color: var(--ink2); }
.btn { display: block; width: 100%; min-width: 260px; text-align: left; font-size: 22px; padding: 12px 18px; margin: 8px 0; background: var(--paper2); color: var(--ink); border: 2px solid var(--ink); border-radius: 10px 4px 12px 4px; box-shadow: 4px 4px 0 var(--ink); transition: transform .1s; }
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn small { display: block; font-size: 14px; color: var(--ink3); margin-top: 2px; }
.btn.ghost { background: transparent; box-shadow: none; text-align: center; font-size: 18px; }
.btn.red { background: var(--red); color: var(--paper2); }
.btn.sm { min-width: 0; width: auto; display: inline-block; font-size: 16px; padding: 8px 14px; margin: 4px; box-shadow: 3px 3px 0 var(--ink); text-align: center; }
.credit { font-size: 14px; color: var(--ink3); }
.credit a { color: var(--red); }
@media (max-width: 600px) {
  .title-wrap { flex-direction: column; gap: 12px; }
  .vtitle { writing-mode: horizontal-tb; font-size: 56px; }
  .btn { min-width: 0; font-size: 19px; }
}

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.hud-tl { position: absolute; top: 14px; left: 14px; background: rgba(247, 241, 227, .85); border: 2px solid var(--ink); border-radius: 8px; padding: 8px 12px; pointer-events: none !important; }
.hud-count { font-size: 20px; margin-top: 6px; }
.hud-count span { font-size: 28px; color: var(--red); font-weight: 700; }
.hud-sub { font-size: 14px; color: var(--ink2); }
#minimap { position: absolute; top: 14px; right: 14px; width: 170px; height: 150px; border: 2px solid var(--ink); border-radius: 8px; background: var(--paper2); pointer-events: none !important; }
#prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(29, 26, 23, .82); color: var(--paper2); padding: 8px 16px; border-radius: 20px; font-size: 18px; white-space: nowrap; pointer-events: none !important; }
.hud-br { position: absolute; right: 16px; bottom: 18px; display: flex; gap: 14px; align-items: flex-end; }
.round { width: 74px; height: 74px; border-radius: 50%; border: 3px solid var(--ink); font-size: 19px; font-weight: 700; box-shadow: 3px 3px 0 var(--ink); }
.round.act { background: var(--red); color: var(--paper2); width: 88px; height: 88px; font-size: 22px; }
.round.phone { background: var(--paper2); color: var(--ink); }
#joy { position: absolute; left: 22px; bottom: 22px; width: 130px; height: 130px; border-radius: 50%; border: 3px dashed rgba(29, 26, 23, .5); background: rgba(247, 241, 227, .4); display: none; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: var(--ink); opacity: .75; }
body.touch #joy { display: block; }
#toasts { position: absolute; top: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none !important; }
.toast { background: var(--paper2); border: 2px solid var(--ink); border-left: 8px solid var(--red); padding: 8px 18px; border-radius: 6px; font-size: 18px; box-shadow: 3px 3px 0 rgba(0, 0, 0, .2); animation: toastIn .3s ease-out; }
.toast.gold { border-left-color: var(--gold); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }

/* 對話框 */
#dialog { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(720px, calc(100% - 32px)); z-index: 20; background: var(--paper2); border: 3px solid var(--ink); border-radius: 12px 4px 14px 4px; padding: 16px 20px; box-shadow: 6px 6px 0 rgba(29, 26, 23, .7); }
.dlg-name { position: absolute; top: -18px; left: 18px; background: var(--ink); color: var(--paper2); padding: 2px 14px; border-radius: 4px; font-size: 18px; }
.dlg-text { font-size: 21px; line-height: 1.7; min-height: 2em; }
.dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.dlg-choices button { font-size: 18px; padding: 8px 16px; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; }
.dlg-choices button:hover { background: var(--ink); color: var(--paper2); }

/* 面板 */
#panel { position: fixed; inset: 0; z-index: 25; background: rgba(29, 26, 23, .45); display: grid; place-items: center; padding: 12px; }
.panel-inner { position: relative; width: min(820px, 100%); max-height: calc(100vh - 24px); overflow: auto; background: var(--paper2); border: 3px solid var(--ink); border-radius: 14px 4px 16px 4px; padding: 22px 22px 26px; box-shadow: 8px 8px 0 rgba(29, 26, 23, .6); -webkit-user-select: text; user-select: text; touch-action: pan-y; }
.panel-close { position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper); font-size: 18px; z-index: 2; }
.panel-inner h2 { margin: 0 0 6px; font-size: 28px; letter-spacing: .1em; }
.panel-inner h3 { margin: 16px 0 6px; font-size: 20px; }
.muted { color: var(--ink3); font-size: 15px; }
.tabs { display: flex; gap: 6px; margin: 8px 0 14px; flex-wrap: wrap; padding-right: 44px; }
.tabs button { font-size: 17px; padding: 6px 16px; border: 2px solid var(--ink); background: var(--paper); border-radius: 18px; }
.tabs button.on { background: var(--ink); color: var(--paper2); }
.phone-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-right: 44px; }

.quest { border: 2px solid var(--ink); border-radius: 8px; padding: 10px 14px; margin: 10px 0; background: var(--paper); }
.quest.done { border-color: var(--gold); background: #f6edd2; }
.quest-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.quest-title { font-size: 20px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 16px; padding: 3px 10px; border-radius: 4px; background: var(--paper2); border: 1px dashed var(--ink3); color: var(--ink3); }
.chip.got { border: 1px solid var(--ink); color: var(--ink); background: #fffaf0; }

/* 拼詩 */
.slots { display: grid; gap: 10px; margin: 14px 0; }
.slot { display: flex; align-items: center; gap: 10px; min-height: 58px; border: 2px dashed var(--ink3); border-radius: 8px; padding: 6px 12px; background: var(--paper); font-size: 24px; letter-spacing: .12em; }
.slot.filled { border-style: solid; border-color: var(--ink); background: #fffaf0; cursor: pointer; }
.slot .num { font-size: 15px; color: var(--paper2); background: var(--ink3); border-radius: 50%; min-width: 28px; height: 28px; display: grid; place-items: center; letter-spacing: 0; }
.slot.filled .num { background: var(--red); }
.cards { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.card { font-family: inherit; font-size: 22px; letter-spacing: .1em; padding: 10px 14px; border: 2px solid var(--ink); border-radius: 6px; background: #fffaf0; box-shadow: 3px 3px 0 var(--ink); }
.card.used { opacity: .25; pointer-events: none; }
.card.hint { outline: 3px solid var(--gold); }
.feedback { min-height: 1.6em; font-size: 18px; color: var(--red); }
.hintbox { background: #f4ecd6; border-left: 5px solid var(--gold); padding: 8px 12px; margin: 8px 0; font-size: 17px; line-height: 1.6; }
ruby rt { font-size: 11px; letter-spacing: 0; color: var(--red); }

/* 詩卡 */
.poem-lines { margin: 14px 0; }
.pl { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px dashed rgba(29, 26, 23, .2); }
.pl .fn { width: 40px; height: 40px; display: grid; place-items: center; background: var(--red); color: var(--paper2); border-radius: 6px; font-size: 20px; font-weight: 700; }
.pl .txt { font-size: 26px; letter-spacing: .15em; }
.pl .tr, .pl .fd { font-size: 16px; color: var(--ink2); letter-spacing: 0; margin-top: 2px; }
.pl .fd { color: var(--red); }
.note { border-bottom: 2px dotted var(--red); cursor: help; }
.notes { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.notes span { font-size: 15px; background: var(--paper); border: 1px solid var(--ink3); padding: 3px 8px; border-radius: 4px; }
.author { display: flex; gap: 12px; align-items: flex-start; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: 16px; line-height: 1.6; }
.stars { font-size: 26px; color: var(--gold); letter-spacing: .1em; }
.stars .off { color: rgba(29, 26, 23, .18); }
.star-legend { font-size: 14px; color: var(--ink2); line-height: 1.7; }
.quiz-opt { display: block; width: 100%; text-align: left; font-size: 19px; padding: 12px 14px; margin: 8px 0; background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; }
.quiz-opt.wrong { background: #f0d6d0; border-color: var(--red); opacity: .6; }
.quiz-opt.right { background: #e3ecd6; border-color: #4f6b3a; }
textarea { width: 100%; min-height: 80px; font-family: inherit; font-size: 19px; padding: 10px; border: 2px solid var(--ink); border-radius: 8px; background: #fffaf0; resize: vertical; }

.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dex-card { border: 2px solid var(--ink); border-radius: 8px; padding: 10px; background: var(--paper); text-align: center; min-height: 120px; font-family: inherit; color: var(--ink); }
.dex-card.locked { border-style: dashed; color: var(--ink3); background: transparent; }
.dex-card .t { font-size: 20px; font-weight: 700; margin: 6px 0; }
.dex-card .stars { font-size: 18px; }
.outfits { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.banner { text-align: center; padding: 10px 0; }
.banner .seal { font-size: 30px; padding: 10px 20px; margin: 10px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.kbd { display: inline-block; border: 1px solid var(--ink); border-bottom-width: 3px; border-radius: 4px; padding: 0 6px; font-size: 14px; background: var(--paper); }
