:root {
  --bg-0: #07110a;
  --bg-1: #0d1c12;
  --bg-2: #13291a;
  --border: #234a30;
  --border-hi: #3a6e46;
  --text: #d7ecd9;
  --muted: #7fa787;
  --accent: #7cd992;
  --accent-2: #f0c674;
  --danger: #c26b5a;
  --sky: #6da7c7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(1200px 600px at 20% -10%, #17321f 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #1a3a24 0%, transparent 55%),
    linear-gradient(180deg, #050b07 0%, #0a1a10 100%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  padding: 24px 20px 40px;
  display: flex;
  justify-content: center;
}

#app { max-width: 1220px; width: 100%; }

/* ---------- Header ---------- */

header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
}

.title-block h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(124, 217, 146, 0.35);
}
.title-block h1 .from {
  color: var(--accent-2);
  font-weight: 400;
  font-style: italic;
  font-size: 1.4rem;
  margin: 0 4px;
}
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }

.hud {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.hud-stat {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  min-width: 78px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: box-shadow 0.25s, border-color 0.25s;
}
.hud-stat.pulse {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 20px rgba(124,217,146,0.35);
}
.hud-stat .label {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.hud-stat strong {
  font-size: 1.05rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.hud-stat.weather strong { color: var(--accent-2); }

.canopy-stat { min-width: 120px; }
.canopy-stat #spark {
  display: block;
  margin: 4px auto 0;
  opacity: 0.85;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.difficulty {
  display: inline-flex;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.difficulty button {
  width: auto;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}
.difficulty button.active {
  background: var(--accent);
  color: #0a1a10;
  font-weight: 600;
}
.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-hi); }

/* ---------- Main ---------- */

#main {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  padding: 6px;
  background: linear-gradient(160deg, #1c3a26 0%, #0f2416 60%, #1a3524 100%);
  box-shadow:
    0 20px 60px rgba(0,0,0,0.6),
    0 0 0 1px rgba(124,217,146,0.08),
    inset 0 0 30px rgba(0,0,0,0.4);
}

#game {
  display: block;
  background: #0a1a10;
  border-radius: 6px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

.banner {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 26, 16, 0.92);
  border: 1px solid var(--border-hi);
  color: var(--accent);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.9rem;
  letter-spacing: 0.6px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5), 0 0 30px rgba(124,217,146,0.25);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.banner.hidden { opacity: 0; transform: translate(-50%, -8px); }

.toasts {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
.toast {
  background: linear-gradient(180deg, rgba(30, 58, 40, 0.96), rgba(19, 41, 26, 0.96));
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55), 0 0 24px rgba(124,217,146,0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in 0.3s ease;
  max-width: 260px;
}
.toast .toast-icon { font-size: 1.15rem; }
.toast .toast-title { font-weight: 700; color: var(--accent); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 1px; }
.toast .toast-text { color: var(--text); font-size: 0.82rem; margin-top: 1px; }
.toast.leaving { animation: toast-out 0.4s ease forwards; }

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(20px); opacity: 0; }
}

/* ---------- Sidebar ---------- */

#sidebar {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: linear-gradient(180deg, rgba(19,41,26,0.9), rgba(13,28,18,0.9));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

.panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--accent);
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.panel h2 .hint {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.6px;
  font-weight: 500;
  text-transform: none;
}

/* ---------- Tools ---------- */

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tool-btn {
  position: relative;
  background: linear-gradient(180deg, #1a2f22, #14261b);
  border: 1px solid #2c4a36;
  color: var(--text);
  padding: 10px 8px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.78rem;
  text-align: center;
  transition: transform 0.08s ease, border-color 0.15s, background 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.tool-btn .icon {
  display: block;
  font-size: 1.2rem;
  line-height: 1;
  margin-bottom: 4px;
}
.tool-btn .name { display: block; font-weight: 600; color: var(--text); }
.tool-btn .cost { display: block; font-size: 0.68rem; color: var(--muted); margin-top: 3px; }
.tool-btn .key {
  position: absolute;
  top: 4px;
  left: 6px;
  font-size: 0.6rem;
  color: var(--muted);
  opacity: 0.7;
}
.tool-btn:hover { border-color: var(--border-hi); transform: translateY(-1px); }
.tool-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #22462d, #1a3624);
  box-shadow: 0 0 0 1px var(--accent), 0 0 18px rgba(124,217,146,0.3);
}

/* ---------- Info ---------- */

.info-panel #tooltip {
  font-size: 0.88rem;
  line-height: 1.45;
  min-height: 2.6em;
  color: var(--text);
}
.info-panel #tile-info {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: "SFMono-Regular", Menlo, monospace;
}
.muted { opacity: 0.75; }

/* ---------- Actions ---------- */

button {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  transition: filter 0.15s, transform 0.08s;
}
button:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

#advance {
  background: linear-gradient(180deg, #2f8a3f, #256b32);
  color: white;
  border-color: #3fa054;
  box-shadow: 0 4px 14px rgba(47, 138, 63, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
#advance kbd {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-family: inherit;
}

.actions .row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.actions .secondary {
  background: rgba(60, 90, 70, 0.3);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 1;
}
.actions .secondary:hover { background: rgba(60,90,70,0.5); }

#reset {
  background: transparent;
  color: var(--danger);
  border-color: #5a2e26;
  margin-top: 8px;
}
#reset:hover { background: rgba(194,107,90,0.1); }

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  background: rgba(60,90,70,0.15);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.toggle input { accent-color: var(--accent); }

/* ---------- Achievements ---------- */

.achievements-panel ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}
.achievements-panel li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,0.15);
  border: 1px solid transparent;
  transition: background 0.2s;
}
.achievements-panel li.done {
  color: var(--text);
  border-color: var(--border);
  background: rgba(124,217,146,0.08);
}
.achievements-panel li .ach-icon {
  font-size: 1rem;
  filter: grayscale(1) opacity(0.5);
}
.achievements-panel li.done .ach-icon { filter: none; }
.achievements-panel li .ach-name { font-weight: 600; }
.achievements-panel li .ach-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.85;
}

/* ---------- Log ---------- */

.log-panel ul {
  list-style: none;
  max-height: 140px;
  overflow-y: auto;
  padding-right: 4px;
}
.log-panel li {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 0;
  border-bottom: 1px dashed rgba(124,217,146,0.1);
  line-height: 1.3;
}
.log-panel li:last-child { border-bottom: none; }
.log-panel li .day-tag {
  color: var(--accent);
  font-family: "SFMono-Regular", Menlo, monospace;
  margin-right: 6px;
}
.log-panel ul::-webkit-scrollbar,
.achievements-panel ul::-webkit-scrollbar { width: 6px; }
.log-panel ul::-webkit-scrollbar-thumb,
.achievements-panel ul::-webkit-scrollbar-thumb {
  background: var(--border-hi);
  border-radius: 3px;
}

/* ---------- Footer ---------- */

footer {
  text-align: center;
  margin-top: 22px;
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.75;
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  header { grid-template-columns: 1fr; text-align: center; }
  .hud { justify-content: center; }
  .header-controls { justify-content: center; }
  #sidebar { width: 100%; max-width: 640px; }
}
