:root {
  --bark: #4a3a28;
  --moss: #6b8a4a;
  --leaf: #8fc18a;
  --sky: #e8e3d0;
  --paper: #f5efde;
  --paper-warm: #fcf6e3;
  --warm-shadow: rgba(64, 40, 24, 0.18);
  --warm-shadow-strong: rgba(64, 40, 24, 0.32);
  --accent: #cf8a3c;
  --accent-deep: #8a5a1f;
  --bad: #c25a4a;
  --good: #4f8a4a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(180deg, #f0ead5 0%, #d6e2c0 100%);
  font-family: "Quicksand", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #2c2418;
  overflow: hidden;
}

#forest-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

.hidden { display: none !important; }

/* ----- Loading screen ----- */

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #f0ead5 0%, #d6e2c0 100%);
  transition: opacity 600ms ease;
}
#loading-screen.fade {
  opacity: 0;
  pointer-events: none;
}
.loading-inner {
  text-align: center;
  color: var(--accent-deep);
  font-family: "Caveat", cursive;
  font-size: 22px;
}
.loading-leaf {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  background: radial-gradient(circle at 30% 30%, #b4d4a0 0%, #6b8a4a 70%);
  border-radius: 0 100% 0 100%;
  transform: rotate(-25deg);
  animation: leafSway 2.4s ease-in-out infinite;
  box-shadow: 0 6px 12px rgba(80, 100, 60, 0.25);
}
@keyframes leafSway {
  0%, 100% { transform: rotate(-25deg) translateY(0); }
  50% { transform: rotate(-10deg) translateY(-6px); }
}

/* ----- Overlay screens (name entry) ----- */

.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(245, 239, 222, 0.92);
  backdrop-filter: blur(4px);
}
.overlay-card {
  background: var(--paper-warm);
  border: 1px solid rgba(74, 58, 40, 0.18);
  border-radius: 16px;
  padding: 32px 36px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 18px 42px var(--warm-shadow-strong);
}
.overlay-card .title {
  font-family: "Caveat", cursive;
  font-size: 44px;
  margin: 0 0 4px;
  color: var(--accent-deep);
  letter-spacing: 0.02em;
}
.overlay-card .muted { color: #8a7958; font-size: 13px; margin: 0 0 18px; }
.overlay-card .lede { line-height: 1.55; margin: 0 0 22px; }
.overlay-card label { display: block; font-size: 14px; margin: 0 0 6px; }
.overlay-card input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(74, 58, 40, 0.25);
  background: var(--paper);
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 18px;
}

.leaf-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(207, 138, 60, 0.35);
  transition: transform 80ms ease, box-shadow 120ms ease, background 120ms ease;
}
.leaf-btn:hover { transform: translateY(-1px); background: var(--accent-deep); }
.leaf-btn:active { transform: translateY(0); }
.leaf-btn.small { padding: 8px 14px; font-size: 13px; }

.controls-help {
  margin-top: 22px;
  font-size: 13px;
  color: #5a4a32;
}
.controls-help summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}
.controls-help ul {
  margin: 12px 0 0;
  padding-left: 18px;
  line-height: 1.7;
}

/* ----- HUD ----- */

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  font-size: 14px;
}
#hud .hud-left,
#hud .hud-right {
  background: rgba(252, 246, 227, 0.88);
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 6px 14px var(--warm-shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
#hud .leaf-icon {
  width: 16px;
  height: 16px;
  background: radial-gradient(circle at 30% 30%, #b4d4a0 0%, #6b8a4a 70%);
  border-radius: 0 100% 0 100%;
  transform: rotate(-25deg);
  display: inline-block;
}
#hud .muted { color: #8a7958; }
#mute-btn {
  background: transparent;
  border: 1px solid rgba(74, 58, 40, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  color: #5a4a32;
}
#mute-btn.muted-on { opacity: 0.5; text-decoration: line-through; }

/* ----- Approach prompt ----- */

.approach {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(252, 246, 227, 0.94);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 18px var(--warm-shadow);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  z-index: 40;
  animation: approachFloat 2.4s ease-in-out infinite;
}
@keyframes approachFloat {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-3px); }
}
.approach .key {
  background: var(--accent-deep);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* ----- Modal ----- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(32, 24, 12, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modalIn 220ms ease;
}
@keyframes modalIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-card {
  background: var(--paper-warm);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 52px var(--warm-shadow-strong);
}
.modal-card.wide { max-width: 680px; }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(74, 58, 40, 0.1);
}
.creature-tag {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.creature-tag .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(207, 138, 60, 0.25);
}
.creature-tag .dot.ok { background: var(--good); box-shadow: 0 0 0 3px rgba(79, 138, 74, 0.25); }
.creature-tag .small { font-size: 12px; font-weight: 400; }
.close-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  color: #8a7958;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.close-btn:hover { background: rgba(74, 58, 40, 0.08); color: #2c2418; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.greeting {
  font-family: "Caveat", cursive;
  font-size: 20px;
  line-height: 1.45;
  color: var(--accent-deep);
  margin: 0 0 20px;
  padding: 12px 16px;
  background: rgba(207, 138, 60, 0.08);
  border-radius: 12px;
  border-left: 3px solid var(--accent);
}

.q-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.q-meta .small { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.diff-pill {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 700;
  background: rgba(74, 58, 40, 0.08);
  color: #5a4a32;
}
.diff-pill[data-diff="easy"] { background: rgba(79, 138, 74, 0.12); color: var(--good); }
.diff-pill[data-diff="medium"] { background: rgba(207, 138, 60, 0.14); color: var(--accent-deep); }
.diff-pill[data-diff="hard"] { background: rgba(194, 90, 74, 0.14); color: var(--bad); }

.q-prompt {
  font-size: 16px;
  line-height: 1.55;
  margin: 6px 0 16px;
  white-space: pre-wrap;
}
.options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.option-btn {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  background: var(--paper);
  border: 1px solid rgba(74, 58, 40, 0.15);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: inherit;
  cursor: pointer;
  transition: background 100ms ease, border-color 100ms ease, transform 80ms ease;
}
.option-btn:hover {
  background: rgba(207, 138, 60, 0.06);
  border-color: var(--accent);
}
.option-btn:disabled { cursor: default; opacity: 0.88; }
.option-btn .letter {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(74, 58, 40, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #5a4a32;
}
.option-btn.correct {
  background: rgba(79, 138, 74, 0.12);
  border-color: var(--good);
}
.option-btn.correct .letter { background: var(--good); color: #fff; }
.option-btn.wrong {
  background: rgba(194, 90, 74, 0.1);
  border-color: var(--bad);
}
.option-btn.wrong .letter { background: var(--bad); color: #fff; }

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.feedback.good {
  background: rgba(79, 138, 74, 0.1);
  border-left: 3px solid var(--good);
}
.feedback.bad {
  background: rgba(194, 90, 74, 0.08);
  border-left: 3px solid var(--bad);
}

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid rgba(74, 58, 40, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.modal-foot.stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}
.export-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.export-row label { font-size: 13px; color: #5a4a32; flex-shrink: 0; }
.export-row input {
  flex: 1;
  min-width: 140px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(74, 58, 40, 0.2);
  background: var(--paper);
  font-family: inherit;
  font-size: 14px;
}

.signpost-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.summary-card {
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(74, 58, 40, 0.12);
}
.summary-card .name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.summary-card .score { font-size: 18px; font-weight: 700; color: var(--accent-deep); }
.summary-card .score .sep { color: #8a7958; font-weight: 400; }
.summary-card.helped { background: rgba(79, 138, 74, 0.08); border-color: var(--good); }
.summary-card.helped .score { color: var(--good); }

/* ----- Floating world tag (creature name above NPC) ----- */

.world-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: none;
  background: rgba(252, 246, 227, 0.92);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 4px 10px var(--warm-shadow);
  z-index: 30;
  color: #2c2418;
  transition: opacity 200ms ease;
}
.world-tag.dim { opacity: 0.4; }
.world-tag.helped { background: rgba(79, 138, 74, 0.18); color: var(--good); }
