:root {
  --ink: #2a1a0e;
  --ink2: #5a3d22;
  --parch: #efe2c4;
  --parch2: #e4d2aa;
  --ultra: #23408e;
  --verm: #a8321f;
  --gold: #c08a1e;
  --gold2: #e9c15a;
  --font: Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #140c07; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#viewport { position: fixed; inset: 0; overflow: hidden; }
#app { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; font-family: var(--font); color: var(--ink); overflow: hidden; }
.hidden { display: none !important; }

#desk { position: absolute; inset: 0; background:
  radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 40%, rgba(0,0,0,0.55) 100%),
  repeating-linear-gradient(92deg, rgba(255,255,255,0.025) 0 3px, rgba(0,0,0,0.04) 3px 9px),
  linear-gradient(180deg, #4a2c17, #2b170b); }

#book { position: absolute; left: 10px; top: 8px; width: 940px; height: 524px; }
.page { position: absolute; top: 0; height: 524px; width: 466px;
  border: 26px solid transparent; border-image: url("assets/ui-panel.webp") 64 fill / 26px stretch;
  background-color: transparent; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.45)); }
.page-left { left: 0; }
.page-right { left: 474px; }
.gutter { position: absolute; left: 456px; top: 14px; width: 28px; height: 496px; background: linear-gradient(90deg, rgba(60,35,15,0), rgba(60,35,15,0.35) 45%, rgba(60,35,15,0.35) 55%, rgba(60,35,15,0)); pointer-events: none; z-index: 2; }

/* left page */
#scenePane { position: absolute; inset: 4px 4px 4px 4px; display: flex; flex-direction: column; gap: 6px; }
.illum-frame { position: relative; width: 406px; height: 262px; padding: 5px; background: linear-gradient(135deg, var(--gold2), var(--gold) 40%, #8a5f12); box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px rgba(255,240,200,0.6); }
.illum-frame::after { content: ""; position: absolute; inset: 5px; box-shadow: inset 0 0 0 2px var(--ultra), inset 0 0 18px rgba(40,20,5,0.35); pointer-events: none; }
#scene { width: 396px; height: 252px; display: block; background: #d9c69c; }
#dateRibbon { height: 34px; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; font-weight: 700; font-size: 20px; color: var(--verm); border-bottom: 2px solid rgba(90,61,34,0.4); }
#dateRibbon .gold { display: flex; align-items: center; gap: 4px; color: var(--ink); font-size: 19px; }
#dateRibbon .gold img { width: 26px; height: 26px; }
#statGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; }
.stat { display: flex; align-items: center; gap: 6px; height: 50px; padding: 2px 4px; position: relative; }
.stat img { width: 38px; height: 38px; flex: 0 0 auto; filter: drop-shadow(0 1px 0 rgba(0,0,0,0.25)); }
.stat .sv { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.stat .sl { font-size: 15px; color: var(--ink2); line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .sn { font-size: 22px; font-weight: 900; line-height: 1.05; color: var(--ink); }
.stat .bar { height: 5px; background: rgba(90,61,34,0.22); border-radius: 3px; overflow: hidden; margin-top: 2px; }
.stat .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ultra), #4d6fc4); transition: width 0.5s; }
.stat.health .bar i { background: linear-gradient(90deg, var(--verm), #d4573c); }
.stat.flash-up { animation: flashUp 0.7s; }
.stat.flash-down { animation: flashDown 0.7s; }
@keyframes flashUp { 0% { background: rgba(233,193,90,0.7); transform: scale(1.06); } 100% { background: transparent; transform: none; } }
@keyframes flashDown { 0% { background: rgba(168,50,31,0.35); transform: translateX(-3px); } 30% { transform: translateX(3px); } 100% { background: transparent; transform: none; } }
.stat .floaty { position: absolute; right: 2px; top: -6px; font-weight: 900; font-size: 18px; pointer-events: none; animation: floatUp 1.1s forwards; }
@keyframes floatUp { from { opacity: 1; transform: translateY(6px); } to { opacity: 0; transform: translateY(-16px); } }

#leftAlt { position: absolute; inset: 4px; display: flex; flex-direction: column; gap: 8px; }

/* right page */
#rightContent { position: absolute; inset: 2px 4px 2px 6px; display: flex; flex-direction: column; gap: 8px; }
#rightContent.turn { animation: pageTurn 0.38s cubic-bezier(0.25, 0.9, 0.35, 1.1); transform-origin: 0 50%; }
#leftAlt.turn { animation: pageTurnL 0.38s cubic-bezier(0.25, 0.9, 0.35, 1.1); transform-origin: 100% 50%; }
@keyframes pageTurn { from { opacity: 0; transform: perspective(1400px) rotateY(-28deg) translateX(-14px); } to { opacity: 1; transform: none; } }
@keyframes pageTurnL { from { opacity: 0; transform: perspective(1400px) rotateY(28deg) translateX(14px); } to { opacity: 1; transform: none; } }
.head { padding-right: 70px; min-height: 40px; }
.head h1 { margin: 0; font-size: 28px; font-weight: 900; line-height: 1.15; color: var(--ink); letter-spacing: 0.01em; text-shadow: 0 1px 0 rgba(255,245,220,0.7); }
.head h2 { margin: 2px 0 0; font-size: 17px; font-weight: 700; color: var(--verm); }
.rubric { color: var(--verm); }
.prose { font-size: 20px; line-height: 1.5; margin: 0; }
.prose::first-letter { font-size: 44px; float: left; line-height: 0.95; margin: 3px 6px 0 0; color: var(--verm); font-weight: 900; text-shadow: 1px 1px 0 var(--gold2), 2px 2px 0 var(--ink); }
.prose.plain::first-letter { font-size: inherit; float: none; margin: 0; color: inherit; text-shadow: none; font-weight: inherit; }
.small-note { font-size: 16px; color: var(--ink2); line-height: 1.35; }
.scroll { overflow-y: auto; overflow-x: hidden; flex: 1 1 auto; min-height: 0; scrollbar-width: thin; scrollbar-color: rgba(90,61,34,0.5) transparent; padding-right: 2px; }
.spacer { flex: 1 1 auto; }

.btn { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 60px; padding: 6px 16px;
  border: 14px solid transparent; border-image: url("assets/ui-button.webp") 40 fill / 14px stretch; background: transparent;
  font-family: var(--font); font-size: 20px; font-weight: 800; color: var(--ink); text-align: center; line-height: 1.15;
  cursor: pointer; transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.5, 1), filter 0.15s; outline: none; }
.btn > * { margin: -8px 0; }
.btn:hover, .btn.focus { transform: scale(1.035); filter: brightness(1.08) drop-shadow(0 0 6px rgba(233,193,90,0.9)); }
.btn.focus::after { content: ""; position: absolute; inset: -16px; border: 2px solid var(--gold); border-radius: 4px; box-shadow: 0 0 10px rgba(233,193,90,0.8); pointer-events: none; }
.btn.press { transform: scale(0.94); }
.btn.disabled { opacity: 0.45; filter: grayscale(0.6); }
.btn img { width: 38px; height: 38px; flex: 0 0 auto; }
.btn .bl { display: flex; flex-direction: column; align-items: flex-start; text-align: left; min-width: 0; }
.btn .bl small { font-size: 14px; font-weight: 600; color: var(--ink2); line-height: 1.15; }
.btn.small { min-height: 50px; font-size: 18px; padding: 4px 12px; }
.btn.primary { color: #fff6df; border-image: none; background: linear-gradient(180deg, #b8402a, #8a2414); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--gold2), 0 3px 0 var(--ink); border-radius: 3px; text-shadow: 0 2px 0 rgba(40,10,0,0.6); }
.btn.left { justify-content: flex-start; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .btn { flex: 1 1 0; }

.slots { display: flex; align-items: center; gap: 8px; font-size: 17px; color: var(--ink2); }
.slots .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); background: radial-gradient(circle at 35% 35%, var(--gold2), var(--gold)); box-shadow: 0 1px 0 rgba(0,0,0,0.3); }
.slots .dot.used { background: rgba(90,61,34,0.15); }
.calendar { font-size: 17px; padding: 4px 10px; border-left: 4px solid var(--verm); background: rgba(168,50,31,0.08); color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px 2px 4px; border-radius: 20px; background: rgba(255,250,235,0.6); border: 1.5px solid rgba(90,61,34,0.4); font-size: 18px; font-weight: 800; }
.chip img { width: 28px; height: 28px; }
.chip.up { color: var(--ultra); }
.chip.down { color: var(--verm); }

.piece { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; width: 100%; }
.piece .pt { font-size: 18px; font-weight: 800; line-height: 1.2; }
.piece .pc { font-size: 15px; color: var(--verm); font-weight: 700; }
.piece .pm { display: flex; align-items: center; gap: 6px; width: 100%; font-size: 14px; color: var(--ink2); font-weight: 600; }
.mbar { flex: 1; height: 6px; border-radius: 3px; background: rgba(90,61,34,0.2); overflow: hidden; position: relative; }
.mbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--ultra), #5a7fd0); }
.mbar.ready i { background: linear-gradient(90deg, var(--gold), var(--gold2)); }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 15px; }

/* codex list on left page */
.codex-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.codex-head h1 { margin: 0; font-size: 26px; font-weight: 900; }
.codex-tabs { display: flex; gap: 8px; }
.codex-list { display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto; min-height: 0; }
.codex-item { min-height: 54px; justify-content: flex-start; padding: 2px 10px; }
.codex-item.sel { filter: drop-shadow(0 0 5px rgba(192,138,30,0.9)); }
.codex-item .cn { font-size: 13px; color: var(--verm); font-weight: 700; display: block; }
.codex-item .ct { font-size: 17px; font-weight: 800; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }
.codex-item.unknown { opacity: 0.55; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; font-size: 18px; font-weight: 700; }
.pager .btn { min-width: 60px; }

.link-box { display: flex; gap: 8px; align-items: center; }
.link-input { flex: 1; min-width: 0; height: 46px; font-family: var(--font); font-size: 16px; color: var(--ink); background: rgba(255,250,235,0.7); border: none; border-bottom: 2px solid var(--ink2); padding: 4px 8px; outline: none; user-select: text; -webkit-user-select: text; }
.link-input:focus { background: rgba(255,250,235,0.95); border-bottom-color: var(--verm); }
.kv { font-size: 17px; line-height: 1.4; }
.kv b { color: var(--verm); font-size: 15px; display: block; }
.yt { font-family: var(--font); font-size: 16px; color: var(--ultra); word-break: break-word; user-select: text; -webkit-user-select: text; }

/* minigame */
#perfCanvas { width: 100%; height: 170px; display: block; }
.judge { text-align: center; font-size: 30px; font-weight: 900; height: 40px; }
.bigscore { font-size: 44px; font-weight: 900; text-align: center; color: var(--ink); text-shadow: 2px 2px 0 var(--gold2); }
.verdict { font-size: 34px; font-weight: 900; text-align: center; color: var(--verm); text-shadow: 2px 2px 0 var(--gold2), 3px 3px 0 var(--ink); animation: slam 0.45s cubic-bezier(0.3, 1.8, 0.5, 1); }
@keyframes slam { from { transform: scale(2.2) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.rank-list { display: flex; flex-direction: column; gap: 2px; font-size: 17px; }
.rank-list div { display: flex; justify-content: space-between; padding: 1px 8px; }
.rank-list .me { background: rgba(233,193,90,0.45); font-weight: 900; }

/* title */
.screen { position: absolute; inset: 0; z-index: 20; }
#title { background: #d9c69c url("assets/title-bg.webp") center / cover no-repeat; cursor: pointer; }
#titleLogo { position: absolute; left: 4%; top: 6%; max-width: 54%; max-height: 34%; object-fit: contain; opacity: 0; filter: drop-shadow(0 3px 0 rgba(255,245,220,0.6)); }
#titleLogo.in { animation: logoIn 0.7s cubic-bezier(0.3, 1.6, 0.5, 1) forwards, logoFloat 4s 0.7s ease-in-out infinite; }
@keyframes logoIn { from { opacity: 0; transform: translateY(-30px) scale(0.85); } to { opacity: 1; transform: none; } }
@keyframes logoFloat { 0%, 100% { opacity: 1; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-5px); } }
#titlePrompt { position: absolute; left: 0; right: 0; bottom: 7%; text-align: center; font-size: 24px; font-weight: 900; color: #fff3d6; text-shadow: 0 0 2px var(--ink), 2px 2px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); animation: pulse 1.8s ease-in-out infinite; pointer-events: none; }
@keyframes pulse { 0%, 100% { opacity: 0.55; transform: scale(0.98); } 50% { opacity: 1; transform: scale(1.03); } }

#intro { background: #000 url("assets/title-bg.webp") center / cover no-repeat; z-index: 30; }
#introVideo { width: 100%; height: 100%; object-fit: cover; display: block; }
#introSkip { position: absolute; right: 18px; top: 16px; color: var(--ink); }

#subtitle { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: 760px; z-index: 40; padding: 8px 18px; font-size: 21px; font-weight: 700; line-height: 1.4; color: #fff6e0; background: rgba(30, 18, 8, 0.78); border: 1.5px solid var(--gold); border-radius: 4px; text-align: center; opacity: 0; transition: opacity 0.25s; pointer-events: none; }
#subtitle.show { opacity: 1; }
#toast { position: absolute; left: 50%; top: 18px; transform: translate(-50%, -80px); z-index: 25; padding: 8px 18px; font-size: 19px; font-weight: 800; color: var(--ink); background: var(--parch); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px var(--gold2), 0 4px 10px rgba(0,0,0,0.4); transition: transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1); white-space: nowrap; pointer-events: none; }
#toast.show { transform: translate(-50%, 0); }
#fade { position: absolute; inset: 0; background: #1a0f07; opacity: 0; pointer-events: none; z-index: 50; transition: opacity 0.3s; }
#fade.on { opacity: 1; }

.ending-title { font-size: 36px; font-weight: 900; color: var(--verm); text-align: center; text-shadow: 2px 2px 0 var(--gold2), 3px 3px 0 var(--ink); margin: 4px 0; }
.end-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.end-card { min-height: 64px; font-size: 18px; }
