:root {
  --sky-top: #dcefe3;
  --sky-bottom: #f6fbf4;
  --ink: #26361f;
  --ink-soft: #5b6b52;
  --cream: #fffdf7;
  --cream-dim: #f3f0e6;
  --leaf-alive-1: #2f6b29;
  --leaf-alive-2: #4f8f3f;
  --leaf-dead-1: #d69a3e;
  --leaf-dead-2: #e8bd6b;
  --trunk: #6b4226;
  --ground-1: #a3d18d;
  --ground-2: #6fa658;
  --ground-edge: #34592b;
  --accent: #2f5233;
  --accent-dark: #203a24;
  --danger: #b5502f;
  --shadow: rgba(31, 46, 26, 0.18);
  --radius: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 65%);
}

h1, h2, h3, .brand {
  font-family: "Inter", system-ui, sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Lock screen ---------- */

.lock-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 65%);
  z-index: 50;
}

#lock-form {
  background: var(--cream);
  padding: 40px 36px;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px var(--shadow);
  width: min(360px, 88vw);
  text-align: left;
}

#lock-form h1 {
  margin: 0 0 6px;
  font-size: 2rem;
  color: var(--accent-dark);
}

#lock-form p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

#lock-password {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid #d8d4c4;
  font-size: 1rem;
  margin-bottom: 14px;
  background: #fff;
}

#lock-password:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -6px 0 12px;
}

/* ---------- Shared buttons ---------- */

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: var(--cream);
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-ghost {
  background: rgba(255, 255, 255, 0.6);
  color: var(--accent-dark);
  border: 1.5px solid rgba(47, 82, 51, 0.25);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.9); }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-soft);
  padding: 4px 8px;
}

/* ---------- App shell ---------- */

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 18px 28px;
  flex: 0 0 auto;
}

.brand {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--accent-dark);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.app.presenting .topbar-actions {
  display: none;
}

.app.presenting .topbar {
  padding-top: 64px;
}

.forest {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  padding: 0 28px;
}

.plots {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  height: 100%;
  width: 100%;
}

.plots-row {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  gap: 18px;
}

.plot {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
}

/* 3+ projects: each plot is explicitly sized (via JS) to its own aspect
   ratio and grouped into rows chosen to use the most space, instead of
   being stretched into equal grid cells. Vertical centering is shared with
   the 1-2 project layout via .plots' own justify-content: center. */
.plots.packed .plots-row {
  flex: 0 0 auto;
  justify-content: center;
}

.plots.packed .plot {
  flex: 0 0 auto;
}

.plot-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.plot-title {
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(0.95rem, 1.4vw, 1.25rem);
  line-height: 1.4;
  padding-bottom: 0.15em;
  color: var(--ink);
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plot-count {
  font-size: 0.78rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.plot-svg-wrap {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.plot-svg-wrap svg {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

.tree-group { cursor: pointer; }
.tree-group .foliage { transition: fill 0.25s ease; }
.tree-group[data-alive="true"] .foliage { fill: url(#leafAliveGradient); }
.tree-group[data-alive="false"] .foliage { fill: url(#leafDeadGradient); }

.empty-state {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- Manage panel ---------- */

.manage-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 17, 0.28);
  z-index: 40;
}

.manage-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 92vw);
  background: var(--cream);
  box-shadow: -18px 0 40px var(--shadow);
  z-index: 41;
  padding: 26px 24px 24px;
  overflow-y: auto;
}

.manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.manage-header h2 {
  font-size: 1.3rem;
  margin: 0;
  color: var(--accent-dark);
}

.manage-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--cream-dim);
}

.manage-section:first-of-type { border-top: none; }

.manage-section label,
.manage-section h3 {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 10px;
  font-family: "Inter", sans-serif;
}

.manage-section h3 { font-size: 0.95rem; color: var(--ink); }

.add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-form input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1.5px solid #d8d4c4;
  font-size: 0.95rem;
  background: #fff;
}

.manage-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--cream-dim);
  border-radius: 12px;
  padding: 10px 10px;
}

.manage-row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  font-size: 0.92rem;
  color: var(--ink);
  padding: 4px 2px;
}

.manage-row input[type="text"]:focus {
  outline: none;
  border-bottom: 1.5px solid var(--accent);
}

.manage-row input[type="number"] {
  width: 58px;
  padding: 6px 6px;
  border-radius: 6px;
  border: 1.5px solid #d8d4c4;
  font-size: 0.88rem;
  text-align: center;
}

.manage-row .row-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  padding: 2px 4px;
}

.manage-empty {
  color: var(--ink-soft);
  font-size: 0.88rem;
}

[hidden] { display: none !important; }

@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .forest { padding: 0 12px; }
  .plots { gap: 10px; }
}
