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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- control panel ---------- */

#panel-root {
  position: fixed;
  top: 10px;
  left: 10px;
  width: 300px;
  max-width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
  color: #cfd8cf;
  font-size: 12px;
  scrollbar-width: thin;
  scrollbar-color: #3a4a3a transparent;
}

.pl-panel {
  background: rgba(8, 12, 8, 0.88);
  border: 1px solid #1d2a1d;
  border-radius: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.pl-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #1d2a1d;
}

.pl-header .pl-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: #e6efe6;
}

.pl-section {
  border-bottom: 1px solid #172117;
}
.pl-section:last-child { border-bottom: none; }

.pl-section-head {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  letter-spacing: 0.1em;
  font-size: 11px;
  font-weight: 600;
  color: #9fb59f;
}
.pl-section-head:hover { color: #d8e8d8; }
.pl-section-head .arrow {
  margin-left: auto;
  transition: transform 0.15s;
  font-size: 9px;
}
.pl-section.collapsed .arrow { transform: rotate(180deg); }
.pl-section.collapsed .pl-section-body { display: none; }

.pl-section-body { padding: 4px 12px 10px; }

.pl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  min-height: 20px;
}

.pl-row label {
  flex: 0 0 108px;
  color: #8fa58f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pl-row input[type="range"] {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #26332638;
  border: 1px solid #2c3a2c;
  border-radius: 2px;
  outline: none;
}
.pl-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 18px;
  border-radius: 2px;
  background: #dfe8df;
  border: 1px solid #666;
  cursor: pointer;
}
.pl-row input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 18px;
  border-radius: 2px;
  background: #dfe8df;
  border: 1px solid #666;
  cursor: pointer;
}

.pl-row .val {
  flex: 0 0 40px;
  font-size: 11px;
  text-align: right;
  color: #d5e5d5;
  font-variant-numeric: tabular-nums;
}

.pl-row input[type="text"], .pl-row input[type="number"] {
  flex: 1;
  min-width: 0;
  background: #f2f5f2;
  color: #111;
  border: none;
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 12px;
}

.pl-btn {
  background: transparent;
  color: #9fe89f;
  border: 1px solid #3f6a3f;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.pl-btn:hover { background: #1c2e1c; color: #c9ffc9; }
.pl-btn.warn { color: #e8b06a; border-color: #7a5a2c; }
.pl-btn.warn:hover { background: #2e2413; color: #ffd9a0; }
.pl-btn.wide { width: 100%; margin: 4px 0; }

.pl-check {
  width: 15px;
  height: 15px;
  accent-color: #6fbf6f;
  cursor: pointer;
}

.pl-info {
  color: #7d917d;
  font-size: 11px;
  line-height: 1.5;
}
.pl-info b { color: #cfe5cf; font-weight: 600; }

/* ---------- matrix editor ---------- */

.pl-matrix {
  display: grid;
  gap: 2px;
  margin: 6px 0 2px;
  touch-action: none;
}
.pl-matrix .mcell {
  aspect-ratio: 1;
  border-radius: 2px;
  cursor: ns-resize;
  position: relative;
}
.pl-matrix .mhead {
  aspect-ratio: 1;
  border-radius: 50%;
  align-self: center;
  justify-self: center;
  width: 60%;
}
.pl-matrix .mcorner { background: transparent; }

.pl-hint {
  color: #63755f;
  font-size: 10px;
  margin-top: 4px;
}

@media (max-width: 640px) {
  #panel-root { width: 260px; font-size: 11px; }
  .pl-row label { flex-basis: 92px; }
}

/* ---------- build 02: header badge + menu link ---------- */

.pl-menu-link {
  color: #6fbf6f;
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  padding: 0 4px;
  line-height: 1;
}
.pl-menu-link:hover { color: #c9ffc9; }

.pl-build-badge {
  font-size: 9px;
  letter-spacing: 0.14em;
  color: #6fbf6f;
  border: 1px solid #3f6a3f;
  border-radius: 3px;
  padding: 2px 5px;
  white-space: nowrap;
}

/* ---------- build 02: presets ---------- */

.pl-select {
  flex: 1;
  min-width: 0;
  background: #101710;
  color: #cfe5cf;
  border: 1px solid #2c3a2c;
  border-radius: 3px;
  padding: 5px 6px;
  font-size: 12px;
}

/* ---------- build 02: matrix mutation flash ---------- */

@keyframes pl-mutate-flash {
  0% { box-shadow: 0 0 0 2px #fff, 0 0 12px 4px #9fe89f; }
  100% { box-shadow: none; }
}
.pl-matrix .mcell.mutated { animation: pl-mutate-flash 1.2s ease-out; }

/* ---------- build 02: achievements ---------- */

.pl-ach-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.pl-ach {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 8px;
  border: 1px solid #172117;
  border-radius: 4px;
  opacity: 0.55;
}
.pl-ach.got { opacity: 1; border-color: #3f6a3f; background: #0d140d; }
.pl-ach-name { font-size: 11px; font-weight: 600; color: #cfe5cf; }
.pl-ach-desc { font-size: 10px; color: #7d917d; }

/* ---------- build 02: toasts ---------- */

.pl-toasts {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  pointer-events: none;
}
.pl-toast {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(10, 18, 10, 0.95);
  border: 1px solid #3f6a3f;
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 220px;
  max-width: 320px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  box-shadow: 0 6px 24px rgba(60, 160, 60, 0.25);
}
.pl-toast.show { transform: translateX(0); }
.pl-toast b { font-size: 10px; letter-spacing: 0.12em; color: #9fe89f; }
.pl-toast span { font-size: 14px; font-weight: 600; color: #e6efe6; }
.pl-toast em { font-size: 11px; font-style: normal; color: #8fa58f; }

/* header: keep title + badge + restart on one line */
.pl-header { flex-wrap: nowrap; }
.pl-header .pl-title { font-size: 12px; white-space: nowrap; flex: 0 1 auto; }
.pl-header .pl-build-badge { margin-right: auto; }

/* ================= Build 03 "Shepherd" ================= */

/* pointer tool cursor ring */
.pl-ring {
  position: fixed;
  border: 1px solid rgba(160, 220, 160, 0.5);
  border-radius: 50%;
  pointer-events: none;
  z-index: 5;
}
.pl-ring[data-mode="1"] { border-color: rgba(120, 220, 255, 0.85); box-shadow: 0 0 18px rgba(120, 220, 255, 0.25) inset; }
.pl-ring[data-mode="2"] { border-color: rgba(255, 140, 110, 0.85); box-shadow: 0 0 18px rgba(255, 140, 110, 0.25) inset; }
.pl-ring[data-mode="3"] { border-color: rgba(220, 160, 255, 0.85); box-shadow: 0 0 18px rgba(220, 160, 255, 0.25) inset; }

.pl-btn.active {
  border-color: #6fbf6f;
  color: #c9ffc9;
  background: #1a2a1a;
}

/* ---------- HUD (top-right) ---------- */
.sh-hud {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 250px;
  z-index: 10;
  background: rgba(8, 12, 8, 0.88);
  border: 1px solid #1d2a1d;
  border-radius: 6px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #cfd8cf;
  font-size: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.sh-hud-row { display: flex; align-items: center; gap: 8px; }
.sh-hud-top { justify-content: space-between; font-weight: 700; letter-spacing: 0.1em; }
.sh-score { color: #9fe89f; }
.sh-lab { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; padding: 2px 6px; border-radius: 3px; }
.sh-lab.you { background: #0d2733; color: #7fd8ff; }
.sh-lab.foe { background: #331111; color: #ff8f7f; }
.sh-rname { color: #b58f8f; font-size: 11px; }
.sh-bar {
  flex: 1;
  height: 6px;
  background: #142014;
  border: 1px solid #223022;
  border-radius: 3px;
  overflow: hidden;
}
.sh-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #3f8f5f, #9fe89f); transition: width 0.25s; }
.sh-bar.goal .sh-bar-fill { background: linear-gradient(90deg, #6f5f9f, #c9a9ff); }
.sh-next { font-size: 10px; letter-spacing: 0.08em; color: #8fa58f; }
.sh-disc { font-size: 11px; color: #c9a9ff; min-height: 0; }

/* ---------- event feed (bottom-right) ---------- */
.sh-feed {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  pointer-events: none;
  max-width: 46vw;
}
.sh-feed-line {
  background: rgba(8, 12, 8, 0.9);
  border: 1px solid #1d2a1d;
  border-left: 3px solid #3f6a3f;
  border-radius: 4px;
  color: #b5c9b5;
  font-size: 12px;
  padding: 6px 10px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s, transform 0.3s;
}
.sh-feed-line.show { opacity: 1; transform: none; }
.sh-feed-line.rival { border-left-color: #a03a2a; color: #e8b0a0; }
.sh-feed-line.evolve { border-left-color: #7f5fbf; color: #d8c9ff; }
.sh-feed-line.milestone { border-left-color: #3f6a9f; color: #b0d0f0; }
.sh-feed-line.victory { border-left-color: #bfa03a; color: #f0e0a0; }
.sh-feed-line.discover { border-left-color: #bf8fff; color: #e8d8ff; font-weight: 600; }

/* ---------- overlays ---------- */
.sh-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
  padding: 24px 12px;
}
.sh-card {
  background: rgba(10, 14, 10, 0.96);
  border: 1px solid #2a3a2a;
  border-radius: 10px;
  padding: 26px 30px;
  max-width: 860px;
  width: 100%;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  color: #cfd8cf;
  scrollbar-width: thin;
  scrollbar-color: #3a4a3a transparent;
}
.sh-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: #e6efe6;
  text-align: center;
}
.sh-title.small { font-size: 18px; letter-spacing: 0.2em; }
.sh-tag { margin-top: 8px; text-align: center; color: #8fa58f; font-size: 13px; }
.sh-how { margin: 18px auto 0; max-width: 560px; display: flex; flex-direction: column; gap: 8px; font-size: 12px; color: #9fb59f; line-height: 1.5; }
.sh-how b { color: #9fe89f; letter-spacing: 0.1em; margin-right: 4px; }
.sh-btn-row { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.sh-btn {
  background: #121a12;
  border: 1px solid #2d3f2d;
  border-radius: 5px;
  color: #b5c9b5;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 10px 18px;
  cursor: pointer;
}
.sh-btn:hover { border-color: #4f7a4f; color: #d9efd9; }
.sh-btn.primary { background: #16301a; border-color: #3f7a4f; color: #9fe89f; }
.sh-btn.primary:hover { background: #1c3f22; color: #c9ffc9; }
.sh-sec { margin: 22px 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.18em; color: #6f8f6f; }
.sh-dim { color: #63755f; font-size: 12px; }

.sh-records, .sh-bestiary { display: flex; flex-direction: column; gap: 5px; }
.sh-record, .sh-beast {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: #0d130d;
  border: 1px solid #1a251a;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 12px;
}
.sh-rank { color: #6f8f6f; font-weight: 700; }
.sh-record b { color: #9fe89f; }
.sh-record span:last-child { color: #7d917d; }
.sh-beast b { color: #d9efd9; }
.sh-beast .sh-rarity { font-size: 9px; letter-spacing: 0.14em; padding: 2px 6px; border-radius: 3px; }
.sh-beast.common .sh-rarity { background: #16301a; color: #8fbf8f; }
.sh-beast.rare .sh-rarity { background: #14243f; color: #8fb5ff; }
.sh-beast.epic .sh-rarity { background: #2d1a3f; color: #d0a9ff; }
.sh-beast .sh-count { margin-left: auto; color: #6f8f6f; }

/* ---------- draft modal ---------- */
.sh-pending { text-align: center; max-width: 420px; }
.sh-spinner {
  margin: 22px auto 6px;
  width: 34px;
  height: 34px;
  border: 3px solid #223022;
  border-top-color: #9fe89f;
  border-radius: 50%;
  animation: sh-spin 0.9s linear infinite;
}
@keyframes sh-spin { to { transform: rotate(360deg); } }

.sh-draft-row { display: flex; gap: 14px; margin-top: 20px; align-items: stretch; flex-wrap: wrap; justify-content: center; }
.sh-cand {
  flex: 1 1 200px;
  max-width: 250px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: #0c110c;
  border: 1px solid #223022;
  border-radius: 8px;
  padding: 14px;
}
.sh-cand:hover { border-color: #4f7a4f; }
.sh-cand-key {
  align-self: center;
  width: 22px; height: 22px;
  border: 1px solid #3f5a3f;
  border-radius: 4px;
  color: #9fe89f;
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.sh-cand-title { text-align: center; font-size: 16px; font-weight: 700; letter-spacing: 0.12em; color: #e6efe6; }
.sh-thumb { width: 100%; border: 1px solid #1a251a; border-radius: 4px; background: #050805; }
.sh-traits { display: flex; flex-direction: column; gap: 3px; }
.sh-trait { font-size: 11px; color: #9fb59f; }
.sh-forecast { display: flex; flex-direction: column; gap: 3px; min-height: 30px; }
.sh-fore { font-size: 11px; font-style: italic; color: #c9a9ff; }
.sh-cand .sh-btn { margin-top: auto; }

/* ---------- game over ---------- */
.sh-over .sh-title { color: #ffb5a5; }
.sh-stats {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.sh-stats > div {
  background: #0d130d;
  border: 1px solid #1a251a;
  border-radius: 6px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.sh-stats b { font-size: 20px; color: #e6efe6; }
.sh-stats span { font-size: 9px; letter-spacing: 0.16em; color: #6f8f6f; }
