:root {
  --ink: #000;
  --paper: #fff;
  --muted: #444;
  --font-display: "Caveat", cursive;
  --font-body: "Patrick Hand", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: var(--paper);
}

#hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 2.5px solid #000;
  background: #fff;
  z-index: 6;
  flex-shrink: 0;
}

.hud-top, .hud-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  transform: rotate(-2deg);
}

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.82rem;
}

.hud-status {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.status-chip {
  border: 2px solid #000;
  background: #fff;
  padding: 2px 8px;
  font-size: 0.78rem;
  line-height: 1.3;
}
.status-chip.ok { color: #333; }
.status-chip.warn { background: #000; color: #fff; }
.status-chip.sleep { background: #e8f0ff; }
.status-chip.bleed { background: #ffe4e4; }
.status-chip.poison { background: #e4ffe8; }
.status-chip.thirst { background: #fff4d6; }

.vital-bars {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-left: auto;
}
.vbar {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  text-transform: uppercase;
}
.vbar .track {
  width: 64px;
  height: 7px;
  border: 2px solid #000;
  background: #fff;
}
.vbar .fill {
  height: 100%;
  width: 100%;
  background: #000;
}
.ability-vbar .track {
  width: 110px;
}
.xp-vbar .track {
  width: 100px;
}
.xp-fill {
  background: #2a7fff !important;
}
.ability-vbar span {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-transform: none;
  font-size: 0.78rem;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  background: #f5f5f5;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  outline: none;
}

.banner {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 8;
  border: 2.5px solid #000;
  background: #fff;
  padding: 8px 16px;
  box-shadow: 4px 4px 0 #000;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  overflow: auto;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
}

.overlay[hidden] { display: none !important; }

.card {
  width: min(560px, 94vw);
  max-height: min(92vh, 900px);
  overflow: auto;
  border: 3px solid #000;
  background: #fff;
  padding: 22px 24px;
  box-shadow: 8px 8px 0 #000;
}

.home-card, .hub-card { text-align: center; }
.home-card h1, .hub-card h2 {
  font-family: var(--font-display);
  font-size: 2.8rem;
  margin: 0 0 4px;
  transform: rotate(-2deg);
}
.hub-card h2 { font-size: 2.2rem; }
.tagline { margin: 0 0 10px; color: var(--muted); }

.starters {
  border: 2px solid #000;
  margin: 12px 0;
  padding: 10px;
  text-align: left;
}
.starters legend {
  padding: 0 6px;
  font-family: var(--font-display);
  font-size: 1.2rem;
}
.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  max-height: 280px;
  overflow: auto;
}
.starter-grid label.starter-pick {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.92rem;
  border: 2px solid #000;
  padding: 8px;
  cursor: pointer;
  background: #fff;
}
.starter-grid label.starter-pick:has(input:checked) {
  background: #000;
  color: #fff;
}
.starter-grid label.starter-pick:has(input:checked) .tag {
  color: #ddd;
}
.starter-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
}
.starter-body strong {
  font-size: 1.05rem;
}
.starter-body .ability {
  margin-top: 2px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.hint { color: var(--muted); margin: 6px 0; }
.hint.tiny { font-size: 0.85rem; }
.tag { font-size: 0.8rem; color: var(--muted); }

button {
  font: inherit;
  border: 2.5px solid #000;
  background: #fff;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary { background: #000; color: #fff; }
button.ghost { background: #fff; }
button:hover:not(:disabled) {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 #000;
}

.hub-section {
  border-top: 2px dashed #000;
  margin-top: 12px;
  padding-top: 10px;
  text-align: left;
}
.hub-section h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.stat-row button { padding: 4px 10px; }

.evolve-card-wrap { width: min(780px, 96vw); }
.evolve-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
@media (max-width: 720px) {
  .evolve-grid, .starter-grid { grid-template-columns: 1fr; }
}
.evolve-card {
  text-align: left;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.evolve-card .stats { margin: 0; font-size: 0.85rem; }

.ency-card {
  width: min(980px, 96vw);
  max-height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
  text-align: left;
}
.ency-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.ency-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.2rem;
  transform: rotate(-1deg);
}
.ency-tabs {
  display: flex;
  gap: 6px;
  margin: 6px 0 2px;
}
.ency-tab {
  border: 2px solid #000;
  background: #fff;
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 4px 12px;
  cursor: pointer;
}
.ency-tab.on {
  background: #000;
  color: #fff;
}
.ency-pane {
  overflow: auto;
  flex: 1;
  min-height: 0;
  margin-top: 8px;
}
#ency-animals {
  display: flex;
  gap: 12px;
  min-height: 0;
}
.ency-tiers {
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding-right: 4px;
}
.ency-tier {
  border-top: 2px dashed #000;
  padding: 10px 0 14px;
}
.ency-tier h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.35rem;
}
.ency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.ency-entry {
  border: 2px solid #000;
  padding: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 158px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: inherit;
  box-shadow: none;
}
.ency-entry:hover,
.ency-entry:focus {
  background: #f3f3f3;
  outline: 2px solid #000;
  outline-offset: 1px;
  transform: none;
  box-shadow: none;
}
.ency-entry.on {
  background: #000;
  color: #fff;
}
.ency-entry.on .tag,
.ency-entry.on .ability {
  color: #ddd;
}
.ency-entry canvas {
  width: 100%;
  height: 86px;
  image-rendering: auto;
  border-bottom: 1.5px dashed #000;
  margin-bottom: 4px;
  background: #fff;
}
.ency-entry strong {
  font-size: 1rem;
  line-height: 1.1;
}
.ency-entry .tag { line-height: 1.2; }
.ency-entry .ability {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}
.ency-detail {
  width: min(280px, 42%);
  flex-shrink: 0;
  border: 2.5px solid #000;
  padding: 10px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}
.ency-pane[hidden],
#ency-animals[hidden],
#ency-weather[hidden],
#ency-events[hidden],
.ency-detail[hidden] { display: none !important; }
.ency-detail canvas {
  width: 100%;
  height: 140px;
  border: 2px dashed #000;
  background: #fff;
}
.ency-detail h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.7rem;
  line-height: 1;
}
.ency-perks {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ency-perk {
  border: 2px solid #000;
  padding: 6px 8px;
  background: #fafafa;
}
.ency-perk strong {
  display: block;
  font-size: 0.95rem;
}
.ency-perk span {
  font-size: 0.8rem;
  color: var(--muted);
}
.ency-info-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ency-info {
  border: 2px solid #000;
  padding: 10px 12px;
  background: #fff;
}
.ency-info h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.45rem;
}
.ency-info .tag {
  display: inline-block;
  margin-bottom: 4px;
}
.ency-info p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.35;
}
@media (max-width: 720px) {
  #ency-animals { flex-direction: column; }
  .ency-detail { width: 100%; max-height: 46%; }
}
