/* FarmLife – UI styles */
:root {
  --wood: #8a5a35; --wood-d: #5e3a1f; --cream: #fff6e2; --cream-d: #f1e1bd; --green: #5cb53f; --green-d: #3d8a27;
  --red: #e0533d; --red-d: #a8341f; --blue: #3d9be0; --blue-d: #2470a8; --gold: #f6c022; --text: #4a2f1a; --shadow: 0 4px 0 rgba(0,0,0,.25);
  --font: "Nunito", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6fae54; font-family: var(--font); color: var(--text); user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; cursor: grab; }
canvas#game.tool { cursor: crosshair; }
.hidden { display: none !important; }
img { -webkit-user-drag: none; }

/* ---------- loading ---------- */
#loading { position: fixed; inset: 0; background: linear-gradient(#8fd0ff, #b9e88f 70%, #7cc24f); display: flex; align-items: center; justify-content: center; z-index: 100; transition: opacity .5s; }
.load-box { text-align: center; }
.load-title { font-size: 64px; font-weight: 900; color: #fff; text-shadow: 0 5px 0 var(--wood-d), 0 8px 18px rgba(0,0,0,.3); letter-spacing: 2px; }
.load-bar { width: 260px; height: 18px; background: rgba(0,0,0,.25); border-radius: 10px; margin: 18px auto 8px; overflow: hidden; border: 3px solid #fff; }
#load-fill { height: 100%; width: 0; background: linear-gradient(#ffd54f, #f0a020); transition: width .2s; }
#load-txt { color: #fff; font-weight: 700; text-shadow: 0 2px 0 rgba(0,0,0,.3); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#topbar { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.hud-chip { pointer-events: auto; display: flex; align-items: center; gap: 6px; background: rgba(255,246,226,.95); border: 3px solid var(--wood); border-radius: 14px; padding: 3px 10px 3px 4px; box-shadow: var(--shadow); font-weight: 800; height: 40px; cursor: pointer; }
.hud-chip img { width: 28px; height: 28px; }
.hud-chip.farm { padding: 3px 12px; background: var(--wood); color: #fff; border-color: var(--wood-d); max-width: 200px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hud-chip.level { padding-left: 2px; min-width: 150px; }
.lvl-badge { width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #8fe36b, var(--green-d)); color: #fff; display: grid; place-items: center; font-weight: 900; border: 2px solid #fff; text-shadow: 0 1px 0 rgba(0,0,0,.4); font-size: 15px; flex: none; }
.xp-wrap { position: relative; flex: 1; height: 18px; background: #e3d3ad; border-radius: 9px; overflow: hidden; min-width: 100px; }
.xp-bar { height: 100%; width: 0; background: linear-gradient(#ffe27a, #f0a81e); transition: width .4s; }
.xp-wrap span { position: absolute; inset: 0; font-size: 11px; display: grid; place-items: center; color: var(--text); }
.hud-chip.money span { min-width: 44px; font-size: 17px; }
.hud-chip.store { font-size: 12px; flex-direction: row; position: relative; }
.mini-bar { position: absolute; left: 36px; right: 8px; bottom: 3px; height: 4px; background: #e3d3ad; border-radius: 2px; overflow: hidden; }
.mini-bar div { height: 100%; background: var(--green); }
.mini-bar div.full { background: var(--red); }
.hud-chip.clock { margin-left: auto; padding-right: 12px; }
.hud-chip.clock canvas { width: 30px; height: 30px; }
.hud-chip.clock div { display: flex; flex-direction: column; line-height: 1.05; }
.hud-chip.clock small { font-size: 11px; font-weight: 700; opacity: .8; }

#events { position: absolute; left: 8px; top: 64px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.ev-chip { pointer-events: auto; background: linear-gradient(#fff6e2, #f6e4bb); border: 3px solid #c58b3c; border-radius: 12px; padding: 4px 10px; font-size: 13px; font-weight: 800; box-shadow: var(--shadow); max-width: 240px; cursor: pointer; animation: pop .35s ease-out; }
.ev-chip small { display: block; font-weight: 700; opacity: .75; }
.ev-chip.bad { border-color: #d0602f; background: linear-gradient(#ffe9dc, #ffd2b8); }

#sidebar { position: absolute; right: 8px; top: 64px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100% - 140px); overflow-y: auto; scrollbar-width: none; }
.side-btn { position: relative; width: 66px; height: 62px; border-radius: 16px; border: 3px solid var(--wood-d); background: linear-gradient(#fff6e2, #f0dcae); box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; font-family: var(--font); color: var(--text); transition: transform .1s; }
.side-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.side-btn em { font-style: normal; font-size: 10px; font-weight: 800; line-height: 1; margin-top: 2px; }
.side-btn .si { width: 34px; height: 34px; background-size: contain; background-repeat: no-repeat; background-position: center; }
.badge { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--red); color: #fff; font-size: 12px; display: grid; place-items: center; border: 2px solid #fff; padding: 0 4px; }
.badge:empty { display: none; }

#zoom-ctl { position: absolute; left: 8px; bottom: max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
#zoom-ctl button { width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--wood-d); background: var(--cream); font-size: 22px; font-weight: 900; color: var(--text); box-shadow: var(--shadow); cursor: pointer; }

#tray { position: absolute; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(255,246,226,.97); border: 4px solid var(--wood); border-radius: 18px; box-shadow: 0 6px 0 rgba(0,0,0,.25); padding: 8px 10px; display: flex; gap: 8px; align-items: center; max-width: calc(100% - 140px); overflow-x: auto; animation: rise .2s ease-out; }
.tray-title { font-weight: 900; font-size: 13px; writing-mode: horizontal-tb; padding-right: 4px; white-space: nowrap; }
.tray-item { position: relative; width: 64px; min-width: 64px; height: 74px; border-radius: 12px; background: #fff; border: 3px solid var(--cream-d); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; font-size: 11px; font-weight: 800; transition: transform .1s; touch-action: none; }
.tray-item:hover { transform: translateY(-3px); border-color: var(--gold); }
.tray-item img { width: 40px; height: 40px; pointer-events: none; }
.tray-item.locked { opacity: .5; filter: grayscale(.8); }
.tray-item.active { border-color: var(--green); background: #effbe6; }
.tray-item .cnt { position: absolute; top: 2px; right: 4px; font-size: 11px; color: var(--wood-d); }
.tray-info { font-size: 13px; font-weight: 700; min-width: 140px; }
.tray-info b { font-size: 15px; display: block; }

#toolbar { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: rgba(40,30,20,.85); color: #fff; padding: 6px 8px 6px 14px; border-radius: 14px; display: flex; gap: 10px; align-items: center; font-weight: 800; box-shadow: var(--shadow); }

/* ---------- buttons ---------- */
.btn { font-family: var(--font); font-weight: 900; font-size: 14px; border-radius: 12px; border: 3px solid var(--green-d); background: linear-gradient(#7fd35c, var(--green)); color: #fff; padding: 7px 14px; cursor: pointer; text-shadow: 0 1px 0 rgba(0,0,0,.35); box-shadow: 0 3px 0 rgba(0,0,0,.25); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; justify-content: center; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn:disabled { filter: grayscale(1); opacity: .55; cursor: not-allowed; }
.btn.small { padding: 4px 10px; font-size: 12px; border-radius: 10px; }
.btn.red { border-color: var(--red-d); background: linear-gradient(#f2785f, var(--red)); }
.btn.blue { border-color: var(--blue-d); background: linear-gradient(#6cbaf2, var(--blue)); }
.btn.gold { border-color: #b8860b; background: linear-gradient(#ffe066, #f0b000); color: #5a3a00; text-shadow: none; }
.btn.wood { border-color: var(--wood-d); background: linear-gradient(#b07a4a, var(--wood)); }
.btn img { width: 18px; height: 18px; }

/* ---------- modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.modal-bg { position: absolute; inset: 0; background: rgba(20,30,10,.45); pointer-events: auto; animation: fade .2s; display: flex; align-items: center; justify-content: center; padding: 10px; }
.modal { width: min(820px, 100%); max-height: min(88vh, 100%); background: var(--cream); border: 5px solid var(--wood); border-radius: 22px; box-shadow: 0 10px 0 rgba(0,0,0,.25), 0 20px 50px rgba(0,0,0,.35); display: flex; flex-direction: column; overflow: hidden; animation: pop .25s ease-out; }
.modal.small { width: min(440px, 100%); }
.modal.medium { width: min(600px, 100%); }
.modal-head { background: linear-gradient(#b07a4a, var(--wood)); color: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 900; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
.modal-head img { width: 34px; height: 34px; }
.modal-head .x { margin-left: auto; width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--red-d); background: var(--red); color: #fff; font-size: 18px; font-weight: 900; cursor: pointer; line-height: 1; }
.tabs { display: flex; gap: 4px; padding: 8px 10px 0; background: var(--cream-d); overflow-x: auto; flex: none; }
.tab { padding: 8px 14px; border-radius: 12px 12px 0 0; background: #e2cc9c; font-weight: 800; cursor: pointer; border: none; font-family: var(--font); color: var(--text); font-size: 13px; white-space: nowrap; position: relative; }
.tab.on { background: var(--cream); }
.tab .badge { top: -4px; right: -4px; min-width: 18px; height: 18px; font-size: 10px; }
.modal-body { padding: 12px; overflow-y: auto; flex: 1; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.card { background: #fff; border: 3px solid var(--cream-d); border-radius: 14px; padding: 8px; text-align: center; position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; touch-action: none; }
.card.click { cursor: pointer; transition: transform .1s, border-color .1s; }
.card.click:hover { transform: translateY(-3px); border-color: var(--gold); }
.card.locked { opacity: .6; }
.card.locked::after { content: ""; position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; background: var(--lock) center/contain no-repeat; }
.card img.thumb { width: 96px; height: 96px; pointer-events: none; }
.card img.ic { width: 44px; height: 44px; }
.card .name { font-weight: 900; font-size: 14px; }
.card .meta { font-size: 11px; opacity: .75; }
.card .price { display: flex; align-items: center; gap: 3px; font-weight: 900; }
.card .price img { width: 18px; height: 18px; }
.card.done { background: #ebf9e1; border-color: #9fd27f; }

.row { display: flex; align-items: center; gap: 10px; background: #fff; border: 3px solid var(--cream-d); border-radius: 14px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; font-weight: 700; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 120px; }
.row img.ic { width: 38px; height: 38px; }
.row b.t { font-size: 15px; font-weight: 900; display: block; }
.req { display: inline-flex; align-items: center; gap: 2px; background: #f7efdc; border-radius: 8px; padding: 2px 6px 2px 2px; margin: 2px; font-weight: 800; font-size: 12px; }
.req img { width: 24px; height: 24px; }
.req.ok { background: #e2f6d6; color: #2e6b18; }
.req.no { background: #fde2dc; color: #a8341f; }
.pbar { height: 10px; background: #e3d3ad; border-radius: 5px; overflow: hidden; margin-top: 4px; }
.pbar > div { height: 100%; background: linear-gradient(#9be27a, var(--green)); }
.stat-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--cream-d); font-weight: 700; font-size: 13px; }
.section-title { font-weight: 900; font-size: 15px; margin: 10px 0 6px; display: flex; align-items: center; gap: 6px; }
.muted { opacity: .7; font-size: 12px; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.center { text-align: center; }
.slots { display: flex; gap: 6px; flex-wrap: wrap; }
.slot { width: 56px; height: 56px; border-radius: 12px; border: 3px dashed var(--cream-d); background: #fff; display: grid; place-items: center; position: relative; }
.slot img { width: 38px; height: 38px; }
.slot.filled { border-style: solid; border-color: #9fd27f; background: #f2fbea; cursor: pointer; }
.slot.working { border-style: solid; border-color: var(--gold); }
.slot .tm { position: absolute; bottom: -2px; left: 0; right: 0; font-size: 10px; font-weight: 800; text-align: center; }
.animal-card { width: 150px; }
.mini-stat { display: flex; align-items: center; gap: 4px; font-size: 11px; width: 100%; }
.mini-stat span { width: 52px; text-align: left; }
.mini-stat .pbar { flex: 1; margin: 0; height: 8px; }
.mini-stat .pbar.food > div { background: linear-gradient(#ffd27a, #f0a020); }
.mini-stat .pbar.hap > div { background: linear-gradient(#ffb3c7, #ff5c8a); }
.mini-stat .pbar.hp > div { background: linear-gradient(#9be27a, #3d8a27); }
input[type=text], select { font-family: var(--font); font-size: 15px; font-weight: 700; padding: 8px 10px; border: 3px solid var(--cream-d); border-radius: 10px; background: #fff; color: var(--text); width: 100%; }
input[type=range] { width: 100%; accent-color: var(--green); }
.setting { display: grid; grid-template-columns: 160px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; font-weight: 800; }
.login-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.login-day { background: #fff; border: 3px solid var(--cream-d); border-radius: 12px; padding: 6px 2px; text-align: center; font-size: 11px; font-weight: 800; }
.login-day img { width: 32px; height: 32px; }
.login-day.today { border-color: var(--gold); background: #fff7d6; transform: scale(1.06); }
.login-day.past { opacity: .5; }
.big-reward { text-align: center; padding: 10px; }
.big-reward .lv { font-size: 72px; font-weight: 900; color: var(--green-d); text-shadow: 0 4px 0 #fff, 0 6px 0 rgba(0,0,0,.2); }
.unlock-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.unlock-list div { background: #fff; border-radius: 12px; padding: 6px; border: 3px solid var(--cream-d); font-size: 11px; font-weight: 800; width: 84px; }
.unlock-list img { width: 48px; height: 48px; }
.chart { width: 100%; height: 200px; background: #fff; border-radius: 12px; border: 3px solid var(--cream-d); }
.trend-up { color: #2e8b1f; } .trend-down { color: #c0392b; }

/* toasts */
#toasts { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(255,246,226,.97); border: 3px solid var(--green-d); border-radius: 14px; padding: 8px 16px; font-weight: 800; box-shadow: var(--shadow); animation: pop .3s ease-out; display: flex; align-items: center; gap: 8px; max-width: 90vw; }
.toast img { width: 26px; height: 26px; }
.toast.bad { border-color: var(--red-d); background: #ffe7e0; }
.toast.out { opacity: 0; transition: opacity .4s; }

#drag-ghost { position: fixed; z-index: 60; pointer-events: none; width: 80px; height: 80px; transform: translate(-50%, -50%); opacity: .85; }
#drag-ghost img { width: 100%; height: 100%; }

@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .hud-chip { height: 34px; border-width: 2px; font-size: 13px; padding: 2px 8px 2px 3px; }
  .hud-chip img { width: 22px; height: 22px; }
  .hud-chip.farm { display: none; }
  .hud-chip.level { min-width: 120px; }
  .lvl-badge { width: 28px; height: 28px; font-size: 13px; }
  .hud-chip.money span { min-width: 30px; font-size: 14px; }
  .hud-chip.store span { display: none; }
  .hud-chip.store { width: 46px; }
  .mini-bar { left: 4px; right: 4px; }
  .hud-chip.clock { margin-left: 0; }
  #sidebar { top: auto; bottom: 8px; right: 6px; max-height: calc(100% - 170px); }
  .side-btn { width: 54px; height: 50px; border-radius: 12px; }
  .side-btn .si { width: 26px; height: 26px; }
  .side-btn em { font-size: 9px; }
  #events { top: 96px; }
  .ev-chip { font-size: 11px; max-width: 180px; }
  #tray { max-width: calc(100% - 130px); left: calc(50% - 20px); padding: 6px; gap: 6px; }
  .tray-item { width: 54px; min-width: 54px; height: 64px; }
  .tray-item img { width: 32px; height: 32px; }
  .modal { border-width: 3px; border-radius: 16px; max-height: 94vh; }
  .modal-head { font-size: 17px; padding: 8px 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
  .card img.thumb { width: 72px; height: 72px; }
  .setting { grid-template-columns: 1fr; gap: 4px; }
  #toolbar { top: 100px; }
}
