:root {
  --sky: #9edaf2;
  --grass: #8bcf6b;
  --grass-dark: #5ea65b;
  --soil: #b87542;
  --path: #e9ba73;
  --wood: #8e562f;
  --cream: #fff5dc;
  --ink: #26302a;
  --muted: #677060;
  --sun: #ffd36b;
  --blue: #4b9bd8;
  --good: #2d9b67;
  --warn: #d98b28;
  font-family: "Nunito", "Trebuchet MS", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 211, 107, 0.32), transparent 24rem),
    linear-gradient(180deg, #dff6ff 0%, #f3ffe3 52%, #f7edcf 100%);
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 18px;
  min-height: 100vh;
}

.game-stage,
.side-panel {
  background: rgba(255, 250, 231, 0.84);
  border: 3px solid rgba(115, 82, 39, 0.2);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(83, 73, 45, 0.15);
}

.game-stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 2px solid rgba(115, 82, 39, 0.12);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--good);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 2.5vw, 2.35rem);
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.hud span,
.stat-card,
.clean-list li,
.trust-box,
.parent-log {
  background: #fffaf0;
  border: 2px solid rgba(142, 86, 47, 0.16);
  border-radius: 8px;
}

.hud span {
  padding: 8px 10px;
  font-size: 0.95rem;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 420px;
  background: #76bb68;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

.mini-map {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 118px;
  height: 78px;
  border: 3px solid rgba(38, 48, 42, 0.22);
  border-radius: 8px;
  background: rgba(255, 250, 231, 0.82);
}

.dot {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--good);
}

.dot.home { left: 18px; top: 18px; }
.dot.coop { left: 28px; bottom: 14px; background: var(--warn); }
.dot.store { left: 54px; top: 36px; background: var(--wood); }
.dot.market { right: 20px; top: 18px; background: var(--blue); }
.dot.grove { right: 34px; bottom: 14px; background: #8d66c2; }

.action-btn {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  min-width: 190px;
  padding: 13px 18px;
  color: white;
  background: #2f8d5f;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 7px 0 #236d49;
  font-weight: 900;
  cursor: pointer;
}

.action-btn:active {
  transform: translate(-50%, 4px);
  box-shadow: 0 3px 0 #236d49;
}

.exit-btn {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: #fffaf0;
  color: var(--wood);
  box-shadow: 0 4px 0 rgba(142, 86, 47, 0.24);
  font-weight: 900;
  cursor: pointer;
}

.exit-btn.hidden {
  display: none;
}

.mobile-pad {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: none;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 6px;
}

.mobile-pad button {
  border: 0;
  border-radius: 8px;
  background: rgba(255, 250, 231, 0.88);
  font-weight: 900;
}

.mobile-pad [data-dir="up"] { grid-column: 2; }
.mobile-pad [data-dir="left"] { grid-column: 1; grid-row: 2; }
.mobile-pad [data-dir="down"] { grid-column: 2; grid-row: 2; }
.mobile-pad [data-dir="right"] { grid-column: 3; grid-row: 2; }

.mission-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 12px;
}

.mission-row article {
  padding: 12px;
  background: rgba(255, 250, 231, 0.74);
  border-left: 5px solid var(--sun);
  border-radius: 8px;
}

.mission-row p,
.trust-box p,
.parent-log p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.35;
}

.side-panel {
  padding: 14px;
  overflow: auto;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.tab,
.wide-btn {
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: #efe2bf;
  color: var(--ink);
  font-weight: 850;
  cursor: pointer;
}

.tab.active,
.wide-btn {
  background: var(--wood);
  color: white;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.stat-card {
  padding: 12px;
  margin-bottom: 10px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  margin-bottom: 3px;
}

.stat-card strong {
  font-size: 1.35rem;
}

.clean-list {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
}

.clean-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.wide-btn {
  width: 100%;
}

.trust-box,
.parent-log {
  padding: 12px;
  margin-bottom: 12px;
}

.control-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(38, 48, 42, 0.2);
}

.control-line.compact {
  grid-template-columns: 1fr;
  gap: 7px;
  margin-top: 0;
}

.control-line select {
  width: 100%;
  border: 2px solid rgba(142, 86, 47, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: #fffaf0;
  color: var(--ink);
  font-weight: 800;
}

.control-line input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
}

.quest-list {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.quest-list span {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff4c7;
  border: 2px solid rgba(217, 139, 40, 0.24);
  color: #6a4b20;
  font-weight: 850;
}

.quest-list span.done {
  background: #e4fae9;
  border-color: rgba(45, 155, 103, 0.32);
  color: #236d49;
}

.badge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.badge-grid span {
  min-height: 74px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: #eadfc4;
  color: #756c5a;
  border: 2px dashed rgba(117, 108, 90, 0.35);
  font-weight: 850;
}

.badge-grid .earned {
  color: #5a351c;
  background: linear-gradient(135deg, #fff2a9, #ffc86a);
  border-style: solid;
}

.dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(30, 36, 31, 0.42);
}

.dialog.hidden {
  display: none;
}

.dialog-card {
  width: min(520px, 100%);
  padding: 20px;
  border-radius: 8px;
  background: var(--cream);
  border: 3px solid rgba(115, 82, 39, 0.25);
  box-shadow: 0 24px 80px rgba(31, 35, 26, 0.26);
}

.dialog-options {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.dialog-options button {
  padding: 12px;
  border: 2px solid rgba(38, 48, 42, 0.18);
  border-radius: 8px;
  background: white;
  text-align: left;
  cursor: pointer;
}

.dialog-options button.correct {
  border-color: var(--good);
  background: #e4fae9;
}

.dialog-options button.wrong {
  border-color: #c95b4a;
  background: #ffe7e1;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 8px;
  }

  .topbar,
  .mission-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hud {
    justify-content: flex-start;
  }

  .canvas-wrap {
    min-height: 510px;
  }

  .mobile-pad {
    display: grid;
  }

  .action-btn {
    left: auto;
    right: 12px;
    transform: none;
    min-width: 150px;
  }

  .action-btn:active {
    transform: translateY(4px);
  }

  .mini-map {
    width: 92px;
    height: 62px;
  }

  .badge-grid {
    grid-template-columns: 1fr;
  }
}
