* { box-sizing: border-box; }
:root { --ink: #1b1733; --paper: #f4ebd9; --paper2: #e6d8bb; --lav: #9c89b8; --teal: #5fb3b3; --mint: #bdf2d5; --pumpkin: #f29e4c; --gold: #f7c948; --rose: #e86a7a; --deep: #171430; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #120f28; color: #fff;
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; touch-action: none; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: radial-gradient(ellipse at center, rgba(36,31,74,.6), rgba(12,9,30,.9)); animation: fade .2s ease; z-index: 5; }
.overlay.hidden, .hidden { display: none !important; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.85) rotate(-1deg); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes wob { 0%,100% { transform: rotate(-2deg) } 50% { transform: rotate(2deg) } }
@keyframes bounce { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes floaty { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.06) } }

/* ---------------- loading + title */
#loading { background: #171430; }
.loader { text-align: center; font-size: 24px; font-weight: 800; }
.ghostload { font-size: 64px; animation: floaty 1.4s ease-in-out infinite; }
.bar { width: 260px; height: 12px; border-radius: 6px; background: #3a2f6b; overflow: hidden; margin: 8px auto 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--mint); transition: width .2s; }

#title { background: #171430 center/cover; align-items: flex-start; justify-content: center; }
#title::before { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(18,14,40,.85) 0%, rgba(18,14,40,.45) 45%, rgba(18,14,40,0) 70%); }
.title-left { position: relative; margin-left: 70px; display: flex; flex-direction: column; align-items: flex-start; gap: 18px; max-width: 560px; }
.logo { display: flex; flex-direction: column; line-height: .86; filter: drop-shadow(0 7px 0 rgba(0,0,0,.4)); transform-origin: left center; animation: wob 4s ease-in-out infinite; }
.logo .l1 { font-size: 62px; font-weight: 800; color: var(--mint); -webkit-text-stroke: 2px #1b3a3a; letter-spacing: 4px; }
.logo .l2 { font-size: 84px; font-weight: 800; color: var(--paper); -webkit-text-stroke: 2px #3a2f6b; letter-spacing: 10px; }
.logo .l3 { font-size: 66px; font-weight: 800; color: var(--pumpkin); -webkit-text-stroke: 2px #4a1f00; letter-spacing: 3px; }
.logo .l4 { font-size: 22px; font-weight: 700; color: #e8e0ff; margin-top: 12px; line-height: 1.2; }
.tinfo { font-size: 18px; font-weight: 700; color: var(--paper2); line-height: 1.35; }
.tinfo b { color: var(--gold); }

/* ---------------- buttons */
.btn { font: inherit; font-weight: 800; font-size: 19px; color: #fff; border: 0; cursor: pointer; padding: 9px 20px 11px; border-radius: 14px; position: relative;
  box-shadow: 0 5px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(3px) scale(.97); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; transform: none; }
.btn.big { font-size: 34px; padding: 10px 56px 14px; }
.btn.big2 { font-size: 24px; padding: 10px 30px 12px; }
.btn.small { font-size: 16px; padding: 6px 14px 8px; }
.btn.pumpkin { background: linear-gradient(#ffb36b, #e0751f); color: var(--ink); animation: bounce 1.4s ease-in-out infinite; }
.btn.green { background: linear-gradient(#6fd88a, #2f8a4c); }
.btn.gold { background: linear-gradient(#ffe08a, #d9a21a); color: #3a2200; }
.btn.dark { background: linear-gradient(#5a4f8a, #2e2658); }
.btn.red { background: linear-gradient(#f08a8a, #b83a4a); }
.btn.pulse { animation: pulse 0.8s ease-in-out infinite; }

.topbtns { position: absolute; right: 26px; top: 10px; display: flex; gap: 8px; z-index: 3; }
.tbtn { font: inherit; font-weight: 800; font-size: 17px; color: var(--paper); background: #2a2452; border: 2px solid rgba(255,255,255,.14); border-radius: 21px; height: 42px; padding: 0 14px 2px; cursor: pointer; display: flex; align-items: center; gap: 6px; position: relative; box-shadow: 0 4px 0 rgba(0,0,0,.35); }
.tbtn:hover { filter: brightness(1.2); }
.tbtn:active { transform: translateY(2px); }
.badge { position: absolute; right: -6px; top: -6px; background: var(--rose); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 14px; font-style: normal; animation: pulse .9s infinite; }

.toast { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); z-index: 4; background: var(--paper); color: var(--ink); font-weight: 800; font-size: 20px; padding: 8px 22px 10px;
  border-radius: 16px; box-shadow: 0 6px 0 rgba(0,0,0,.35); max-width: 640px; text-align: center; line-height: 1.2; animation: pop .2s ease both; pointer-events: none; }

/* ---------------- modals */
.modal { background: linear-gradient(180deg, #3a2f6b, #221c48); border: 3px solid rgba(255,255,255,.14); border-radius: 24px; padding: 18px 28px; min-width: 460px; max-width: 900px; max-height: 690px;
  text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: pop .22s ease both; display: flex; flex-direction: column; }
.modal.wide { width: 820px; }
.modal.xwide { width: 1080px; max-width: 1080px; }
.modal h2 { margin: 0 0 4px; font-size: 32px; color: var(--mint); line-height: 1.1; }
.modal h3 { margin: 10px 0 6px; font-size: 22px; color: var(--gold); }
.modal h2.gala { font-size: 54px; color: var(--pumpkin); animation: wob 1.5s infinite; }
.sub { margin: 0 0 8px; color: #e0d8f5; font-size: 17px; line-height: 1.25; }
.sub.small { font-size: 15px; color: #c9bfe6; margin-top: 8px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }

.list { display: flex; flex-direction: column; gap: 7px; text-align: left; }
.trow { display: flex; align-items: center; gap: 12px; background: rgba(15,10,40,.5); border-radius: 14px; padding: 8px 12px; min-height: 54px; }
.trow .ti { width: 34px; text-align: center; font-size: 22px; flex: none; }
.trow .tt { flex: 1; font-weight: 700; font-size: 18px; line-height: 1.15; }
.trow.done { opacity: .6; }
.trow.done .tt { text-decoration: line-through; text-decoration-color: rgba(189,242,213,.6); }
.trow.cur { background: rgba(242,158,76,.22); border: 2px solid var(--pumpkin); }
.trow.locked { opacity: .45; }
.trow .tc { font-weight: 800; color: var(--gold); white-space: nowrap; }

.qrow { display: flex; align-items: center; gap: 12px; background: rgba(15,10,40,.5); border-radius: 12px; padding: 7px 12px; }
.qrow .qt { flex: 1; font-weight: 700; font-size: 17px; line-height: 1.15; }
.qrow .qp { width: 160px; }
.qrow .qp .pb { height: 12px; border-radius: 6px; background: #1a1535; overflow: hidden; }
.qrow .qp .pb i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--mint)); }
.qrow .qp small { display: block; font-size: 13px; color: #c9bfe6; text-align: center; }
.qrow .qr { width: 86px; text-align: right; font-weight: 800; color: var(--gold); }
.streak-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.sday { background: rgba(15,10,40,.5); border-radius: 12px; padding: 6px 4px; font-weight: 800; font-size: 14px; border: 2px solid transparent; }
.sday .sr { font-size: 15px; color: var(--gold); margin-top: 2px; }
.sday.got { opacity: .55; }
.sday.today { border-color: var(--pumpkin); background: rgba(242,158,76,.22); }

.tabs { display: flex; gap: 6px; margin: 4px 0 8px; align-items: center; }
.tab { font: inherit; font-weight: 800; font-size: 17px; color: #fff; background: rgba(90,79,138,.85); border: 2px solid transparent; border-radius: 10px; padding: 3px 16px; cursor: pointer; }
.tab.on { border-color: var(--pumpkin); background: rgba(242,158,76,.3); }
.found { margin-left: auto; font-weight: 800; color: var(--gold); }
.book-body { overflow-y: auto; max-height: 470px; padding: 4px; text-align: left; }
.chainrow { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; background: rgba(15,10,40,.4); border-radius: 14px; padding: 6px 8px; }
.chainrow .cn { width: 150px; flex: none; font-weight: 800; font-size: 16px; line-height: 1.1; display: flex; align-items: center; gap: 6px; }
.icon { width: 88px; flex: none; text-align: center; font-size: 12px; font-weight: 700; line-height: 1.05; color: #e0d8f5; }
.icon .ic { width: 72px; height: 72px; margin: 0 auto 2px; background-repeat: no-repeat; border-radius: 14px; background-color: rgba(255,255,255,.06); position: relative; }
.icon.unknown .ic { filter: brightness(0) opacity(.35); }
.icon.unknown { color: #7d72a8; }
.gen-ic { width: 44px; height: 44px; background-repeat: no-repeat; flex: none; }
.ghosts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.gcard { display: flex; gap: 10px; background: rgba(15,10,40,.45); border-radius: 14px; padding: 8px; align-items: center; }
.gcard .gp { width: 84px; height: 110px; flex: none; background-repeat: no-repeat; background-position: 0 50%; }
.gcard.unknown .gp { filter: brightness(0) opacity(.4); }
.gcard b { display: block; font-size: 17px; color: var(--mint); line-height: 1.1; }
.gcard p { margin: 3px 0 0; font-size: 14px; line-height: 1.2; color: #e0d8f5; }

.bigjar { width: 120px; height: 120px; margin: 4px auto; background: center/contain no-repeat; animation: floaty 2s ease-in-out infinite; font-size: 90px; line-height: 120px; }
.timer { font-size: 22px; font-weight: 800; color: var(--mint); margin: 2px 0 8px; }

.setrow { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin: 7px 0; font-size: 19px; font-weight: 700; }
.setrow select { font: inherit; font-size: 17px; padding: 4px 8px; border-radius: 10px; border: 0; background: var(--paper); color: var(--ink); }
.toggle { min-width: 110px; }

/* ---------------- story */
.story { justify-content: flex-end; background: linear-gradient(180deg, rgba(12,9,30,0) 30%, rgba(12,9,30,.8)); cursor: pointer; }
.story-box { width: 1040px; margin-bottom: 28px; display: flex; align-items: flex-end; gap: 16px; background: var(--paper); color: var(--ink); border-radius: 22px; padding: 14px 20px 16px 16px;
  box-shadow: 0 12px 0 rgba(0,0,0,.35); position: relative; animation: pop .25s ease both; }
.portrait { width: 150px; height: 190px; flex: none; margin-top: -90px; background-repeat: no-repeat; background-position: 0 100%; animation: floaty 2.2s ease-in-out infinite; }
.story-text { flex: 1; min-height: 90px; }
.story-text b { display: block; font-size: 22px; color: #5a3f8f; }
.story-text p { margin: 4px 0 0; font-size: 22px; font-weight: 700; line-height: 1.3; }

#rotate { display: none; position: fixed; inset: 0; background: #171430; color: #fff; font-size: 26px; font-weight: 800; align-items: center; justify-content: center; text-align: center; padding: 30px; z-index: 50; }
@media (orientation: portrait) and (max-width: 820px) and (pointer: coarse) { #rotate { display: flex; } }
@media (prefers-reduced-motion: reduce) { .logo, .btn.pumpkin, .ghostload, .portrait, .bigjar, .badge, .btn.pulse { animation: none !important; } }
