:root {
  --bg: #1b1f1a;
  --panel: rgba(30, 35, 29, .94);
  --panel2: #2b3229;
  --line: #434c3e;
  --fg: #ece6d6;
  --dim: #a3a896;
  --acc: #f0c46a;
  --bad: #e5675a;
  --ok: #9bd67f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; z-index: 10; }
.screen.on { display: flex; }
#scrDesign, #scrGraph, #scrResult { z-index: 30; }
#scrHelp { z-index: 45; }
.dim { background: rgba(14, 17, 13, .6); backdrop-filter: blur(2px); }

button {
  color: var(--fg);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s;
  font-family: inherit;
  font-size: 14px;
}
button:hover { background: #363f33; border-color: #5b6752; }
button:active { transform: scale(.93); }
button.on { background: var(--acc); color: #2b2410; border-color: var(--acc); }
button:disabled { opacity: .3; cursor: default; transform: none; }
button.primary { background: #4a5a3c; border-color: #6e845a; }
button.primary:hover { background: #56693f; }
button.big { width: 104px; height: 76px; border-radius: 20px; }
button.big i.ic { width: 42px; height: 42px; }

i.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
i.ic svg { width: 100%; height: 100%; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: 0 12px 40px rgba(0, 0, 0, .4); }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.nav { display: flex; gap: 10px; }
.nav button { width: 60px; height: 50px; border-radius: 14px; }
.nav button i.ic { width: 26px; height: 26px; }

input { font-family: inherit; }
input[type=range] { width: 200px; accent-color: var(--acc); cursor: pointer; }
.chip { width: 18px; height: 18px; border-radius: 5px; flex: none; border: 1px solid rgba(0, 0, 0, .3); }
.val { min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--dim); font-weight: 600; }
.num {
  width: 130px; height: 36px; background: #20251f; border: 1px solid var(--line);
  border-radius: 8px; color: var(--fg); font-size: 16px; font-weight: 600;
  text-align: center; font-variant-numeric: tabular-nums;
}
.code {
  width: 220px; height: 36px; font-family: Consolas, monospace; font-size: 12px;
  background: #20251f; border: 1px solid var(--line); border-radius: 8px;
  color: var(--dim); padding: 0 8px; user-select: text; -webkit-user-select: text;
}
#scrDesign .code { width: 168px; }
.name {
  width: 180px; height: 42px; background: #20251f; border: 1px solid var(--line);
  border-radius: 10px; color: var(--fg); font-size: 21px; font-weight: 700;
  text-align: center; letter-spacing: 1px;
}
.bad { border-color: var(--bad) !important; box-shadow: 0 0 0 2px rgba(229, 103, 90, .35); }
.shake { animation: shake .4s; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }

.mapprev { border-radius: 12px; border: 1px solid var(--line); width: 576px; height: 324px; }
.biomebar { display: flex; width: 100%; height: 8px; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); background: #20251f; }
.biomebar span { height: 100%; transition: width .12s; }
.logo { font-weight: 800; letter-spacing: 8px; font-size: 32px; color: var(--fg); opacity: .94; }
.corner { position: absolute; right: 16px; bottom: 16px; display: flex; gap: 8px; }

/* Designer & Local Unit Library */
.slotsrow { gap: 14px; }
.slots { gap: 10px; }
.slot { position: relative; width: 62px; height: 62px; border-radius: 14px; padding: 0; }
.slot canvas { width: 48px; height: 48px; }
.slot.sel { border-color: var(--acc); box-shadow: 0 0 0 2px rgba(240, 196, 106, .4); }
.slot.dirty { border-style: dashed; }
.slot.dirty::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--acc);
}
.slot.eco { border-style: dashed; border-color: #6e845a; color: var(--acc); }
.slot.eco:hover { background: #3b4735; border-color: var(--acc); }
.slot .rm {
  position: absolute; top: -8px; right: -8px; min-width: 22px; width: 22px; height: 22px;
  border-radius: 11px; padding: 0; background: #3a2a26; border-color: #6a4740;
}
.slot .rm i.ic { width: 12px; height: 12px; }

.designer { display: flex; gap: 26px; padding: 18px 20px; }
.dleft { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.prevwrap { position: relative; display: flex; }
#prevBig { width: 220px; height: 220px; background: radial-gradient(circle, #8b9a73, #5f6d50); border-radius: 18px; touch-action: none; }
.prevwrap .mini {
  position: absolute; right: 6px; min-width: 30px; width: 30px; height: 30px;
  padding: 0; border-radius: 9px; background: rgba(30, 35, 29, .82); display: none;
}
.prevwrap .mini i.ic { width: 16px; height: 16px; }
.prevwrap.sculptable .mini { display: inline-flex; }
#morphDice { top: 6px; }
#sculptReset { bottom: 6px; }
.samples canvas { width: 52px; height: 52px; background: #6f7d5e; border-radius: 10px; }
.tradeoffs { display: flex; flex-direction: column; gap: 5px; width: 220px; padding: 8px 10px; background: #20251f; border: 1px solid var(--line); border-radius: 12px; }
.tbar { display: flex; align-items: center; gap: 8px; }
.tbar i.ic { width: 16px; height: 16px; color: var(--dim); }
.tbar .bar { flex: 1; width: auto; height: 7px; background: #141813; }
.tbar .bar > div { transition: width .12s, background-color .15s; }
.dright { display: flex; flex-direction: column; gap: 6px; justify-content: space-between; min-width: 356px; }
.dtabs { gap: 6px; margin-bottom: 2px; }
.dtabs button { flex: 1; height: 34px; border-radius: 10px; }
.pane { display: none; flex-direction: column; gap: 6px; }
.pane.on { display: flex; }
.mrow { display: flex; align-items: center; gap: 6px; min-height: 36px; flex-wrap: nowrap; }
.mbtn { min-width: 42px; width: 42px; height: 36px; padding: 0; border-radius: 9px; }
.mbtn canvas { width: 30px; height: 30px; }
.mbtn.sm { min-width: 38px; width: 38px; }
.mbtn.sm canvas { width: 28px; height: 28px; }
.palrow { display: flex; align-items: center; gap: 5px; min-height: 30px; }
.cswatch {
  min-width: 24px; width: 24px; height: 24px; padding: 0; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, .4); transition: transform .1s, border-color .15s;
}
.cswatch:hover { transform: scale(1.14); }
.cswatch.on { border-color: #fff; box-shadow: 0 0 0 2px var(--acc); transform: scale(1.14); background: inherit !important; }
.presets { gap: 6px; margin-bottom: 2px; }
.presetbtn { width: 46px; height: 40px; padding: 0; border-radius: 10px; }
.presetbtn canvas { width: 32px; height: 32px; }
.grow { display: flex; align-items: center; gap: 8px; height: 38px; }
.grow canvas { width: 34px; height: 34px; }
.tog { display: flex; gap: 4px; }
.tog button { width: 48px; }
.cnt { min-width: 36px; text-align: center; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.sep { width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

@media (max-height: 700px) {
  #scrDesign { gap: 8px; padding: 6px 0; overflow-y: auto; justify-content: center; }
  .slot { width: 52px; height: 52px; }
  .slot canvas { width: 40px; height: 40px; }
  .designer { gap: 18px; padding: 12px 14px; }
  #prevBig { width: 168px; height: 168px; }
  .samples canvas { width: 42px; height: 42px; }
  .tradeoffs { width: 176px; padding: 6px 8px; gap: 4px; }
  .grow { height: 32px; }
  .grow canvas { width: 28px; height: 28px; }
  .presetbtn { height: 34px; }
  .presetbtn canvas { width: 28px; height: 28px; }
  .unitlib { max-height: 78px; padding: 6px 10px; }
  #scrDesign .nav button { height: 42px; width: 54px; }
}

.libbtn { position: relative; }
.libbadge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--acc); color: #2b2410; font-size: 11px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}
.unitlib {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(720px, 92vw);
  max-height: 116px;
  overflow-y: auto;
  padding: 10px 12px;
}
.unitlib.on { display: flex; }
.libempty {
  width: 100%;
  min-width: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: var(--dim);
  opacity: .55;
}
.uchip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 26px 4px 6px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.uchip.has2 { padding-right: 48px; }
.uchip:hover { background: #363f33; border-color: #5b6752; }
.uchip.sel { border-color: var(--acc); box-shadow: 0 0 0 2px rgba(240, 196, 106, .35); }
.uchip canvas { width: 36px; height: 36px; background: #20251f; border-radius: 7px; }
.uchip .unm { font-weight: 700; font-size: 13px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uchip .urm,
.uchip .uact {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  min-width: 18px; width: 18px; height: 18px; padding: 0; border-radius: 9px;
  background: transparent; border-color: transparent; color: var(--dim);
}
.uchip.has2 .uact { right: 24px; }
.uchip .urm:hover { background: #4a2d28; color: var(--fg); }
.uchip .uact:hover { background: #36452e; color: var(--acc); }
.uchip .uact.done { color: var(--ok); }
.uchip .urm i.ic,
.uchip .uact i.ic { width: 12px; height: 12px; }

.librefresh { width: 38px; min-width: 38px; height: 46px; padding: 0; border-radius: 10px; }
.librefresh i.ic { width: 18px; height: 18px; }
.libempty.err { color: var(--bad); opacity: .75; }
.spinning i.ic { animation: spin 1s linear infinite; }

/* HUD */
.hud { pointer-events: none; align-items: stretch; justify-content: flex-start; }
.hud .pe { pointer-events: auto; transition: opacity .8s; }
.hud.tutHide .pe { opacity: 0; pointer-events: none; }
.topbar {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px; white-space: nowrap;
}
.topbar button { width: 40px; height: 36px; }
.stat { display: inline-flex; align-items: center; gap: 5px; min-width: 70px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; color: var(--fg); }
.stat i.ic { width: 18px; height: 18px; color: var(--dim); }

.notes { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.note {
  display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px 12px 4px 8px; animation: noteIn .5s;
  transition: opacity .6s, transform .6s; cursor: pointer; pointer-events: auto;
}
.note.new { border-color: #c9a64e; }
.note.new i.ic { color: var(--acc); animation: spin 2s linear infinite; }
.note.spawn { border-color: #799962; }
.note.spawn i.ic { color: var(--ok); }
.note.ext { border-color: #5a5a5a; color: #999; }
.note.out { opacity: 0; transform: translateY(-8px); }
.note canvas { width: 36px; height: 36px; }
.note span { font-weight: 700; }
@keyframes noteIn { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px; background: var(--panel);
  padding: 6px; border-radius: 14px; border: 1px solid var(--line);
}
.toolbar button { width: 48px; height: 48px; }
.toolbar i.ic { width: 24px; height: 24px; }
#tlEnd { position: relative; overflow: hidden; }
#tlEnd::before {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--hold, 0) * 100%);
  background: rgba(229, 103, 90, .62);
  pointer-events: none;
}
#tlEnd i.ic { position: relative; z-index: 1; }
.envpop {
  position: absolute; left: 76px; top: 50%; transform: translateY(-50%);
  display: none; flex-direction: column; gap: 10px; background: var(--panel);
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
}
.envpop.on { display: flex; }

.splist {
  position: absolute; right: 10px; top: 66px; max-height: calc(100vh - 190px);
  overflow-y: auto; width: 220px; display: flex; flex-direction: column; gap: 3px;
  background: var(--panel); padding: 6px; border-radius: 14px; border: 1px solid var(--line);
}
.splist:empty { display: none; }
.sprow { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 8px; cursor: pointer; }
.sprow:hover { background: #363f33; }
.sprow.hl { background: #4c4430; }
.sprow canvas { width: 30px; height: 30px; }
.sprow .nm { flex: 1; font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.sprow .ct { font-variant-numeric: tabular-nums; color: var(--dim); font-weight: 600; }
.sprow.amb { opacity: .72; }
.sprow .anc { width: 14px; height: 14px; color: var(--dim); }
.spsep { height: 1px; background: var(--line); margin: 4px 2px; }

.mmwrap {
  position: absolute; right: 10px; bottom: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
  display: flex; align-items: flex-end; gap: 6px;
}
#minimap { width: 160px; height: 90px; border-radius: 8px; border: 1px solid var(--line); display: block; cursor: crosshair; }
#mmFit { min-width: 32px; width: 32px; height: 32px; padding: 0; border-radius: 9px; }
#mmFit i.ic { width: 17px; height: 17px; }

.info {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: none; gap: 14px; background: var(--panel); padding: 10px 14px;
  border-radius: 14px; border: 1px solid var(--line); align-items: center;
}
@media (max-width: 1180px) {
  .info { left: 10px; transform: none; gap: 8px; padding: 8px 10px; }
  .info #iThumb { width: 48px; height: 48px; }
  .info .bar { width: 76px; }
  .info .genes { gap: 3px 8px; }
  .info .gb .bar { width: 54px; }
  .info .actbox { width: 44px; height: 44px; }
}
.info.on { display: flex; }
.iactions { display: grid; grid-template-columns: repeat(2, 36px); gap: 5px; }
.iactions button { min-width: 36px; width: 36px; height: 36px; padding: 0; border-radius: 9px; }
.iactions i.ic { width: 18px; height: 18px; }
#iThumb { width: 64px; height: 64px; background: #6f7d5e; border-radius: 12px; }
.actbox { width: 52px; height: 52px; border-radius: 12px; background: #252b23; display: flex; align-items: center; justify-content: center; color: var(--acc); }
.actbox i.ic { width: 30px; height: 30px; }
.bar { width: 110px; height: 8px; background: #1d221b; border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; background: var(--acc); border-radius: 4px; }
.genes { display: grid; grid-template-columns: repeat(2, auto); gap: 3px 14px; }
.gb { display: flex; align-items: center; gap: 6px; }
.gb canvas { width: 22px; height: 22px; }
.gb .bar { position: relative; width: 80px; background: #1d221b; overflow: visible; }
.gb .bar > div { background: #c9c2ad; }
.gb .bar .refmark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: var(--acc);
  border-radius: 1px;
  pointer-events: none;
}
.nm { font-weight: 700; font-size: 15px; }

/* Graph & Result */
#gCv { width: 820px; height: 400px; background: #20251f; border-radius: 12px; }
.tabs button { width: 46px; height: 42px; }
.tabs canvas { width: 26px; height: 26px; }
.result { max-width: min(980px, 94vw); align-items: center; }
.stats { gap: 26px; }
.stats .stat { font-size: 20px; }
.stats .stat i.ic { width: 24px; height: 24px; }
.compare { flex-wrap: wrap; justify-content: center; gap: 18px; }
.cmp { position: relative; display: flex; align-items: center; gap: 6px; background: #252b23; border-radius: 14px; padding: 8px 12px; }
.cmp .side { display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 700; font-size: 13px; }
.cmp canvas { width: 84px; height: 84px; }
.cmp i.ic { color: var(--dim); }
.cmp .csave { min-width: 30px; width: 30px; height: 30px; padding: 0; border-radius: 8px; margin-left: 4px; }
.cmp .csave i.ic { width: 16px; height: 16px; }
.treewrap { max-height: 36vh; max-width: min(940px, 90vw); overflow: auto; background: #20251f; border-radius: 12px; }

/* How to Play Guide Modal */
.helpcard {
  width: min(980px, 94vw);
  max-height: min(88vh, 820px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px;
}
.helphead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.helptitle { display: flex; flex-direction: column; gap: 4px; }
.helptitle h2 { font-size: 24px; font-weight: 800; letter-spacing: .5px; color: var(--fg); }
.helptitle p { font-size: 15px; color: var(--dim); font-weight: 500; }
.helptitle .hicon { color: var(--acc); width: 26px; height: 26px; }
.helplang { flex: none; gap: 6px; }
.helplang .lbtn {
  min-width: 62px;
  height: 38px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 700;
  border-radius: 9px;
}
.helpnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.helpnav button {
  height: 36px;
  padding: 0 15px;
  font-size: 14.5px;
  font-weight: 700;
  border-radius: 999px;
  background: #222821;
  color: var(--dim);
}
.helpnav button:hover,
.helpnav button.on {
  background: #3a4533;
  color: var(--fg);
  border-color: var(--acc);
}
.helpbody {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}
.hoverview {
  background: linear-gradient(135deg, rgba(74, 90, 60, .35), rgba(34, 41, 32, .85));
  border: 1px solid #526247;
  border-radius: 13px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.55;
  color: var(--fg);
}
.hsec {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 18px;
  background: #232922;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  align-items: center;
}
.himgwrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: zoom-in;
}
.himgwrap img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #171b16;
  display: block;
  transition: transform .15s, border-color .15s;
}
.himgwrap:hover img {
  border-color: var(--acc);
  transform: scale(1.015);
}
.hzoomhint {
  font-size: 13px;
  color: var(--dim);
  text-align: center;
}
.hcontent {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.hstep {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--acc);
  background: rgba(240, 196, 106, .14);
  border: 1px solid rgba(240, 196, 106, .35);
  padding: 2px 9px;
  border-radius: 999px;
  align-self: flex-start;
}
.hcontent h3 {
  font-size: 20px;
  font-weight: 800;
  color: var(--fg);
}
.hsum {
  font-size: 16px;
  line-height: 1.5;
  color: #e2dccb;
  font-weight: 600;
}
.hlist {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hlist li {
  position: relative;
  padding-left: 15px;
  font-size: 15px;
  line-height: 1.52;
  color: #b7bca9;
}
.hlist li::before {
  content: '•';
  position: absolute;
  left: 2px;
  top: 0;
  color: var(--acc);
  font-weight: 800;
}
.hicons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}
.hibadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #1b201a;
  border: 1px solid #394235;
  border-radius: 8px;
  padding: 5px 10px 5px 7px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg);
}
.hibadge i.ic { width: 20px; height: 20px; color: var(--acc); }
.hibadge canvas { width: 22px; height: 22px; flex: none; }

.hzoom {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 9, .88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 65;
  cursor: zoom-out;
  padding: 24px;
}
.hzoom.on { display: flex; }
.hzoom img {
  max-width: min(1180px, 94vw);
  max-height: 90vh;
  border-radius: 14px;
  border: 2px solid var(--acc);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .7);
}

@media (max-width: 860px) {
  .topbar .stat { min-width: 56px; font-size: 14px; }
  .hsec { grid-template-columns: 1fr; }
  .himgwrap { max-width: 460px; margin: 0 auto; }
}

/* Mobile Responsive Layout (Leaves PC >768px untouched) */
#tlEnd, #minimap, #gCv { touch-action: none; -webkit-touch-callout: none; }

@media (max-width: 768px) {
  #scrWorld,
  #scrDesign,
  #scrGraph,
  #scrResult {
    overflow-y: auto;
    justify-content: flex-start;
    padding: 10px 0 18px;
    gap: 10px;
  }

  /* World Setup */
  #scrWorld .card { width: 94vw; max-width: 480px; padding: 12px; }
  #scrWorld .mapprev { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  #scrWorld .card > .row:first-of-type { flex-wrap: wrap; gap: 8px; }
  #scrWorld .card > .row:first-of-type > .row:last-child { flex: 1; min-width: 200px; }
  #scrWorld .code { flex: 1; width: auto; min-width: 0; }
  #scrWorld input[type=range] { flex: 1; width: auto; min-width: 0; }

  /* Species Designer */
  #scrDesign .slotsrow { flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 94vw; }
  #scrDesign .slots { flex-wrap: wrap; justify-content: center; gap: 8px; }
  #scrDesign .slot { width: 50px; height: 50px; }
  #scrDesign .slot canvas { width: 38px; height: 38px; }
  #scrDesign .designer {
    flex-direction: column;
    width: 94vw;
    max-width: 440px;
    padding: 12px;
    gap: 12px;
    align-items: stretch;
  }
  #scrDesign .dleft { gap: 8px; }
  #scrDesign #prevBig { width: 160px; height: 160px; }
  #scrDesign .samples canvas { width: 42px; height: 42px; }
  #scrDesign .tradeoffs { width: 100%; max-width: 260px; }
  #scrDesign .dright { min-width: 0; width: 100%; }
  #scrDesign .presets { flex-wrap: wrap; justify-content: center; }
  #scrDesign .grow { height: auto; min-height: 36px; flex-wrap: wrap; }
  #scrDesign .grow input[type=range] { flex: 1; width: auto; min-width: 0; }
  #scrDesign .tog button { width: 40px; min-width: 40px; }
  #scrDesign .mrow,
  #scrDesign .palrow { flex-wrap: wrap; justify-content: center; height: auto; }
  #scrDesign #codeRow { flex-wrap: wrap; height: auto; row-gap: 6px; justify-content: center; }
  #scrDesign .code { flex: 1; width: auto; min-width: 110px; }
  #scrDesign .unitlib { width: 94vw; max-width: 440px; max-height: 110px; }

  /* Simulation HUD */
  .topbar {
    top: 6px;
    width: calc(100vw - 12px);
    flex-wrap: wrap;
    justify-content: center;
    padding: 5px 8px;
    gap: 4px 5px;
    white-space: normal;
  }
  .topbar button { min-width: 32px; width: 32px; height: 30px; padding: 0 4px; }
  .topbar button i.ic { width: 18px; height: 18px; }
  .topbar .sep { height: 18px; margin: 0 1px; }
  .topbar .stat { min-width: auto; font-size: 12.5px; gap: 3px; margin: 0 3px; }
  .topbar .stat i.ic { width: 15px; height: 15px; }

  .notes { top: 78px; }

  .toolbar {
    left: 6px;
    top: 82px;
    transform: none;
    padding: 4px;
    gap: 4px;
  }
  .toolbar button { min-width: 38px; width: 38px; height: 38px; }
  .toolbar i.ic { width: 20px; height: 20px; }

  .envpop {
    left: 54px;
    top: 140px;
    transform: none;
    width: min(260px, calc(100vw - 62px));
    padding: 10px;
  }
  .envpop input[type=range] { flex: 1; width: auto; min-width: 0; }

  .splist {
    right: 6px;
    top: 82px;
    width: 138px;
    max-height: calc(100vh - 280px);
    padding: 4px;
  }
  .sprow { padding: 2px 4px; gap: 4px; }
  .sprow canvas { width: 22px; height: 22px; }
  .sprow .nm { font-size: 12px; }
  .sprow .ct { font-size: 12px; }

  .mmwrap {
    right: 6px;
    bottom: 6px;
    padding: 4px;
    gap: 4px;
    transition: bottom .18s;
  }
  #minimap { width: 96px; height: 54px; }
  #mmFit { min-width: 26px; width: 26px; height: 26px; }
  .hud:has(#info.on) .mmwrap { bottom: 118px; }

  .info {
    left: 6px;
    right: 6px;
    bottom: 6px;
    transform: none;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px 8px;
    padding: 8px 10px;
  }
  .info #iThumb { width: 42px; height: 42px; }
  .info .bar { width: 64px; }
  .info .genes { gap: 2px 6px; }
  .info .gb { gap: 4px; }
  .info .gb canvas { width: 18px; height: 18px; }
  .info .gb .bar { width: 44px; }
  .info .actbox { width: 36px; height: 36px; }
  .info .actbox i.ic { width: 22px; height: 22px; }
  .info .iactions { grid-template-columns: repeat(2, 32px); gap: 4px; }
  .info .iactions button { min-width: 32px; width: 32px; height: 32px; }

  /* Graph, Result & Guide Modal */
  #scrGraph .card { width: 94vw; padding: 10px; }
  #scrGraph .tabs { flex-wrap: wrap; justify-content: center; }
  #gCv { width: 100%; height: auto; aspect-ratio: 820 / 400; }

  #scrResult .result { width: 94vw; max-height: 80vh; overflow-y: auto; padding: 12px; }
  #scrResult .stats { flex-wrap: wrap; gap: 10px 14px; justify-content: center; }
  #scrResult .stats .stat { font-size: 16px; min-width: auto; }
  #scrResult .cmp canvas { width: 58px; height: 58px; }
  #scrResult .treewrap { width: 100%; max-width: 100%; }
  #scrResult .result > .row:last-child { width: 100%; justify-content: center; }
  #scrResult .code { flex: 1; width: auto; min-width: 0; max-width: 240px; }

  .helpcard { width: 95vw; max-height: 90vh; padding: 12px 14px; gap: 10px; }
  .helphead { flex-wrap: wrap; gap: 8px; }
  .helptitle h2 { font-size: 20px; }
  .helptitle p { font-size: 13.5px; }
  .helplang .lbtn { min-width: 52px; height: 34px; padding: 0 10px; font-size: 13px; }
  .helpnav { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .helpnav button { flex: none; height: 34px; padding: 0 12px; font-size: 13.5px; }
  .hoverview { font-size: 14.5px; padding: 10px 12px; }
  .hsec { padding: 12px; gap: 12px; }
  .hcontent h3 { font-size: 18px; }
  .hsum { font-size: 14.5px; }
  .hlist li { font-size: 14px; }
  .hibadge { font-size: 12.5px; padding: 4px 8px 4px 6px; }
}

@media (max-width: 920px) and (max-height: 500px) {
  #scrTitle,
  #scrWorld,
  #scrDesign,
  #scrGraph,
  #scrResult {
    overflow-y: auto;
    justify-content: flex-start;
    padding: 8px 0 14px;
    gap: 8px;
  }
  #scrWorld .mapprev { width: 320px; height: 180px; }
  .toolbar {
    flex-direction: row;
    left: 8px;
    top: auto;
    bottom: 8px;
    transform: none;
    padding: 4px;
    gap: 4px;
  }
  .toolbar button { min-width: 36px; width: 36px; height: 36px; }
  .envpop { left: 8px; top: auto; bottom: 56px; transform: none; }
  .splist { top: 56px; max-height: calc(100vh - 150px); width: 160px; }
  #minimap { width: 112px; height: 63px; }
  #gCv { width: min(640px, 88vw); height: auto; aspect-ratio: 820 / 400; }
}

/* Tutorial */
#tut { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 50; }
#tut.on { display: block; }
#hand { position: fixed; width: 46px; height: 46px; color: #fff; filter: drop-shadow(0 2px 5px rgba(0, 0, 0, .7)); transition: left .35s, top .35s; }
#hand i.ic { width: 46px; height: 46px; }
#hand.drag i.ic { animation: hdrag 1.6s ease-in-out infinite; }
#hand.tap i.ic { animation: htap 1s ease-in-out infinite; }
@keyframes hdrag { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(80px); } }
@keyframes htap { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(9px) scale(.9); } }
#tutSkip { position: fixed; right: 16px; bottom: 16px; pointer-events: auto; width: 56px; height: 48px; }
.glow { animation: glow 1.2s infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 7px rgba(240, 196, 106, .5); } }

/* Language Toggle Button & 1s Hover Tooltip */
.langBtn {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .5px;
  color: var(--acc);
}
.hovertip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 80;
  pointer-events: none;
  background: rgba(20, 24, 19, .96);
  color: var(--fg);
  border: 1px solid var(--acc);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .14s ease, transform .14s ease;
  visibility: hidden;
}
.hovertip.on {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

/* Developer Panel (` key) */
#dev {
  position: fixed; left: 8px; bottom: 8px; z-index: 60; background: rgba(0, 0, 0, .85);
  color: #cfe; font: 11px Consolas, monospace; padding: 8px; border-radius: 8px;
  display: none; max-height: 90vh; overflow: auto;
}
#dev.on { display: block; }
#dev label { display: flex; justify-content: space-between; gap: 8px; margin: 2px 0; }
#dev input { width: 70px; background: #111; color: #cfe; border: 1px solid #444; font: 11px Consolas, monospace; }
