* { box-sizing: border-box; }
:root { --ink: #2b2d42; --brown: #5b3a22; --paper: #fff6e5; --paper2: #f3e3c3; --red: #d64545; --gold: #ffd166; --green: #06d6a0; --greenD: #2e9e6b; --blue: #118ab2; --pink: #ef476f; --wood: #a0673a; --sky: #bfe6ff; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #cdeccf; color: var(--brown);
  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; background: linear-gradient(#9fd8f5, #e9d7a6); }
#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(91,58,34,.35), rgba(60,35,15,.75)); 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 hop { 0%,100% { transform: translateY(0) scale(1, 1) } 40% { transform: translateY(-18px) scale(.95, 1.05) } 80% { transform: translateY(0) scale(1.08, .92) } }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.06) } }

/* ---------------- loading + title */
#loading { background: linear-gradient(#9fd8f5, #cdeccf); }
.loader { text-align: center; font-size: 24px; font-weight: 800; color: var(--brown); }
.bounce-ic { font-size: 70px; animation: hop 0.9s ease-in-out infinite; }
.bar { width: 260px; height: 14px; border-radius: 7px; background: rgba(91,58,34,.25); overflow: hidden; margin: 8px auto 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }

#title { background: #9fd8f5 center/cover; align-items: flex-start; justify-content: center; }
#title::before { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(255,246,229,.82) 0%, rgba(255,246,229,.45) 42%, rgba(255,246,229,0) 66%); }
.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: .9; filter: drop-shadow(0 7px 0 rgba(91,58,34,.35)); transform-origin: left center; animation: wob 4s ease-in-out infinite; }
.logo .l1 { font-size: 64px; font-weight: 800; color: var(--gold); -webkit-text-stroke: 3px var(--brown); letter-spacing: 3px; paint-order: stroke fill; }
.logo .l2 { font-size: 104px; font-weight: 800; color: var(--red); -webkit-text-stroke: 4px #fff; letter-spacing: 6px; paint-order: stroke fill; }
.logo .l4 { font-size: 24px; font-weight: 800; color: var(--brown); margin-top: 12px; line-height: 1.2; }
.tinfo { font-size: 19px; font-weight: 800; color: var(--brown); line-height: 1.35; }

#title-cast { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#title-cast .actor { position: absolute; background-repeat: no-repeat; filter: drop-shadow(0 6px 4px rgba(60,35,15,.3)); }
#title-cast .runner { bottom: 18px; left: -140px; animation: run 7s linear infinite; }
@keyframes run { from { transform: translateX(0) } to { transform: translateX(1560px) } }

/* ---------------- 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,.28), inset 0 2px 0 rgba(255,255,255,.3); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(3px) scale(.97); box-shadow: 0 2px 0 rgba(0,0,0,.28); }
.btn:disabled { filter: grayscale(1) brightness(.85); opacity: .7; cursor: not-allowed; transform: none; }
.btn.big { font-size: 36px; padding: 10px 60px 14px; }
.btn.big2 { font-size: 22px; padding: 10px 26px 12px; }
.btn.small { font-size: 16px; padding: 6px 14px 8px; }
.btn.red { background: linear-gradient(#ff7a6e, #c0392b); }
#btn-play { animation: bounce 1.4s ease-in-out infinite; }
.btn.green { background: linear-gradient(#4ee0b0, #2e9e6b); }
.btn.gold { background: linear-gradient(#ffe08a, #e0a91f); color: #4a2d00; }
.btn.dark { background: linear-gradient(#8a6a4a, #5b3a22); }
.btn.pulse { animation: pulse 0.8s ease-in-out infinite; }

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

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

/* ---------------- modals */
.modal { background: var(--paper); border: 5px solid var(--wood); border-radius: 24px; padding: 16px 26px; min-width: 480px; max-width: 900px; max-height: 690px;
  text-align: center; box-shadow: 0 24px 60px rgba(60,35,15,.5), inset 0 0 0 3px #fff; animation: pop .22s ease both; display: flex; flex-direction: column; position: relative; }
.modal::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 14px; border-radius: 18px 18px 0 0;
  background: repeating-linear-gradient(90deg, #e86a5a 0 12px, #f7b3a8 12px 24px); }
.modal.wide { width: 820px; }
.modal.xwide { width: 1100px; max-width: 1100px; }
.modal h2 { margin: 6px 0 4px; font-size: 32px; color: var(--red); line-height: 1.1; }
.modal h3 { margin: 10px 0 6px; font-size: 22px; color: var(--wood); }
.sub { margin: 0 0 8px; color: var(--brown); font-size: 17px; line-height: 1.25; font-weight: 700; }
.sub.small { font-size: 15px; color: #8a6a4a; margin-top: 8px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.coin { display: inline-block; width: .9em; height: .9em; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe89a 0 22%, #f7c948 24% 70%, #c98a1b 72%); vertical-align: -0.12em; margin-right: 2px; font-style: normal; }
.ic { display: inline-block; background-repeat: no-repeat; vertical-align: middle; font-style: normal; text-align: center; line-height: 1.1; font-size: 28px; flex: none; }

.list { display: flex; flex-direction: column; gap: 7px; text-align: left; overflow-y: auto; max-height: 440px; }
.qrow, .rrow, .wrow { display: flex; align-items: center; gap: 12px; background: rgba(160,103,58,.12); border-radius: 14px; padding: 7px 12px; min-height: 48px; }
.qrow.ok { background: rgba(6,214,160,.18); }
.qrow .qt { flex: 1; font-weight: 800; font-size: 17px; line-height: 1.15; display: flex; align-items: center; gap: 8px; }
.qrow small, .rrow small { color: #8a6a4a; font-weight: 700; font-size: 13px; }
.qrow .qp { width: 160px; }
.pb { height: 12px; border-radius: 6px; background: rgba(91,58,34,.2); overflow: hidden; }
.pb.big { height: 20px; border-radius: 10px; }
.pb i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #9ef0cf); }
.qrow .qp small { display: block; text-align: center; }
.qrow .qr { min-width: 86px; text-align: right; font-weight: 800; color: var(--wood); }
.wrow { font-weight: 800; font-size: 19px; }
.rrow .rn { flex: 1; display: flex; flex-direction: column; line-height: 1.1; }
.rrow .rn b { font-size: 17px; }
.ings { display: flex; align-items: center; gap: 4px; }
.ing { display: flex; align-items: center; opacity: .5; font-weight: 800; color: var(--greenD); }
.ing.have { opacity: 1; }
.plus { font-size: 18px; }
.cooking { display: flex; align-items: center; gap: 12px; background: rgba(255,209,102,.3); border-radius: 14px; padding: 8px 14px; margin: 4px 0 10px; text-align: left; }
.cooking .grow { flex: 1; }
.streak-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.sday { background: rgba(160,103,58,.12); border-radius: 12px; padding: 6px 4px; font-weight: 800; font-size: 14px; border: 3px solid transparent; }
.sday .sr { font-size: 15px; color: var(--wood); margin-top: 2px; }
.sday.got { opacity: .5; }
.sday.today { border-color: var(--red); background: rgba(214,69,69,.14); }
.fairbar { position: relative; margin: 26px 20px 4px; }
.fairbar .mk { position: absolute; top: -22px; transform: translateX(-50%); font-style: normal; font-weight: 800; font-size: 14px; color: #8a6a4a; }
.fairbar .mk.on { color: var(--greenD); }
.fairbar .mk::after { content: ''; position: absolute; left: 50%; top: 20px; width: 3px; height: 22px; background: rgba(91,58,34,.35); }
.pts { font-weight: 800; font-size: 22px; margin: 4px 0 8px; }

.tabs { display: flex; gap: 6px; margin: 4px 0 8px; align-items: center; }
.tab { font: inherit; font-weight: 800; font-size: 17px; color: var(--brown); background: rgba(160,103,58,.18); border: 3px solid transparent; border-radius: 10px; padding: 3px 16px; cursor: pointer; }
.tab.on { border-color: var(--red); background: rgba(214,69,69,.14); }
.found { margin-left: auto; font-weight: 800; color: var(--wood); }
.book-body { overflow-y: auto; max-height: 480px; padding: 4px; text-align: left; }
.chainrow { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; background: rgba(160,103,58,.1); border-radius: 14px; padding: 6px 8px; }
.chainrow .cn { width: 120px; flex: none; font-weight: 800; font-size: 16px; line-height: 1.1; }
.cells { display: flex; flex-wrap: wrap; gap: 4px; }
.icon { width: 104px; flex: none; text-align: center; font-size: 12px; font-weight: 800; line-height: 1.05; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.icon .ic { border-radius: 12px; background-color: rgba(255,255,255,.6); }
.icon.unknown .ic { filter: brightness(0) opacity(.3); }
.icon.unknown { color: #b09070; }
.icon.big { width: 200px; font-size: 16px; }
.trophies { display: flex; justify-content: center; gap: 20px; padding: 20px; }
.chars { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gcard { display: flex; gap: 10px; background: rgba(160,103,58,.1); border-radius: 14px; padding: 8px; align-items: center; }
.gcard .gp { width: 96px; height: 96px; flex: none; font-size: 50px; background-position-y: 100%; text-align: center; line-height: 96px; }
.gcard.unknown .gp { filter: brightness(0) opacity(.35); }
.gcard b { display: block; font-size: 18px; color: var(--red); line-height: 1.1; }
.gcard p { margin: 3px 0 0; font-size: 14px; line-height: 1.2; font-weight: 700; }

.bigjar { width: 120px; height: 120px; margin: 0 auto; animation: bounce 2s ease-in-out infinite; font-size: 90px; line-height: 120px; }
.timer { font-size: 22px; font-weight: 800; color: var(--greenD); margin: 2px 0 8px; }

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

/* ---------------- story */
.story { justify-content: flex-end; background: linear-gradient(180deg, rgba(60,35,15,0) 30%, rgba(60,35,15,.6)); cursor: pointer; }
.story-box { width: 1040px; margin-bottom: 28px; display: flex; align-items: flex-end; gap: 16px; background: var(--paper); color: var(--brown); border: 5px solid var(--wood); border-radius: 22px; padding: 14px 20px 16px 16px;
  box-shadow: 0 12px 0 rgba(60,35,15,.35); position: relative; animation: pop .25s ease both; }
.portrait { width: 150px; height: 180px; flex: none; margin-top: -100px; animation: bounce 2.2s ease-in-out infinite; font-size: 110px; line-height: 180px; text-align: center; }
.story-text { flex: 1; min-height: 90px; text-align: left; }
.story-text b { display: block; font-size: 22px; color: var(--red); }
.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: #9fd8f5; color: var(--brown); 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) { #title-cast .runner, .logo, #btn-play, .bounce-ic, .portrait, .bigjar, .badge, .btn.pulse { animation: none !important; } }
