:root {
  --bg: #1a1410;
  --soil: #6b4a2b;
  --gold: #f6c344;
  --red: #d94343;
  --ink: #f5ecdc;
  --card: #2a1f17;
  --card-edge: #4a3624;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud {
  position: absolute;
  top: max(env(safe-area-inset-top), 8px);
  left: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 5;
  flex-wrap: nowrap;
}

.hud-pill {
  background: rgba(20, 14, 10, 0.78);
  color: var(--ink);
  border: 2px solid var(--card-edge);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.hud-pill.gold { color: var(--gold); }
.hud-pill.ghost {
  background: rgba(20, 14, 10, 0.55);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 9px;
}

.goal-bar {
  position: absolute;
  top: calc(max(env(safe-area-inset-top), 8px) + 44px);
  left: 8px;
  right: 8px;
  height: 14px;
  background: rgba(20,14,10,0.7);
  border: 2px solid var(--card-edge);
  border-radius: 999px;
  overflow: hidden;
  z-index: 4;
}
.goal-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6dd07a, #f6c344, #ff6a1c, #d94343);
  transition: width 200ms ease;
}
.goal-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  color: white;
}

.tool-dock {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 14px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(20, 14, 10, 0.82);
  border: 2px solid var(--card-edge);
  border-radius: 18px;
  padding: 10px 14px;
  z-index: 5;
  backdrop-filter: blur(6px);
}

.tool-icon {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3a2a1c;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
}
.tool-icon::after {
  content: '↕';
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--gold);
  color: #2a1f17;
  font-size: 10px;
  font-weight: 800;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-info { flex: 1; min-width: 0; }
.tool-name { font-weight: 800; font-size: 15px; }
.tool-bar {
  margin-top: 6px;
  height: 8px;
  background: #1a120c;
  border-radius: 999px;
  overflow: hidden;
}
.tool-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6dd07a, #f6c344);
  transition: width 120ms ease;
}

.upgrade-btn {
  background: var(--gold);
  color: #2a1f17;
  border: none;
  border-radius: 12px;
  font-weight: 800;
  font-size: 14px;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 #b08a26;
}
.upgrade-btn:disabled {
  background: #4a3624;
  color: #806a52;
  box-shadow: none;
  cursor: not-allowed;
}

.card {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 20px;
}
.card.hidden { display: none; }

.card-inner {
  background: var(--card);
  border: 3px solid var(--card-edge);
  border-radius: 20px;
  padding: 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.card-inner.wide { max-width: 520px; text-align: left; }

.card-emoji { font-size: 56px; line-height: 1; margin-bottom: 6px; }
.card h2 { margin: 6px 0 10px; font-size: 22px; }
.card p { margin: 0 0 18px; font-size: 16px; line-height: 1.45; color: #e7d8c1; }
.card .muted { color: #9b8b75; }
.card .small { font-size: 12px; margin-top: 12px; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin: 8px 0;
  background: #1f1610;
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
}
.setting input[type=checkbox] {
  width: 22px;
  height: 22px;
  accent-color: var(--gold);
}

button.primary, button.danger {
  border: none;
  border-radius: 14px;
  font-weight: 800;
  font-size: 16px;
  padding: 12px 20px;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
}
button.primary {
  background: var(--gold);
  color: #2a1f17;
  box-shadow: 0 4px 0 #b08a26;
}
button.danger {
  background: transparent;
  color: var(--red);
  border: 2px solid var(--red);
  box-shadow: none;
}
button.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #b08a26; }

.journal-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: 16px;
}
.journal-item {
  background: #1f1610;
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  padding: 10px;
  font-size: 13px;
}
.journal-item.locked { opacity: 0.4; }
.journal-item .je { font-size: 26px; position: relative; }
.journal-item .jt { font-weight: 700; margin-top: 4px; }
.journal-item .jcount {
  font-size: 12px;
  background: var(--gold);
  color: #2a1f17;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
  font-weight: 800;
}

.journal-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.journal-stats .stat {
  background: #1f1610;
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}
.journal-stats .stat-num {
  display: block;
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
}
.journal-stats .stat-lbl {
  display: block;
  font-size: 11px;
  color: #b0a08a;
  margin-top: 2px;
}

.tool-pick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  margin: 12px 0 16px;
}
.tool-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #1f1610;
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.tool-pick.equipped { border-color: var(--gold); background: #2a1f17; }
.tool-pick .tp-emoji {
  font-size: 28px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3a2a1c;
  border-radius: 10px;
}
.tool-pick .tp-info { flex: 1; }
.tool-pick .tp-name { font-weight: 800; font-size: 15px; }
.tool-pick .tp-meta { font-size: 11px; color: #b0a08a; margin-top: 2px; }
.tool-pick .tp-tag {
  font-size: 11px;
  color: var(--gold);
  font-weight: 800;
}

.planet-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
  margin: 12px 0 16px;
}
.planet-pick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #1f1610;
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.planet-pick.locked { opacity: 0.45; cursor: not-allowed; }
.planet-pick.current { border-color: var(--gold); background: #2a1f17; }
.planet-pick .pp-emoji {
  font-size: 36px;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #3a2a1c;
  border-radius: 12px;
  flex-shrink: 0;
}
.planet-pick .pp-info { flex: 1; min-width: 0; }
.planet-pick .pp-name { font-weight: 800; font-size: 16px; }
.planet-pick .pp-meta { font-size: 12px; color: #b0a08a; margin-top: 2px; }
.planet-pick .pp-intro { font-size: 12px; margin-top: 6px; color: #d0c0a8; line-height: 1.35; }
.planet-pick .pp-tag {
  font-size: 11px;
  color: var(--gold);
  font-weight: 800;
}

.journal-header {
  grid-column: 1 / -1;
  font-size: 16px;
  padding: 8px 0 4px;
  border-bottom: 2px solid var(--card-edge);
  margin-top: 8px;
}

.red-flash {
  position: absolute;
  inset: 0;
  background: var(--red);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 180ms ease;
}
.red-flash.on { opacity: 0.55; }

.toast {
  position: absolute;
  top: 110px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(20,14,10,0.92);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 10px 18px;
  font-weight: 800;
  font-size: 15px;
  color: var(--gold);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease;
  z-index: 9;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hint {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,14,10,0.7);
  border: 2px solid var(--card-edge);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  color: #e7d8c1;
  z-index: 4;
  pointer-events: none;
  transition: opacity 400ms ease;
}
.hint.fade { opacity: 0; }
