/* ============================================================
   3dFarm — UI stylesheet
   Toy-shelf design language: soft pastels, fat radii, chunky
   type (Baloo 2 display / Nunito body). Mobile-first.
   ============================================================ */

:root {
  --sky:        #87ceeb;
  --cream:      #fffbf2;
  --card:       #fffefa;
  --ink:        #2d2318;
  --ink-soft:   #6b5b47;
  --grass:      #72c84a;
  --terracotta: #e8a07e;
  --coral:      #f4685c;
  --sun:        #f4a535;
  --teal:       #3ecfb2;
  --blueberry:  #3070e0;
  --leaf:       #62c040;
  --shadow:     0 6px 0 rgba(45, 35, 24, .12);
  --radius:     22px;
  --safe-b:     env(safe-area-inset-bottom, 0px);
  --safe-t:     env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Ensure [hidden] always wins regardless of author-stylesheet specificity.
   Without this, an ID-level display rule (e.g. #levelup { display:grid })
   overrides the UA-stylesheet's [hidden]{display:none} and the element
   stays visible even after element.hidden = true. */
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: var(--sky);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}

#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

h1, h2, h3, .level-badge { font-family: "Fredoka One", "Baloo 2", sans-serif; }
.dock-btn, .btn { font-family: "Baloo 2", "Nunito", sans-serif; }

/* ---------- Top HUD ---------- */
#hud {
  position: fixed; top: calc(10px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 10px; z-index: 20; pointer-events: none;
}
#hud > * { pointer-events: auto; }

.hud-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: none; border-radius: 999px;
  padding: 8px 16px; font-weight: 800; font-size: 16px; color: var(--ink);
  box-shadow: var(--shadow);
}
.hud-btn { font-family: "Baloo 2", sans-serif; cursor: pointer; margin-left: auto; }
.hud-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(74,59,50,.12); }
.hud-icon-btn { margin-left: 0; padding: 8px 12px; font-size: 18px; line-height: 1; }

.spool-icon {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at center, var(--card) 0 28%, var(--sun) 30% 100%);
  border: 3px solid var(--terracotta);
}

.hud-level { display: flex; align-items: center; gap: 8px; min-width: 0; }
.level-badge {
  background: var(--coral); color: #fff; border-radius: 999px;
  padding: 7px 13px; font-weight: 800; font-size: 15px; box-shadow: var(--shadow); white-space: nowrap;
}
.xp-track {
  width: clamp(60px, 18vw, 160px); height: 12px; border-radius: 999px;
  background: rgba(255,255,255,.55); overflow: hidden; box-shadow: inset 0 2px 3px rgba(74,59,50,.15);
}
.xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--sun), var(--coral)); border-radius: 999px; transition: width .4s ease; }

/* ---------- Bottom dock ---------- */
#dock {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + var(--safe-b)); z-index: 20;
  display: flex; gap: 8px; padding: 8px;
  background: var(--card); border-radius: 999px; box-shadow: var(--shadow);
  max-width: calc(100vw - 20px);
}
.dock-btn {
  position: relative; border: none; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 700; color: var(--ink-soft);
  padding: 6px 14px; border-radius: 18px; min-width: 64px; min-height: 52px;
}
.dock-btn .dock-ico { font-size: 22px; line-height: 1; }
.dock-btn.active, .dock-btn:active { background: var(--cream); color: var(--ink); }
.dock-badge {
  position: absolute; top: 0; right: 6px;
  background: var(--coral); color: #fff; font-size: 11px; font-weight: 800;
  border-radius: 999px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Sliding panel ---------- */
.panel {
  position: fixed; z-index: 30; background: var(--cream);
  box-shadow: 0 -10px 30px rgba(74,59,50,.18);
  display: flex; flex-direction: column;
  left: 0; right: 0; bottom: 0;
  max-height: min(72vh, 560px);
  border-radius: 28px 28px 0 0;
  padding-bottom: var(--safe-b);
  animation: panel-up .28s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes panel-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 8px;
}
.panel-head h2 { margin: 0; font-size: 22px; }
.panel-close {
  border: none; background: var(--card); border-radius: 50%;
  width: 38px; height: 38px; font-size: 15px; cursor: pointer; color: var(--ink);
  box-shadow: var(--shadow);
}
.panel-body { overflow-y: auto; padding: 6px 16px 18px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }

/* ---------- Plot quick-menu popup ---------- */
.plot-popup {
  position: fixed; z-index: 35; width: 240px; max-width: calc(100vw - 24px);
  max-height: min(64vh, 440px); overflow-y: auto;
  background: var(--cream); border-radius: var(--radius); box-shadow: 0 14px 34px rgba(74,59,50,.28);
  padding: 14px; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  animation: popup-in .15s ease-out;
}
.plot-popup .popup-close {
  position: absolute; top: 8px; right: 8px; border: none; background: var(--card);
  width: 28px; height: 28px; border-radius: 50%; font-size: 13px; line-height: 1;
  cursor: pointer; color: var(--ink); box-shadow: var(--shadow);
}
.plot-popup .popup-title {
  font-family: "Fredoka One", "Baloo 2", sans-serif; font-size: 15px; margin: 0 30px 8px 0;
}
.plot-popup .card-grid { grid-template-columns: 1fr; gap: 8px; }
@keyframes popup-in { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }

/* ---------- Cards inside panels ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.item-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.item-card.locked { opacity: .55; filter: saturate(.4); }
.item-card h3 { margin: 0; font-size: 16px; line-height: 1.2; }
.item-meta { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; }
.item-ico { font-size: 30px; line-height: 1; }

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: none; cursor: pointer; border-radius: 999px; padding: 6px 11px;
  font-size: 12.5px; font-weight: 800; background: var(--cream); color: var(--ink);
  min-height: 32px;
}
.chip.selected { outline: 3px solid var(--ink); outline-offset: -1px; }
.chip .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.15); }

/* Plain color-swatch buttons — used for seed color pick (just a dot, no label) */
.color-chip {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid rgba(0,0,0,.12); padding: 0; flex: 0 0 auto;
}
.color-chip:active { transform: scale(.9); }
.color-chip:disabled { opacity: .35; cursor: not-allowed; }

.btn {
  border: none; cursor: pointer; border-radius: 999px;
  padding: 10px 18px; font-size: 15px; font-weight: 700;
  min-height: 44px;
}
.btn.primary { background: var(--grass); color: #fff; box-shadow: 0 4px 0 #6e9a40; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #6e9a40; }
.btn.primary:disabled { background: #c9c2b8; box-shadow: 0 4px 0 #a9a297; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink-soft); }
.btn.coral { background: var(--coral); color: #fff; box-shadow: 0 4px 0 #b34334; }
.btn.coral:active { transform: translateY(2px); box-shadow: 0 2px 0 #b34334; }

.progress-track { height: 10px; border-radius: 999px; background: var(--cream); overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--leaf), var(--grass)); border-radius: 999px; transition: width .5s linear; }

.empty-note { text-align: center; color: var(--ink-soft); font-weight: 700; padding: 26px 10px; }

.section-label {
  font-family: "Baloo 2", sans-serif; font-size: 13px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft); margin: 16px 4px 8px;
}

/* Order cards */
.order-card { display: flex; align-items: center; gap: 12px; }
.order-card .grow { flex: 1; min-width: 0; }
.order-timer { font-size: 12px; font-weight: 800; color: var(--coral); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(74,59,50,.45);
  display: grid; place-items: center; padding: 18px;
}
.modal {
  background: var(--card); border-radius: 26px; padding: 22px;
  width: min(440px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25);
  max-height: 86vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 4px; }
.modal-sub { margin: 0 0 14px; color: var(--ink-soft); font-weight: 700; font-size: 14px; }
.modal label { display: block; font-weight: 800; font-size: 13px; margin-bottom: 12px; }
.modal input, .modal textarea {
  display: block; width: 100%; margin-top: 5px;
  border: 2px solid #e7ddcd; border-radius: 14px; padding: 11px 13px;
  font: inherit; color: var(--ink); background: var(--cream); resize: vertical;
}
.modal input:focus, .modal textarea:focus { outline: 3px solid var(--sun); border-color: transparent; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; top: calc(64px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: var(--ink); color: #fff; font-weight: 800; font-size: 14px;
  border-radius: 999px; padding: 9px 18px; box-shadow: 0 8px 20px rgba(0,0,0,.2);
  animation: toast-in .25s ease, toast-out .3s ease 2.4s forwards;
  max-width: 100%; text-align: center;
}
.toast.good { background: var(--grass); }
.toast.bad { background: var(--coral); }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toast-out { to { transform: translateY(-12px); opacity: 0; } }

/* ---------- Level up ---------- */
#levelup {
  position: fixed; inset: 0; z-index: 45; background: rgba(74,59,50,.4);
  display: grid; place-items: center; padding: 20px;
}
.levelup-card {
  background: var(--card); border-radius: 28px; padding: 28px 26px; text-align: center;
  width: min(360px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.3);
  animation: pop .35s cubic-bezier(.2,1.4,.4,1);
}
.levelup-burst { font-size: 44px; }
.levelup-card h2 { margin: 6px 0; font-size: 28px; }
.levelup-card p { color: var(--ink-soft); font-weight: 700; min-height: 20px; }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }

/* ---------- Loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 100; background: var(--sky);
  display: grid; place-content: center; text-align: center; gap: 4px;
  transition: opacity .5s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
#loader h1 { margin: 14px 0 0; font-size: 40px; color: #fff; text-shadow: 0 3px 0 rgba(74,59,50,.2); }
#loader p { margin: 0; color: #ffffffd9; font-weight: 800; }
.loader-spool {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 50%;
  border: 10px solid var(--card); border-top-color: var(--coral);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Settings modal: account section ---------- */
.settings-account-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.settings-account-row .hud-avatar { width: 36px; height: 36px; }
.settings-account-row .grow { flex: 1; min-width: 0; }
.settings-account-row .grow strong { display: block; font-size: 15px; }
.settings-account-row .grow span { font-size: 12.5px; color: var(--ink-soft); font-weight: 700; }

/* ---------- HUD account pill ---------- */
.hud-user { gap: 8px; }
.hud-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.hud-avatar[hidden] { display: none; }
.hud-logout {
  border: none; background: var(--cream); color: var(--ink-soft); cursor: pointer;
  width: 26px; height: 26px; border-radius: 50%; font-size: 13px; line-height: 1; padding: 0;
}

/* ---------- Login screen ---------- */
#login-screen {
  position: fixed; inset: 0; z-index: 95; background: var(--sky);
  display: grid; place-items: center; padding: 20px; text-align: center;
}
.login-card {
  background: var(--card); border-radius: 28px; padding: 28px 24px;
  width: min(380px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 32px; color: var(--ink); }
.login-card p { margin: 0; color: var(--ink-soft); font-weight: 700; font-size: 14px; }
.g-signin { min-height: 44px; }
.login-note { color: var(--coral) !important; font-size: 13px; }

/* ---------- Larger screens: panel docks right ---------- */
@media (min-width: 760px) {
  .panel {
    left: auto; right: 16px; bottom: 90px; top: calc(76px + var(--safe-t));
    width: 400px; max-height: none; border-radius: 28px;
  }
  #dock { bottom: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
