:root {
  --paper: #f7f0df;
  --paper-2: #efe5cd;
  --ink: #2a241e;
  --ink-2: #6b5f50;
  --line: #d9ccb0;
  --cinnabar: #b4382b;
  --gold: #c9962f;
  --kai: "BiauKai", "DFKai-SB", "標楷體", "Kaiti TC", "KaiTi", serif;
  --body: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  --panel: 340px;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; background: #e8efe6; color: var(--ink); font-family: var(--body); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--cinnabar); outline-offset: 2px; }
#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#world:active { cursor: grabbing; }


/* 左上 */
#brand { position: fixed; left: 18px; top: 16px; display: flex; align-items: center; gap: 12px; padding: 10px 18px 10px 11px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 4px 16px rgba(50, 35, 20, .16); }
.seal { width: 48px; height: 48px; display: grid; place-items: center; background: var(--cinnabar); color: #fff4df; font-family: var(--kai); font-size: 19px; line-height: 1.02; text-align: center; padding: 3px 9px; border-radius: 4px; }
#brand h1 { margin: 0; font-family: var(--kai); font-size: 27px; letter-spacing: .07em; line-height: 1.15; }
#brand p { margin: 2px 0 0; font-size: 13px; color: var(--ink-2); }

#tools { position: fixed; left: 18px; top: 98px; display: flex; flex-wrap: wrap; gap: 8px; max-width: calc(100vw - var(--panel) - 36px); }
.group { display: flex; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 3px; box-shadow: 0 2px 9px rgba(50, 35, 20, .12); }
.group button { border: 0; background: none; padding: 7px 11px; font-size: 13px; border-radius: 4px; min-height: 34px; }
.group button:hover { background: var(--paper-2); }
.group button[aria-pressed="true"] { background: var(--ink); color: #fff4df; }

#btn-list { display: none; }

/* 右側清單 */
#panel { position: fixed; right: 0; top: 0; bottom: 0; width: var(--panel); background: var(--paper); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(50, 35, 20, .1); }
.phead { padding: 22px 22px 14px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--cinnabar); font-size: 13px; letter-spacing: .05em; }
.phead h2 { margin: 0 0 14px; font-family: var(--kai); font-size: 25px; line-height: 1.32; }
#search { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 5px; background: #fffaf0; font: inherit; font-size: 14px; color: var(--ink); }
#list { flex: 1; overflow-y: auto; padding: 6px 0 22px; }
.reghead { display: block; width: 100%; border: 0; background: none; text-align: left; padding: 15px 22px 7px; }
.reghead b { display: block; font-family: var(--kai); font-size: 20px; letter-spacing: .12em; }
.reghead span { display: block; margin-top: 1px; color: var(--ink-2); font-size: 13px; }
.reghead:hover b { color: var(--cinnabar); }
.row { width: 100%; display: flex; gap: 10px; align-items: center; padding: 9px 22px; border: 0; background: none; text-align: left; }
.row i { font-family: Georgia, serif; font-size: 17px; color: var(--cinnabar); width: 24px; flex: none; }
.row .t { flex: 1; font-family: var(--kai); font-size: 18px; font-weight: 700; min-width: 0; }
.row small { display: block; font-family: var(--body); font-weight: 400; font-size: 12px; color: var(--ink-2); margin-top: 1px; }
.row .d { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.row:hover, .row.hot { background: var(--paper-2); }
.none { padding: 22px; color: var(--ink-2); font-size: 14px; }

/* 提示 */
#intro { position: fixed; left: calc((100vw - var(--panel)) / 2); bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; background: rgba(42, 36, 30, .93); color: #fff4df; padding: 9px 11px 9px 18px; border-radius: 6px; font-size: 14px; width: max-content; max-width: calc(100vw - var(--panel) - 32px); }
#intro p { margin: 0; }
#intro button { border: 0; background: var(--cinnabar); color: #fff; padding: 7px 13px; border-radius: 4px; flex: none; }

/* 播放器 */
#player { position: fixed; inset: 0; z-index: 30; background: rgba(24, 19, 14, .8); display: grid; place-items: center; padding: 20px; animation: fade .3s ease; overflow-y: auto; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: relative; width: min(1040px, 100%, calc((100vh - 240px) * 16 / 9 + 40px)); min-width: min(600px, 100%); background: var(--paper); border-radius: 8px; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
#p-close { position: absolute; right: -10px; top: -10px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: var(--cinnabar); color: #fff; font-size: 25px; line-height: 1; z-index: 2; box-shadow: 0 3px 10px rgba(0, 0, 0, .35); }
.screen { position: relative; background: #17130f; border-radius: 4px; overflow: hidden; aspect-ratio: 16 / 9; }
#video { width: 100%; height: 100%; display: block; background: #17130f; }
#p-error { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: #fff4df; padding: 20px; text-align: center; }
.info { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; margin-top: 14px; }
#p-title { margin: 0; font-family: var(--kai); font-size: 32px; letter-spacing: .08em; }
#p-meta { margin: 2px 0 8px; font-size: 13px; color: var(--cinnabar); }
#p-summary { margin: 0; font-size: 15px; line-height: 1.65; }
.moral { border-left: 3px solid var(--cinnabar); padding-left: 14px; }
.moral h3 { margin: 3px 0 5px; font-family: var(--kai); font-size: 17px; }
.moral p { margin: 0; font-size: 15px; line-height: 1.65; }
.nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 13px; }
.nav button { border: 1px solid var(--line); background: #fffaf0; padding: 7px 14px; border-radius: 5px; font-size: 14px; min-height: 38px; }
.nav button:hover { background: var(--paper-2); }
.nav span { font-family: var(--kai); font-size: 16px; }
#p-next.pulse { background: var(--cinnabar); color: #fff; border-color: var(--cinnabar); animation: pulse 1.3s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }

#nowebgl { position: fixed; left: 20px; top: 110px; max-width: 320px; padding: 14px; background: var(--paper); border: 1px solid var(--line); }

/* 手機與窄視窗:清單改成底部抽屜 */
@media (max-width: 860px) {
  :root { --panel: 0px; }
  #brand { left: 10px; top: 10px; padding: 6px 12px 6px 7px; gap: 8px; }
  .seal { width: 38px; height: 38px; font-size: 15px; padding: 2px 7px; }
  #brand h1 { font-size: 20px; }
  #brand p { font-size: 11px; margin-top: 0; }
  #tools { left: 10px; right: 10px; top: 70px; max-width: none; gap: 5px; }
  .group button { padding: 5px 7px; font-size: 12px; min-height: 32px; }
  #btn-list { display: block; position: fixed; right: 12px; bottom: 16px; z-index: 11; border: 0; background: var(--cinnabar); color: #fff; padding: 11px 17px; border-radius: 6px; font-family: var(--kai); font-size: 17px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
  #panel { z-index: 10; top: auto; left: 0; right: 0; bottom: 0; width: auto; height: 74vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 12px 12px 0 0; transform: translateY(102%); transition: transform .28s ease; }
  .panel-open #panel { transform: none; }
  .phead { padding: 15px 16px 11px; }
  .phead h2 { display: none; }
  .reghead, .row { padding-left: 16px; padding-right: 16px; }
  #intro { left: 12px; right: 116px; bottom: 16px; transform: none; font-size: 12px; width: auto; max-width: none; padding: 7px 8px 7px 11px; gap: 8px; }
  #intro button { padding: 5px 8px; }
  #player { padding: 10px; place-items: start center; }
  .sheet { min-width: 0; width: 100%; padding: 10px; margin-top: 18px; }
  #p-close { right: 4px; top: -14px; }
  .info { grid-template-columns: 1fr; gap: 11px; }
  #p-title { font-size: 25px; }
  .nav span { font-size: 14px; }
}
@media (prefers-reduced-motion: reduce) { #player, #p-next.pulse { animation: none; } #panel { transition: none; } }

/* ---------- 精緻版 ---------- */
#loader { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--paper); transition: opacity .7s ease; color: var(--ink-2); font-family: var(--kai); font-size: 18px; letter-spacing: .3em; }
#loader.done { opacity: 0; pointer-events: none; }
#loader p { margin: 0; }
.seal.big { width: 76px; height: 76px; font-size: 30px; padding: 5px 15px; }
#peek { position: fixed; z-index: 5; width: 186px; padding: 7px 7px 9px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(40, 28, 16, .3); pointer-events: none; }
#peek img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; object-position: top; border-radius: 3px; background: var(--paper-2); }
#peek b { display: block; margin: 7px 3px 0; font-family: var(--kai); font-size: 18px; }
#peek span { display: block; margin: 0 3px; font-size: 12px; color: var(--ink-2); }
#panel { background: linear-gradient(180deg, #faf4e6, var(--paper) 30%, #f3ead6); }
.reghead { position: sticky; top: 0; z-index: 1; background: linear-gradient(180deg, #f7f0df 80%, rgba(247, 240, 223, 0)); }
.reghead b::before { content: ""; display: inline-block; width: 9px; height: 9px; margin: 0 8px 2px 0; background: var(--cinnabar); transform: rotate(45deg); }
.row { padding-top: 7px; padding-bottom: 7px; }
.row img { width: 66px; height: 42px; flex: none; object-fit: cover; object-position: top; border-radius: 3px; background: var(--paper-2); border: 1px solid var(--line); }
.row i { width: 20px; font-size: 15px; }
.row .t { font-size: 17px; }
.row:hover img, .row.hot img { border-color: var(--cinnabar); }
@media (max-width: 860px) { #peek { display: none; } }
/* 播放器不超過視窗高度 */
@media (min-width: 861px) { .sheet { width: min(1040px, 100%, calc((100vh - 310px) * 16 / 9 + 40px)); } }

#nowebgl { z-index: 9; }
a.row { color: inherit; text-decoration: none; font-family: var(--kai); font-size: 18px; }

/* 中央廣場:粉專連結 */
#follow { position: fixed; inset: 0; z-index: 31; background: rgba(24, 19, 14, .72); display: grid; place-items: safe center; padding: 24px 16px; overflow-y: auto; animation: fade .3s ease; }
#btn-follow { position: fixed; right: calc(var(--panel) + 18px); top: 16px; z-index: 5; border: 1px solid var(--line); background: var(--paper); color: var(--cinnabar); padding: 10px 16px; border-radius: 6px; font-family: var(--kai); font-size: 18px; font-weight: 700; letter-spacing: .08em; box-shadow: 0 4px 16px rgba(50, 35, 20, .16); }
#btn-follow:hover { background: var(--paper-2); }
.fsheet { position: relative; width: min(380px, 100%); background: var(--paper); border-radius: 8px; padding: 26px 22px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.fsheet .seal { margin: 0 auto 10px; }
.fsheet h2 { margin: 0; font-family: var(--kai); font-size: 26px; letter-spacing: .1em; }
.fsheet p { margin: 6px 0 18px; color: var(--ink-2); font-size: 14px; }
.flinks { display: grid; gap: 10px; }
.flinks a { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border: 1px solid var(--line); border-radius: 6px; background: #fffaf0; color: var(--ink); text-decoration: none; }
.flinks a:hover, .flinks a:focus-visible { border-color: var(--cinnabar); background: var(--paper-2); outline: none; }
.flinks b { font-size: 16px; }
.flinks span { color: var(--cinnabar); font-size: 13px; }
#f-close { position: absolute; right: -10px; top: -10px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--cinnabar); color: #fff; font-size: 24px; line-height: 1; box-shadow: 0 3px 10px rgba(0, 0, 0, .35); }
@media (max-width: 860px) { #f-close { right: 4px; top: -14px; } #btn-follow { right: 10px; top: 10px; padding: 7px 11px; font-size: 15px; } }
@media (prefers-reduced-motion: reduce) { #follow { animation: none; } }

/* ---------- 新故事「新」印章、版本 ---------- */
.new-seal {
  display: inline-grid; place-items: center; width: 1.45em; height: 1.45em; margin-left: 6px; vertical-align: .1em;
  border-radius: 50%; background: var(--cinnabar); color: #fff4df; box-shadow: inset 0 0 0 1.5px #b4382b, inset 0 0 0 2.5px #f7e3c2;
  font: 700 15px/1 var(--kai); font-style: normal; transform: rotate(-12deg); position: relative;
  animation: seal-bob 2.4s ease-in-out infinite;
}
.new-seal::after {                       /* 小金星 */
  content: ""; position: absolute; right: -6px; top: -5px; width: 7px; height: 7px; background: #e8b64a;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: seal-twinkle 2.4s ease-in-out infinite;
}
@keyframes seal-bob { 0%, 100% { transform: rotate(-12deg) translateY(0); } 50% { transform: rotate(-8deg) translateY(-2px); } }
@keyframes seal-twinkle { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .45; transform: scale(.7); } }
.row .vers { display: inline-block; margin-top: 3px; padding: 0 6px; border: 1px solid var(--line); border-radius: 9px;
  font: 400 11px/16px var(--body); font-style: normal; color: var(--ink-2); }
#btn-list.has-new::after { content: "新"; display: inline-grid; place-items: center; width: 18px; height: 18px; margin-left: 6px;
  border-radius: 50%; background: #fff4df; color: var(--cinnabar); font: 700 11px/1 var(--kai); transform: rotate(-12deg); }
.phead .has-new-note { color: var(--cinnabar); }
#p-vers { display: flex; gap: 6px; margin: 2px 0 6px; flex-wrap: wrap; }
#p-vers[hidden] { display: none; }
#p-vers button { padding: 3px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper);
  font: 700 14px var(--kai); color: var(--ink-2); cursor: pointer; }
#p-vers button[aria-selected="true"] { background: var(--cinnabar); border-color: var(--cinnabar); color: #fff4df; }
#p-vers button .new-seal { font-size: 12px; margin-left: 4px; }
#p-vers button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .new-seal, .new-seal::after { animation: none; } }
