/* ================================================================
   Colheita Feliz 3D — estilo da interface
   Tokens primeiro, depois componentes. Paleta fechada de propósito:
   verde = ação/confirma, âmbar = pesquisa/produção, vermelho = destrutivo.
   ================================================================ */
:root {
  --bg: #0e140d;
  --panel: rgba(16, 22, 15, .975);
  --surface: rgba(255, 255, 255, .055);
  --surface-2: rgba(255, 255, 255, .10);
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);

  --text: #eef2ea;
  --muted: rgba(238, 242, 234, .60);

  --green: #8bd450;
  --green-deep: #4d7a2f;
  --amber: #f2b13c;
  --blue: #5aa2e0;
  --red: #d4553f;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --sh-1: 0 2px 6px rgba(0, 0, 0, .28);
  --sh-2: 0 6px 18px rgba(0, 0, 0, .34);
  --sh-panel: -14px 0 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  font-size: 14px;
}
#canvas-container { position: fixed; inset: 0; }
#canvas-container canvas { display: block; touch-action: none; }

button { font-family: inherit; }

/* ================= HUD ================= */
#hud {
  position: fixed; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
}
#hud * { pointer-events: auto; }

/* ---- barra superior ---- */
#topbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .58), rgba(0, 0, 0, .12) 70%, transparent);
}
.stat {
  display: flex; align-items: center; gap: 6px;
  background: rgba(8, 12, 7, .62);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-weight: 650; font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: var(--sh-1);
  backdrop-filter: blur(6px);
}
.stat .icon { font-size: 14px; line-height: 1; }
#day-label { letter-spacing: .01em; }

#energy-bar-wrap {
  width: 88px; height: 7px; background: rgba(0, 0, 0, .5); border-radius: var(--r-pill);
  overflow: hidden; border: 1px solid rgba(255, 255, 255, .14);
}
#energy-bar-fill {
  height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--green-deep), var(--green));
  transition: width .35s ease;
}
#topbar-spacer { flex: 1; }

.toggle-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: rgba(8, 12, 7, .72); color: var(--text);
  font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  box-shadow: var(--sh-1);
  transition: transform .12s ease, background .16s ease, border-color .16s ease;
  backdrop-filter: blur(6px);
}
.toggle-btn:hover { background: rgba(30, 44, 26, .85); border-color: var(--green); }
.toggle-btn:active { transform: scale(.93); }

/* ---- barra inferior: sementes ---- */
#toolbar {
  display: flex; gap: 8px; padding: 12px;
  overflow-x: auto; scrollbar-width: none;
  background: linear-gradient(to top, rgba(0, 0, 0, .55), transparent);
}
#toolbar::-webkit-scrollbar { display: none; }
.seed-btn {
  flex: 0 0 auto; width: 54px; height: 54px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: rgba(10, 15, 9, .78);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  cursor: pointer; color: var(--text);
  box-shadow: var(--sh-1);
  transition: transform .12s ease, border-color .16s ease, background .16s ease;
  backdrop-filter: blur(6px);
}
.seed-btn:hover { background: rgba(28, 40, 24, .85); }
.seed-btn:active { transform: scale(.95); }
.seed-btn.selected {
  border-color: var(--green);
  background: rgba(60, 96, 40, .9);
  box-shadow: 0 0 0 2px rgba(139, 212, 80, .28), var(--sh-1);
}
.seed-btn .emoji { font-size: 21px; line-height: 1; }
.seed-btn .count { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seed-btn.disabled { opacity: .38; }

/* ================= painel lateral ================= */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(380px, 94vw);
  background: var(--panel);
  backdrop-filter: blur(10px);
  transform: translateX(105%);
  transition: transform .28s cubic-bezier(.22, .61, .36, 1);
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border);
  box-shadow: var(--sh-panel);
}
.panel.open { transform: translateX(0); }

.panel h2 {
  margin: 0; font-size: 16px; font-weight: 650; letter-spacing: .01em;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.panel .close-btn {
  cursor: pointer; font-size: 14px; background: var(--surface); border: none; color: var(--text);
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  transition: background .16s ease, transform .12s ease;
}
.panel .close-btn:hover { background: var(--surface-2); }
.panel .close-btn:active { transform: scale(.92); }

/* ---- grade de abas: todas visíveis de uma vez, sem rolagem lateral ---- */
.panel-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-tab-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0;
  padding: 7px 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer; font-size: 10.5px; font-weight: 600;
  line-height: 1.15;
  text-align: center;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .1s ease;
}
.panel-tab-btn .t-ico { font-size: 16px; line-height: 1; }
.panel-tab-btn .t-lbl { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-tab-btn:hover { background: var(--surface-2); color: var(--text); }
.panel-tab-btn:active { transform: scale(.96); }
.panel-tab-btn.active {
  background: var(--green-deep); border-color: var(--green); color: #fff;
  box-shadow: 0 2px 10px rgba(139, 212, 80, .22);
}

/* pílula horizontal reutilizável (amostras de genética etc.) */
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer; font-size: 12.5px; font-weight: 600;
  white-space: nowrap;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .1s ease;
}
.chip-btn .t-ico { font-size: 13px; line-height: 1; }
.chip-btn:hover { background: var(--surface-2); color: var(--text); }
.chip-btn:active { transform: scale(.96); }

.panel-body {
  overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 16px 20px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .16) transparent;
}
.panel-body::-webkit-scrollbar { width: 9px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .14); border-radius: var(--r-pill); border: 2px solid transparent; background-clip: content-box; }
.panel-body::-webkit-scrollbar-track { background: transparent; }

/* estado vazio / texto auxiliar dentro do painel */
.panel-body p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 18px; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--r-md);
  color: var(--muted);
}
.empty-state .es-ico { font-size: 28px; opacity: .8; }
.empty-state b { color: var(--text); font-weight: 650; }

.section-label {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin: 10px 2px 2px;
}
.section-label:first-child { margin-top: 0; }

/* ================= cartões ================= */
.item-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 11px;
  transition: background .16s ease, border-color .16s ease;
}
.item-row:hover { background: var(--surface-2); }
.item-row .emoji { font-size: 20px; width: 24px; text-align: center; flex: 0 0 auto; }
.item-row .name { flex: 1; font-size: 13px; font-weight: 550; line-height: 1.3; }
.item-row .qty {
  color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums;
  background: rgba(0, 0, 0, .28); border-radius: var(--r-pill); padding: 2px 8px; flex: 0 0 auto;
}

.research-node {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  font-size: 12.5px;
  box-shadow: var(--sh-1);
}
.research-node.locked { opacity: .5; }
.research-node.done { border-color: rgba(139, 212, 80, .5); background: rgba(139, 212, 80, .1); }
.research-node .rn-title {
  font-weight: 650; font-size: 13.5px; margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.research-node .rn-title > span:last-child { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.research-node.done .rn-title > span:last-child { color: var(--green); }
.research-node .rn-desc { color: var(--muted); margin-bottom: 9px; line-height: 1.45; }
.research-node .rn-desc b { color: var(--text); font-weight: 600; }

/* linhas de "tecla → o que faz" da aba Ajuda */
.help-row {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px; line-height: 1.45;
}
.help-row:last-child { border-bottom: none; padding-bottom: 0; }
.help-row:first-child { padding-top: 0; }
.help-row b { flex: 0 0 42%; color: var(--text); font-weight: 650; }
.help-row span { color: var(--muted); }
.research-node .rn-cost { margin-bottom: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.research-node .rn-cost > span {
  background: rgba(0, 0, 0, .3); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 3px 9px; font-size: 11.5px; color: var(--muted);
}

/* barra de progresso (fundição / cozinha / curral) */
.progress {
  background: rgba(0, 0, 0, .38); border-radius: var(--r-pill);
  height: 7px; overflow: hidden; margin-bottom: 9px;
  border: 1px solid rgba(255, 255, 255, .07);
}
.progress > i { display: block; height: 100%; border-radius: var(--r-pill); background: linear-gradient(90deg, #d98a2b, var(--amber)); transition: width .4s linear; }
.progress.green > i { background: linear-gradient(90deg, var(--green-deep), var(--green)); }
.progress.red > i { background: linear-gradient(90deg, #a33a28, var(--red)); }

/* ================= botões ================= */
.item-row button,
.research-node button,
.btn {
  border: none; cursor: pointer; font-weight: 650;
  border-radius: var(--r-sm);
  transition: transform .1s ease, filter .14s ease, background .14s ease;
  color: #14210b; background: var(--green);
  box-shadow: var(--sh-1);
}
.item-row button { padding: 6px 10px; font-size: 12px; flex: 0 0 auto; }
.research-node button, .btn { width: 100%; padding: 9px; font-size: 13px; border-radius: var(--r-sm); }
.research-node button { background: var(--amber); color: #2a1c00; }

.item-row button:hover:not(:disabled),
.research-node button:hover:not(:disabled),
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.item-row button:active:not(:disabled),
.research-node button:active:not(:disabled),
.btn:active:not(:disabled) { transform: scale(.97); }

.item-row button:disabled,
.research-node button:disabled,
.btn:disabled {
  background: rgba(255, 255, 255, .07); color: rgba(238, 242, 234, .32);
  cursor: not-allowed; box-shadow: none;
}

.btn.secondary, .item-row button.secondary { background: var(--blue); color: #06121d; }
.btn.ghost {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: none;
}
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { background: var(--red); color: #fff; }

.btn-row { display: flex; flex-direction: column; gap: 6px; }

/* textarea (ajustes / save) */
.panel textarea {
  width: 100%; font: 11.5px/1.45 ui-monospace, Menlo, Consolas, monospace;
  border-radius: var(--r-sm); background: rgba(0, 0, 0, .35); color: var(--text);
  border: 1px solid var(--border); padding: 9px; resize: vertical;
}
.panel textarea:focus { outline: none; border-color: var(--green); }

/* ================= toasts ================= */
#toasts {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 7px; pointer-events: none; z-index: 50;
  align-items: center;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  background: rgba(10, 14, 9, .92);
  border: 1px solid var(--border-strong);
  padding: 9px 16px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 550; white-space: normal;
  max-width: 100%; text-align: center;
  box-shadow: var(--sh-2);
  backdrop-filter: blur(8px);
  animation: toast-in .22s cubic-bezier(.22, .61, .36, 1), toast-out .3s ease 1.85s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

/* ================= tela de carregamento ================= */
#loading {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(circle at 50% 42%, #1b2a17, var(--bg) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
#loading .l-title {
  font-size: 26px; font-weight: 700; letter-spacing: .02em;
  display: flex; align-items: center; gap: 10px;
}
#loading .l-sub { color: var(--muted); font-size: 13px; }
#loading .l-bar { width: 190px; height: 4px; border-radius: var(--r-pill); background: rgba(255, 255, 255, .1); overflow: hidden; }
#loading .l-bar > i { display: block; height: 100%; width: 40%; border-radius: var(--r-pill); background: linear-gradient(90deg, var(--green-deep), var(--green)); animation: l-slide 1.15s ease-in-out infinite; }
@keyframes l-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(350%); } }

/* ================= mobile ================= */
@media (max-width: 520px) {
  .stat { padding: 5px 10px; font-size: 12px; }
  #energy-bar-wrap { width: 62px; }
  .seed-btn { width: 48px; height: 48px; }
  .panel h2 { padding: 13px 13px 10px; font-size: 15px; }
  .panel-tabs { padding: 9px 13px; gap: 5px; }
  .panel-tab-btn { font-size: 10px; padding: 6px 2px; }
  .panel-body { padding: 12px 13px 18px; }
  #loading .l-title { font-size: 21px; }
}
