:root {
  --cream: #fff3dc;
  --amber: #ffc46b;
  --crimson: #d4553a;
  --ink: #2b160b;
  --font: Georgia, "Times New Roman", serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --outline: 0 0 0 transparent;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #0b1024; color: var(--cream); font-family: var(--font); user-select: none; -webkit-user-select: none; }
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

.ol { text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink), 0 3px 4px rgba(0,0,0,.45); }

/* wooden plates */
.plate {
  border-style: solid; border-color: transparent;
  border-width: 12px;
  border-image: url("assets/ui-panel.webp") 110 fill / 22px stretch;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.45));
}

#hud { position: fixed; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(70px + var(--safe-r)); display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: flex-start; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#leafBox { display: flex; align-items: center; gap: 6px; padding: 0 6px 0 2px; min-width: 150px; height: 64px; }
.leafIcon { width: 36px; height: 36px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); animation: sway 3s ease-in-out infinite; }
@keyframes sway { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.leafNums { display: flex; flex-direction: column; line-height: 1.05; }
.num { font-weight: 900; font-size: 24px; color: var(--cream); }
#leafCount.bump { animation: bump .18s ease-out; }
@keyframes bump { 0% { transform: scale(1.18); } 100% { transform: scale(1); } }
.rate { font-size: 14px; font-weight: 700; color: var(--amber); }
#goldBox { display: flex; align-items: center; gap: 4px; height: 52px; padding: 0 2px 0 2px; cursor: pointer; }
#goldBox .num { font-size: 19px; }
#goldIcon { width: 26px; height: 26px; object-fit: contain; }
.plusBtn { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #8a5a1e; background: radial-gradient(circle at 35% 30%, #ffe7a8, #e0a03a); color: var(--ink); font: 900 20px/1 var(--font); padding: 0; cursor: pointer; }
#dayBox { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 6px; }
#dayTrack { position: relative; width: 104px; height: 10px; border-radius: 6px; background: linear-gradient(90deg, #ffe2a0 0%, #ffd27a 55%, #ff8a4a 74%, #3a3f78 80%, #141a3c 100%); box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
#dayFill { position: absolute; left: 61%; width: 17%; top: -3px; bottom: -3px; border: 2px solid rgba(255,220,150,.9); border-radius: 6px; }
#daySun { position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: radial-gradient(circle, #fff6d0 20%, #ffb43c 70%); box-shadow: 0 0 8px #ffc65a; left: 0; }
#daySun.moon { background: radial-gradient(circle at 40% 40%, #f4f6ff 30%, #a9b6e0 75%); box-shadow: 0 0 8px #b8c6ff; }
#dayLabel { font-size: 15px; font-weight: 800; min-width: 64px; }
#boostRow { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.boost { display: flex; align-items: center; gap: 4px; padding: 3px 9px 3px 4px; border-radius: 16px; background: rgba(40, 20, 8, .72); border: 1.5px solid var(--amber); font-size: 13px; font-weight: 800; animation: pop .25s cubic-bezier(.34,1.56,.64,1); }
.boost img { width: 20px; height: 20px; object-fit: contain; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

#banner { position: fixed; left: 50%; top: 27%; transform: translateX(-50%); width: min(92vw, 380px); text-align: center; pointer-events: none; z-index: 12; }
#banner.show { animation: slam .45s cubic-bezier(.34,1.56,.64,1); }
@keyframes slam { 0% { transform: translateX(-50%) scale(2); opacity: 0; } 100% { transform: translateX(-50%) scale(1); opacity: 1; } }
#bannerTitle { font-size: 28px; font-weight: 900; color: #ffe2a6; letter-spacing: .02em; }
#bannerSub { margin-top: 6px; font-size: 16px; font-weight: 700; color: var(--cream); }

#hint { position: fixed; left: 50%; top: 46%; transform: translateX(-50%); padding: 8px 16px; border-radius: 20px; background: rgba(40,20,8,.7); border: 2px solid var(--amber); font-size: 16px; font-weight: 800; white-space: nowrap; pointer-events: none; z-index: 11; animation: hintBob 1.4s ease-in-out infinite; }
@keyframes hintBob { 0%,100% { margin-top: 0; } 50% { margin-top: -6px; } }

#subtitle { position: fixed; left: 50%; bottom: calc(225px + var(--safe-b)); transform: translateX(-50%); width: min(90vw, 360px); text-align: center; padding: 8px 14px; border-radius: 14px; background: rgba(15, 8, 4, .62); font-size: 15px; font-weight: 700; line-height: 1.35; pointer-events: none; z-index: 13; }
#floaters { position: fixed; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.floater { position: absolute; font-weight: 900; font-size: 20px; color: #ffe9b8; white-space: nowrap; transform: translate(-50%, -50%); animation: rise 1s ease-out forwards; }
.floater.gold { color: #ffd84a; font-size: 22px; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }

/* bottom panel */
#panel {
  position: fixed; left: calc(4px + var(--safe-l)); right: calc(4px + var(--safe-r)); bottom: calc(4px + var(--safe-b));
  border-style: solid; border-color: transparent; border-width: 16px;
  border-image: url("assets/ui-panel.webp") 110 fill / 30px stretch;
  padding: 2px 2px 0; z-index: 10;
  filter: drop-shadow(0 -4px 10px rgba(0,0,0,.45));
  animation: slideUp .35s cubic-bezier(.34,1.3,.64,1);
}
@keyframes slideUp { 0% { transform: translateY(110%); } 100% { transform: translateY(0); } }
#infoLine { min-height: 20px; font-size: 14px; font-weight: 700; color: var(--amber); text-align: center; padding: 0 4px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#cards { display: flex; gap: 5px; }
.card {
  position: relative; flex: 1 1 0; min-width: 0; height: 104px; padding: 4px 2px 5px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  border-style: solid; border-color: transparent; border-width: 8px;
  border-image: url("assets/ui-button.webp") 90 fill / 14px stretch;
  background: none; color: var(--ink); font-family: var(--font); cursor: pointer;
  transition: transform .09s ease-out, filter .15s;
}
.card:active, .card.press { transform: scale(.93); }
.card img { width: 40px; height: 40px; object-fit: contain; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); margin-top: -2px; }
.card .cname { font-size: 12px; font-weight: 900; width: 100%; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; }
.card .clv { position: absolute; top: -6px; right: -4px; font-size: 11px; font-weight: 900; background: var(--crimson); color: #fff; border-radius: 9px; padding: 1px 5px; border: 1.5px solid #fff3dc; }
.card .ccost { display: flex; align-items: center; justify-content: center; gap: 2px; font-size: 13px; font-weight: 900; white-space: nowrap; line-height: 1; }
.card .ccost img { width: 14px; height: 14px; margin: 0; filter: none; }
.card.poor { filter: saturate(.35) brightness(.72); }
.card.ok { filter: drop-shadow(0 0 5px #ffcf6a); }
.card.sel { outline: 3px solid #fff; outline-offset: 1px; border-radius: 10px; }
.card.maxed .ccost { color: #7a3b16; }

#itemRow { display: flex; gap: 5px; margin-top: 6px; }
.itemBtn {
  flex: 1 1 0; min-width: 0; height: 48px; display: flex; align-items: center; justify-content: center; gap: 3px;
  border-radius: 12px; border: 2px solid #c99a52; background: linear-gradient(#5a3315, #3a1f0b);
  color: var(--cream); font: 800 13px var(--font); cursor: pointer; padding: 0 3px;
  transition: transform .09s ease-out, filter .15s; box-shadow: inset 0 1px 0 rgba(255,220,160,.35), 0 2px 4px rgba(0,0,0,.4);
}
.itemBtn:active { transform: scale(.93); }
.itemBtn img { width: 26px; height: 26px; object-fit: contain; flex: 0 0 auto; }
.itemBtn .iname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.itemBtn .icount { color: var(--amber); flex: 0 0 auto; }
.itemBtn.dim { filter: brightness(.7); }
.itemBtn.sel { outline: 3px solid #fff; outline-offset: 1px; }
.adIcon { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--amber); color: var(--ink); align-items: center; justify-content: center; font-size: 11px; flex: 0 0 auto; }

/* modals */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(5, 3, 12, .55); backdrop-filter: blur(2px); }
.modalPanel {
  width: min(88vw, 360px); padding: 18px 16px; text-align: center;
  border-style: solid; border-color: transparent; border-width: 22px;
  border-image: url("assets/ui-panel.webp") 110 fill / 40px stretch;
  animation: pop .3s cubic-bezier(.34,1.56,.64,1);
  filter: drop-shadow(0 10px 20px rgba(0,0,0,.5));
}
.modalTitle { font-size: 28px; font-weight: 900; color: #ffe2a6; margin-bottom: 8px; }
.modalBody { font-size: 16px; line-height: 1.4; margin-bottom: 8px; }
.modalBig { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 34px; font-weight: 900; color: #ffe9b8; margin: 6px 0 14px; }
.modalBig img { width: 40px; height: 40px; }
.modalBtns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.helpText { text-align: left; font-size: 15px; line-height: 1.5; margin-bottom: 14px; }
.helpText p { margin: 0 0 8px; }
.woodBtn {
  min-width: 120px; min-height: 52px; padding: 6px 18px;
  border-style: solid; border-color: transparent; border-width: 10px;
  border-image: url("assets/ui-button.webp") 90 fill / 18px stretch;
  background: none; color: var(--ink); font: 900 18px var(--font); cursor: pointer;
  transition: transform .09s ease-out, filter .15s;
}
.woodBtn:active { transform: scale(.93); }
.woodBtn.primary { filter: drop-shadow(0 0 6px #ffcf6a); }
.woodBtn.sel { outline: 3px solid #fff; outline-offset: 2px; border-radius: 12px; }

/* title */
#title { position: fixed; inset: 0; z-index: 40; overflow: hidden; background: #1a1d36; cursor: pointer; }
#titleBg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; animation: kenburns 24s ease-in-out infinite alternate; }
@keyframes kenburns { 0% { transform: scale(1.02); } 100% { transform: scale(1.09) translateY(-1.5%); } }
#titleShade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10,12,30,.25) 0%, rgba(0,0,0,0) 35%, rgba(0,0,0,0) 70%, rgba(10,6,4,.55) 100%); }
#titleLogo { position: absolute; left: 50%; top: calc(7% + var(--safe-t)); width: 84%; max-height: 30%; object-fit: contain; transform: translateX(-50%); filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); opacity: 0; }
#titleLogo.in { animation: logoIn .7s cubic-bezier(.34,1.56,.64,1) forwards, logoFloat 4s ease-in-out .7s infinite; }
@keyframes logoIn { 0% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(.7); } 100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); } }
@keyframes logoFloat { 0%,100% { opacity: 1; transform: translateX(-50%) translateY(0); } 50% { opacity: 1; transform: translateX(-50%) translateY(-6px); } }
#titlePrompt { position: absolute; left: 0; right: 0; bottom: calc(9% + var(--safe-b)); text-align: center; font-size: 21px; font-weight: 900; color: var(--cream); animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .55; transform: scale(.97); } 50% { opacity: 1; transform: scale(1.03); } }

/* intro */
#introBox { position: fixed; inset: 0; z-index: 50; background: #1a1d36 url("assets/cover-bg.webp") center / cover no-repeat; }
#introVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#introSub { position: absolute; left: 50%; bottom: calc(10% + var(--safe-b)); transform: translateX(-50%); width: min(88vw, 360px); text-align: center; font-size: 17px; font-weight: 700; line-height: 1.45; padding: 8px 14px; border-radius: 14px; background: rgba(10,6,4,.5); opacity: 0; transition: opacity .6s; }
#introSub.on { opacity: 1; }
#introSkip { position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); min-width: 96px; min-height: 48px; font-size: 16px; }

#fade { position: fixed; inset: 0; background: #0a0710; opacity: 0; pointer-events: none; z-index: 60; transition: opacity .35s ease; }
#fade.on { opacity: 1; }
