* { box-sizing: border-box; }
:root {
  --ink: #3b2616;
  --paper: #fff8e8;
  --sun: #ffc233;
  --leaf: #6cc93a;
  --sky: #2f8fe0;
  --tomato: #ff4d57;
  --grape: #9b5bd6;
  --font: "Baloo 2", "Nunito", system-ui, "Noto Sans", sans-serif;
}
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #6b3f17; color: var(--ink);
  font-family: var(--font);
  -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; touch-action: none; display: block; }
.hidden { display: none !important; }

/* ---------- overlays & modals */
.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(50, 28, 10, 0.55); animation: fade .2s ease;
}
.overlay.clear { background: linear-gradient(90deg, rgba(60,30,8,.6) 0%, rgba(60,30,8,0) 30%, rgba(60,30,8,0) 70%, rgba(60,30,8,.6) 100%); }
.overlay.clear-hotel { background: none; justify-content: flex-start; align-items: stretch; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { 0% { transform: scale(.7) rotate(-2deg); opacity: 0 } 70% { transform: scale(1.04) rotate(.5deg); opacity: 1 } 100% { transform: scale(1) } }
@keyframes wobble { 0%,100% { transform: rotate(-2deg) } 50% { transform: rotate(2deg) } }
@keyframes bob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes starpop { 0% { transform: scale(0) rotate(-40deg) } 70% { transform: scale(1.35) rotate(10deg) } 100% { transform: scale(1) } }

.modal {
  background: var(--paper); border: 4px solid var(--ink); border-radius: 26px; padding: 22px 34px 24px;
  min-width: 440px; max-width: 980px; max-height: 690px; overflow: auto; text-align: center;
  box-shadow: 0 10px 0 rgba(59,38,22,.35), 0 30px 60px rgba(0,0,0,.4); animation: pop .32s cubic-bezier(.2,.9,.3,1.3) both;
  background-image: radial-gradient(circle at 15% 8%, rgba(255,202,58,.28), transparent 40%), radial-gradient(circle at 92% 92%, rgba(47,143,224,.16), transparent 45%);
}
.modal.wide { width: 920px; }
.modal h2 { margin: 0 0 4px; font-size: 42px; line-height: 1.05; color: #d9480f; text-shadow: 2px 2px 0 #ffe3a3; }
.modal .sub { margin: 4px 0 10px; color: #7a5a3a; font-size: 18px; }
.actions { display: flex; gap: 14px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; margin: 12px auto; width: 340px; }
.icon-row { display: flex; gap: 10px; justify-content: center; }

/* ---------- buttons */
.btn {
  font: inherit; font-weight: 800; font-size: 22px; color: #fff; border: 3px solid var(--ink); cursor: pointer;
  padding: 8px 26px 10px; border-radius: 18px; position: relative; line-height: 1.15;
  box-shadow: 0 5px 0 var(--ink); transition: transform .08s, filter .15s;
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.btn:hover { filter: brightness(1.08); transform: translateY(-2px) rotate(-.5deg); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { filter: grayscale(1) opacity(.55); cursor: not-allowed; transform: none; }
.btn.sun { background: linear-gradient(#ffd95a, #f29a12); }
.btn.leaf { background: linear-gradient(#9fe35a, #3f9a2a); }
.btn.sky { background: linear-gradient(#6cc0ff, #1f6fbf); }
.btn.tomato { background: linear-gradient(#ff8a8f, #d6243a); }
.btn.paper { background: var(--paper); color: var(--ink); text-shadow: none; }
.btn.big { font-size: 34px; padding: 10px 34px 14px; border-radius: 24px; animation: wobble 2.4s ease-in-out infinite; max-width: 380px; }
.btn.icon { padding: 6px 14px 8px; font-size: 22px; }
.btn.off { opacity: .45; }
.badge { position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--tomato); border: 2px solid var(--ink); color: #fff; font-style: normal; font-size: 14px; line-height: 20px; padding: 0 5px; }

/* ---------- menu */
#menu { flex-direction: row; justify-content: space-between; align-items: stretch; padding: 26px 30px; }
.menu-left, .menu-right { width: 330px; display: flex; flex-direction: column; gap: 14px; }
.menu-left { align-items: center; justify-content: center; }
.menu-right { justify-content: center; }
.logo { display: flex; flex-direction: column; align-items: center; line-height: .88; animation: bob 3s ease-in-out infinite; text-align: center; }
.logo .l1 { font-size: 40px; font-weight: 800; letter-spacing: 3px; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); }
.logo .l2 { font-size: 72px; font-weight: 800; color: var(--sun); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); max-width: 330px; white-space: nowrap; }
.tagline { margin: 0; color: #fff; font-weight: 700; font-size: 18px; text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(0,0,0,.4); text-align: center; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip { background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; padding: 2px 14px; font-weight: 800; font-size: 20px; }
.goal { margin: 0; color: #fff; font-weight: 700; font-size: 17px; text-align: center; text-shadow: 0 2px 0 var(--ink); max-width: 330px; }
.card { background: var(--paper); border: 4px solid var(--ink); border-radius: 22px; padding: 12px 16px 14px; box-shadow: 0 6px 0 rgba(59,38,22,.5); }
.daily { text-align: left; display: flex; flex-direction: column; gap: 4px; }
.dc-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 8px; }
.dc-title { font-size: 26px; font-weight: 800; color: #d9480f; white-space: nowrap; }
.dc-time { font-size: 14px; color: #7a5a3a; white-space: nowrap; }
.dc-desc { font-size: 16px; color: #6b4a2a; line-height: 1.2; }
.dc-row { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; font-size: 15px; color: #2f7f3a; }
.daily .btn { margin-top: 6px; font-size: 20px; }
.grid-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-btns .btn { font-size: 18px; padding: 8px 8px 10px; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; }
.grid-btns .btn .e { font-size: 22px; }
.grid-btns .wide { grid-column: span 2; }

/* ---------- in-game HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
.hbtn { pointer-events: auto; position: absolute; font: inherit; font-weight: 800; border: 3px solid var(--ink); border-radius: 16px; background: var(--paper); color: var(--ink); cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
.hbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#btn-pause { left: 22px; top: 18px; width: 60px; height: 56px; font-size: 20px; }
.lvl-label { position: absolute; left: 640px; top: 10px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; white-space: nowrap; max-width: 560px; }
.lvl-label #lvl-name { background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; padding: 0 16px; font-weight: 800; font-size: 22px; box-shadow: 0 3px 0 var(--ink); overflow: hidden; text-overflow: ellipsis; }
.tough { background: var(--tomato); color: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 0 10px; font-weight: 800; font-size: 18px; animation: wobble .8s ease-in-out infinite; }
.panel-title { position: absolute; font-weight: 800; font-size: 22px; color: var(--ink); text-align: center; width: 250px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lbl-boxes { left: 55px; top: 124px; }
#lbl-tray { left: 980px; top: 122px; }
.tools { position: absolute; left: 968px; top: 330px; width: 274px; display: flex; flex-direction: column; gap: 12px; pointer-events: auto; }
.tool { font: inherit; display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 8px; height: 76px; padding: 4px 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 5px 0 var(--ink); cursor: pointer; text-align: left; transition: transform .08s; }
.tool:hover { transform: translateY(-2px); }
.tool:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.tool svg { width: 48px; height: 48px; }
.tool .tl { font-weight: 800; font-size: 20px; line-height: 1.05; overflow: hidden; }
.tool .cnt { background: var(--sun); border: 3px solid var(--ink); border-radius: 12px; padding: 0 8px; font-size: 18px; min-width: 34px; text-align: center; }
.tool.empty .cnt { background: #fff; font-size: 15px; }
.tool.armed { background: #ffe9a8; box-shadow: 0 0 0 4px var(--tomato), 0 5px 0 var(--ink); animation: wobble .5s ease-in-out infinite; }
.tool:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- toast */
.toast { position: absolute; left: 50%; top: 60px; transform: translateX(-50%); background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 6px 20px; font-size: 20px; font-weight: 800; box-shadow: 0 4px 0 var(--ink); animation: pop .3s ease both; z-index: 5; max-width: 760px; text-align: center; pointer-events: none; }

/* ---------- loading */
.loader { text-align: center; font-size: 24px; color: #fff; font-weight: 800; text-shadow: 0 2px 0 var(--ink); }
.spin { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; border: 8px solid rgba(255,255,255,.3); border-top-color: var(--sun); animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg) } }
.loader .bar { width: 260px; height: 14px; border: 3px solid var(--ink); border-radius: 10px; background: var(--paper); overflow: hidden; margin: 8px auto 0; }
.loader .bar i { display: block; height: 100%; width: 0; background: var(--sun); transition: width .2s; }

/* ---------- missions */
.mission-list { display: flex; flex-direction: column; gap: 10px; min-width: 560px; text-align: left; }
.mission { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.mission b { font-size: 19px; }
.m-bar { height: 12px; border-radius: 6px; background: #eadcc0; overflow: hidden; margin: 4px 0 2px; }
.m-bar i { display: block; height: 100%; background: var(--sun); }
.mission small { color: #7a5a3a; }
.mission.claimed { background: #eaf8e2; }
.mission .btn { font-size: 18px; padding: 4px 14px 6px; }
.streak-line { font-weight: 800; color: #d9480f; margin: 12px 0 0; }

/* ---------- settings */
.set-list { display: flex; flex-direction: column; gap: 12px; min-width: 460px; margin: 12px 0; }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; font-size: 22px; font-weight: 700; background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 6px 14px; }
.toggle { font: inherit; width: 72px; height: 36px; border: 3px solid var(--ink); border-radius: 18px; cursor: pointer; background: #cbbfa8; position: relative; }
.toggle::after { content: ''; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transition: left .15s; }
.toggle.on { background: var(--leaf); }
.toggle.on::after { left: 37px; }
select { font: inherit; font-size: 18px; font-weight: 700; border: 3px solid var(--ink); border-radius: 12px; padding: 4px 8px; background: var(--paper); color: var(--ink); max-width: 260px; }

/* ---------- howto */
.howto { text-align: left; font-size: 20px; line-height: 1.35; margin: 8px 0; padding-left: 28px; }
.howto li { margin: 5px 0; }
.keys { color: #7a5a3a; font-size: 16px; }

/* ---------- result */
.modal.result { width: 640px; }
.joke { margin: 0 0 6px; font-size: 19px; color: #7a5a3a; font-style: italic; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 4px 0; }
.stars i { font-style: normal; font-size: 64px; line-height: 1; color: #e2d3b5; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
.stars i.on { color: var(--sun); animation: starpop .4s cubic-bezier(.2,.9,.3,1.4) both; }
.reward { font-size: 30px; font-weight: 800; color: #d9480f; min-height: 36px; }
.result-extra { font-size: 18px; font-weight: 700; color: #1f6fbf; display: flex; flex-direction: column; gap: 2px; }

/* ---------- pet hotel */
.hotel-top { display: flex; align-items: center; gap: 14px; padding: 14px 20px 0; }
.hotel-title { font-size: 36px; font-weight: 800; color: #fff; -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--ink); flex: 1; }
#hotel-stars { color: var(--sun); font-size: 30px; }
.hotel-panel { position: absolute; right: 18px; top: 84px; width: 380px; bottom: 18px; background: var(--paper); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 rgba(59,38,22,.5); display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 3px solid var(--ink); }
.tab { flex: 1; font: inherit; font-weight: 800; font-size: 18px; padding: 8px 4px; background: #f1e3c4; border: none; border-right: 3px solid var(--ink); cursor: pointer; color: var(--ink); }
.tab:last-child { border-right: none; }
.tab.on { background: var(--sun); }
.hotel-list { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.h-row { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px; }
.h-row canvas { width: 64px; height: 64px; flex: none; }
.h-name { flex: 1; font-weight: 800; font-size: 18px; display: flex; flex-direction: column; line-height: 1.1; }
.h-sub { font-weight: 600; font-size: 14px; color: #7a5a3a; }
.h-have { font-weight: 800; font-size: 18px; }
.h-row .btn { font-size: 16px; padding: 4px 12px 6px; white-space: nowrap; }

#rotate { display: none; position: fixed; inset: auto 0 0 0; padding: 10px; text-align: center; background: var(--paper); color: var(--ink); font-weight: 800; border-top: 3px solid var(--ink); z-index: 10; }
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) { #rotate { display: block; } }
