/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green:    #4a7c3f;
  --green-l:  #5c9950;
  --gold:     #d4a017;
  --red:      #c0392b;
  --ink:      #1e1a14;
  --muted:    #7a6e5e;
  --surface:  #fffdf8;
  --bg:       #f4efe5;
  --border:   rgba(30,26,20,0.13);
  --radius:   18px;
  --nav-h:    58px;
  --hud-h:    44px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #1a2b12;
  color: var(--ink);
  font-size: 16px;
  overflow: hidden;
}

button {
  cursor: pointer;
  font: inherit;
  border: none;
  border-radius: 12px;
  transition: opacity 0.15s, transform 0.1s;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.42; cursor: not-allowed; }

/* ── App shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-width: 700px;
  margin: 0 auto;
  background: var(--surface);
  position: relative;
  overflow: hidden;
}

/* ── HUD ────────────────────────────────────────────────────────────────────── */
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: var(--hud-h);
  background: var(--green);
  color: #fff;
  flex-shrink: 0;
  z-index: 10;
}

.hud-stat {
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ── Canvas ─────────────────────────────────────────────────────────────────── */
#farm-canvas {
  display: block;
  flex: 1;
  width: 100%;
  touch-action: none;
  cursor: pointer;
  background: #6ea34e;
  transition: flex 0.3s;
}

#farm-canvas.panel-open {
  flex: 0 0 200px;
}

/* ── Slide-up panels ────────────────────────────────────────────────────────── */
.panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--nav-h);
  max-height: calc(100dvh - var(--hud-h) - var(--nav-h) - 8px);
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  z-index: 20;
  animation: slide-up 0.22s ease;
}

.panel.hidden { display: none; }

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1.05rem;
  font-weight: 800;
}

.panel-close {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-body {
  overflow-y: auto;
  padding: 14px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Shop ───────────────────────────────────────────────────────────────────── */
.shop-section-title {
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 6px;
}

.shop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 14px;
  border: 1px solid var(--border);
}

.shop-card--done {
  justify-content: center;
  color: var(--green);
  font-weight: 700;
  font-size: 0.9rem;
}

.shop-icon { font-size: 1.8rem; flex-shrink: 0; }
.shop-meta { flex: 1; min-width: 0; }
.shop-meta strong { display: block; font-size: 0.92rem; }
.shop-desc { font-size: 0.78rem; color: var(--muted); }

.btn-buy {
  background: var(--green);
  color: #fff;
  padding: 9px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  border-radius: 10px;
}
.btn-buy:hover:not(:disabled) { background: var(--green-l); }

.danger-zone { margin-top: 8px; }

/* ── Market ─────────────────────────────────────────────────────────────────── */
#market-list { display: flex; flex-direction: column; gap: 10px; }

.market-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 14px;
  border: 1px solid var(--border);
}

.market-icon { font-size: 1.7rem; flex-shrink: 0; }
.market-meta { flex: 1; min-width: 0; }
.market-meta strong { display: block; font-size: 0.92rem; }
.market-sub { font-size: 0.78rem; color: var(--muted); }

.btn-sell {
  background: var(--gold);
  color: #fff;
  padding: 9px 12px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  border-radius: 10px;
}

/* ── Inventory ──────────────────────────────────────────────────────────────── */
#inventory-list { display: flex; flex-direction: column; gap: 8px; }

.inv-row {
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 0.92rem;
  font-weight: 600;
}

/* ── Shared buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--green);
  color: #fff;
  padding: 13px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 14px;
}
.btn-primary:hover:not(:disabled) { background: var(--green-l); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1.5px solid var(--border);
  padding: 11px 18px;
  font-size: 0.88rem;
  border-radius: 12px;
}

.full-width { width: 100%; }

/* ── Bottom nav ─────────────────────────────────────────────────────────────── */
#bottom-nav {
  display: flex;
  height: var(--nav-h);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 10;
}

.tab-btn {
  flex: 1;
  background: none;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-top: 3px solid transparent;
  padding: 6px 4px 8px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-icon { font-size: 1.25rem; line-height: 1; }
.tab-btn.active { color: var(--green); border-color: var(--green); }

/* ── Flash ──────────────────────────────────────────────────────────────────── */
#flash {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(20,15,10,0.88);
  color: #fff;
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 100;
  white-space: nowrap;
  max-width: calc(100% - 40px);
  text-align: center;
}
#flash.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Desktop ────────────────────────────────────────────────────────────────── */
@media (min-width: 720px) {
  #app {
    max-width: 700px;
    border-radius: 0 0 24px 24px;
    margin: 0 auto;
    height: 100dvh;
    box-shadow: 0 0 60px rgba(0,0,0,0.3);
  }
}
