:root {
  --bg: #040a14;
  --dim: #163a6a;
  --mid: #2e74cf;
  --bright: #8fd0ff;
  --white: #ffffff;
  --font: 'Press Start 2P', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--bright);
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.6;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100%;
}

/* ---------- stage ---------- */
#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
}

#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 0 0 2px var(--dim), 0 0 0 4px var(--bg), 0 0 0 6px var(--dim);
}

/* scanlines + vignette */
#stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0px, rgba(0,0,0,0.18) 1px, transparent 1px, transparent 3px),
    radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.5) 100%);
}

#caption {
  position: absolute;
  left: 0; right: 0; bottom: 28px;
  text-align: center;
  color: var(--white);
  text-shadow: 2px 2px 0 var(--bg), 0 0 8px var(--mid);
  padding: 0 16px;
  pointer-events: none;
  z-index: 2;
}

#hint {
  position: absolute;
  left: 0; right: 0; top: 8px;
  text-align: center;
  color: var(--dim);
  font-size: 8px;
  pointer-events: none;
}

#extinct, #away {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(4,10,20,0.85);
  z-index: 3;
}
#extinct .big, #away .big { font-size: 32px; color: var(--white); text-shadow: 4px 4px 0 var(--dim); }
#extinct .small, #away .small { color: var(--mid); text-align: center; line-height: 1.8; }
#extinct button, #away button { flex: 0; min-width: 120px; }
#away { background: rgba(4,10,20,0.7); }
.hidden { display: none !important; }

/* ---------- panel ---------- */
#panel {
  width: 300px;
  padding: 14px 16px;
  overflow-y: auto;
  border-left: 2px solid var(--dim);
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--dim) var(--bg);
}

/* brand: the wordmark is pixel art, kept crisp at whole-number scales */
.px { image-rendering: pixelated; image-rendering: crisp-edges; }
h1.logo { margin: 0 0 14px; padding: 14px 0; line-height: 0; }
h1.logo img { display: block; margin: 0 auto; width: 96px; max-width: 100%; height: auto; }   /* 1x: one logo pixel per screen pixel */

#credit { margin: 12px 0 0; padding: 24px 0 28px; border-top: 2px solid var(--dim); }
#credit img { display: block; width: 130px; max-width: 60%; height: auto; margin: 0 auto; opacity: 0.85; }   /* small, centred, room above and below */

/* the title card: shown as the page opens, then gone; the world runs underneath */
#boot {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  background: var(--bg);
  z-index: 5;
  pointer-events: none;
  animation: bootOut 0.6s steps(4) 2.4s forwards;
}
#boot .word { width: 322px; max-width: 90%; height: auto; }      /* 2x */
@media (min-width: 1200px) { #boot .word { width: 483px; } }    /* 3x */
#boot .studio { width: min(360px, 48%); height: auto; }
@keyframes bootOut { to { opacity: 0; visibility: hidden; } }

h2 {
  font-size: 9px;
  margin: 0 0 6px;
  color: var(--mid);
  letter-spacing: 1px;
}

section {
  border: 2px solid var(--dim);
  padding: 8px 10px;
  margin-bottom: 10px;
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.row span { color: var(--mid); }
.row b { color: var(--white); font-weight: normal; text-align: right; }

.col { display: block; margin: 6px 0 2px; }
.col span { display: block; color: var(--mid); margin-bottom: 3px; }

.bar {
  height: 6px;
  border: 1px solid var(--dim);
  background: var(--bg);
  margin: 3px 0 6px;
}
.bar i {
  display: block;
  height: 100%;
  width: 50%;
  background: var(--mid);
  transition: width .4s steps(8);
}

.gene {
  display: grid;
  grid-template-columns: 48px 1fr 36px;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.gene span { color: var(--mid); font-size: 8px; }
.gene .bar { margin: 0; }
.gene b { font-weight: normal; color: var(--white); font-size: 8px; text-align: right; }

#thoughts {
  margin-top: 6px;
  border-top: 1px dashed var(--dim);
  padding-top: 6px;
  color: var(--bright);
  font-size: 8px;
  line-height: 1.8;
  max-height: 130px;
  overflow: hidden;
}
#thoughts div { white-space: normal; overflow-wrap: anywhere; }
#spoken {
  color: var(--bright);
  font-size: 8px;
  line-height: 1.8;
  max-height: 150px;
  overflow: hidden;
}
#spoken div { white-space: normal; }
#spoken div:first-child { color: var(--white); }
#spoken b { font-weight: normal; color: var(--white); }
#spoken .src { color: var(--dim); }
.sub { margin-top: 6px; font-size: 7px; color: var(--dim); border-top: 1px dashed var(--dim); padding-top: 4px; }
#thoughts { margin-top: 2px; border-top: none; padding-top: 0; max-height: none; }
#thoughts div:first-child { color: var(--white); }
#thoughts b { font-weight: normal; color: var(--white); }
#thoughts .src { color: var(--dim); }

.mem {
  margin-top: 6px;
  border-top: 1px dashed var(--dim);
  padding-top: 5px;
  color: var(--bright);
  font-size: 8px;
  line-height: 1.8;
}
.mem div { white-space: normal; overflow-wrap: anywhere; margin-bottom: 2px; }
.mem.notes { border-top: none; padding-top: 0; color: var(--white); font-style: italic; }
.mem.wrap div { white-space: normal; overflow: visible; margin-bottom: 2px; }
.mem.wrap .src { color: var(--dim); }
.hintline { margin-top: 6px; font-size: 7px; color: var(--dim); }
.row b { max-width: 72%; white-space: normal; overflow-wrap: anywhere; }
.row { align-items: flex-start; }

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

button {
  font-family: var(--font);
  font-size: 8px;
  padding: 7px 8px;
  background: var(--bg);
  color: var(--bright);
  border: 2px solid var(--mid);
  box-shadow: 2px 2px 0 var(--dim);
  cursor: pointer;
  flex: 1;
  min-width: 56px;
}
button:hover { background: var(--dim); color: var(--white); }
button:active { transform: translate(2px,2px); box-shadow: none; }
button.good { border-color: var(--bright); }
button.bad { border-color: var(--dim); color: var(--mid); }
button.bad:hover { color: var(--white); }

input[type=text], select {
  font-family: var(--font);
  font-size: 8px;
  width: 100%;
  padding: 5px 6px;
  background: var(--bg);
  color: var(--white);
  border: 2px solid var(--dim);
  outline: none;
}
select { width: auto; }
input[type=text]:focus, select:focus { border-color: var(--mid); }
input[type=checkbox] { accent-color: var(--mid); width: 14px; height: 14px; }

.msg { font-size: 8px; color: var(--mid); min-height: 14px; margin-top: 4px; word-break: break-word; }
.msg.ok { color: var(--bright); }
.msg.err { color: var(--white); }

/* ---------- the panel can be read in full ---------- */
#spoken, #thoughts { max-height: none; overflow: visible; }
#panel { width: 300px; flex: none; }
#grip {
  width: 6px; flex: none; cursor: col-resize; background: var(--bg);
  border-left: 2px solid var(--dim); touch-action: none;
}
#grip:hover, body.resizing #grip { background: var(--dim); }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
#panel { border-left: none; }
h2.fold { cursor: pointer; user-select: none; }
h2.fold::after { content: ' -'; color: var(--dim); }
section.folded h2.fold::after { content: ' +'; }
section.folded > :not(h2) { display: none !important; }
section.folded h2 { margin: 0; }

/* ---------- the creature card ---------- */
#card {
  position: absolute; z-index: 4; width: 300px; max-width: calc(100% - 16px);
  background: rgba(4, 10, 20, 0.95); border: 2px solid var(--mid);
  box-shadow: 4px 4px 0 var(--dim), 0 0 18px rgba(46, 116, 207, 0.25);
  font-size: 8px; line-height: 1.7; color: var(--bright); cursor: default;
}
#card.dragging { opacity: 0.85; }
.card-head {
  display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 8px;
  background: var(--dim); color: var(--white); cursor: grab; touch-action: none; user-select: none;
}
#card.dragging .card-head { cursor: grabbing; }
.card-head b { flex: 1; font-weight: normal; font-size: 9px; letter-spacing: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-head .grip { width: 8px; height: 10px; background: repeating-linear-gradient(0deg, var(--bright) 0 2px, transparent 2px 4px); opacity: 0.6; }
.card-btn { flex: 0 0 auto; min-width: 0; padding: 2px 6px; font-size: 8px; box-shadow: none; border-width: 1px; }
.card-body {
  max-height: min(62vh, 520px); overflow-y: auto; padding: 8px 10px 10px;
  scrollbar-width: thin; scrollbar-color: var(--mid) var(--bg); overscroll-behavior: contain;
}
#card.folded .card-body { display: none; }
.card-body h3 { font-size: 8px; font-weight: normal; color: var(--mid); letter-spacing: 1px; margin: 10px 0 4px; border-top: 1px dashed var(--dim); padding-top: 6px; }
.card-top { display: flex; gap: 8px; align-items: flex-start; }
#kPortrait { width: 120px; height: 90px; flex: none; border: 1px solid var(--dim); }
#kTop { flex: 1; min-width: 0; }
.kline { margin-bottom: 2px; overflow-wrap: anywhere; }
.kline span, .krow span, .kmeter span, .kgene span { color: var(--mid); }
.kline em, .kmem em { color: var(--white); font-style: normal; }
.ksaid { color: var(--white); margin-top: 4px; overflow-wrap: anywhere; }
.ksaid span { color: var(--mid); }
.krow { display: flex; justify-content: space-between; gap: 8px; margin: 2px 0; }
.krow b { font-weight: normal; color: var(--white); text-align: right; overflow-wrap: anywhere; }
.kmeter, .kgene { display: grid; grid-template-columns: 56px 1fr 74px; gap: 6px; align-items: center; margin: 1px 0; }
.kgene { grid-template-columns: 48px 1fr 46px; }
.kmeter .bar, .kgene .bar { margin: 0; position: relative; }
.kmeter b, .kgene b { font-weight: normal; color: var(--white); text-align: right; white-space: nowrap; }
.kgene .bar u { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--white); opacity: 0.7; z-index: 1; }
.kgene b i { font-style: normal; margin-left: 3px; color: var(--dim); }
.kgene b i.up { color: var(--white); }
.kgene b i.down { color: var(--mid); }
.ktags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.ktags i { font-style: normal; border: 1px solid var(--dim); padding: 0 4px; color: var(--bright); }
.kfoot { color: var(--dim); font-size: 7px; margin-top: 3px; }
.knote { color: var(--white); font-style: italic; margin-top: 3px; overflow-wrap: anywhere; }
.kbond { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 6px; align-items: center; margin: 1px 0; }
.kbond em { color: var(--mid); font-style: normal; }
.kfeel { position: relative; margin: 0; }
.kfeel i { position: absolute; top: 0; bottom: 0; }
.kfeel::before { content: ''; position: absolute; left: 50%; top: -1px; bottom: -1px; width: 1px; background: var(--dim); }
.klink { color: var(--white); text-decoration: underline dotted var(--mid); cursor: pointer; }
.klink:hover { color: var(--bright); }
.kdead { color: var(--dim); }
.kmem { margin: 2px 0; overflow-wrap: anywhere; }
.kmem span { color: var(--dim); display: inline-block; min-width: 30px; }
.kmem.big { color: var(--white); }
.kgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.kgrid div { border: 1px solid var(--dim); padding: 3px 0; }
.kgrid b { display: block; font-weight: normal; color: var(--white); font-size: 9px; }
.kgrid span { color: var(--mid); font-size: 6px; }

/* on a narrow screen the card sits along the bottom of the field */
@media (max-width: 700px) {
  #card { left: 8px !important; right: 8px; top: auto !important; bottom: 8px; width: auto; }
  .card-head { cursor: default; }
  .card-body { max-height: 45vh; }
  #grip { display: none; }
}

/* names in what is said: click to see who is meant, double-click to open its card */
.cname { color: var(--white); text-decoration: underline dotted var(--mid); text-underline-offset: 2px; cursor: pointer; }
.cname:hover { color: var(--white); text-decoration-color: var(--white); }
.cname.on { background: var(--mid); color: var(--white); text-decoration-color: var(--white); }
#thoughts .cname, .kmem .cname { color: var(--white); }
#caption .cname { pointer-events: auto; }

/* the line that ties the open card to its creature: dotted, glowing, marching toward it */
#tether { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
#tetherGlow { stroke: var(--mid); stroke-width: 6; stroke-linecap: round; opacity: 0.18; }
#tetherLine {
  stroke: var(--bright); stroke-width: 3; stroke-dasharray: 3 7; stroke-linecap: butt;
  filter: drop-shadow(0 0 2px var(--bright)) drop-shadow(0 0 5px var(--mid));
  animation: tetherMarch 0.6s steps(5) infinite;
}
#tetherEnd { fill: var(--white); filter: drop-shadow(0 0 3px var(--bright)); }
@keyframes tetherMarch { to { stroke-dashoffset: -10; } }

/* ---------- the panel: a glance, tabs, short reads ---------- */
#glance { border: 2px solid var(--dim); padding: 9px 10px 10px; margin-bottom: 4px; }
.glance-time { color: var(--white); font-size: 9px; letter-spacing: 1px; }
.glance-line { color: var(--bright); font-size: 8px; line-height: 1.9; margin: 6px 0 9px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; text-align: center; }
.tiles div { border: 1px solid var(--dim); padding: 6px 0 5px; }
.tiles b { display: block; font-weight: normal; color: var(--white); font-size: 10px; }
.tiles span { display: block; color: var(--mid); font-size: 6px; margin-top: 4px; letter-spacing: 1px; }

#tabs {
  position: sticky; top: -14px; z-index: 3; display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  margin: 0 -2px 6px; padding: 8px 2px; background: var(--bg); border-bottom: 2px solid var(--dim);
}
#tabs button { min-width: 0; padding: 6px 0; font-size: 7px; box-shadow: none; border-width: 1px; border-color: var(--dim); color: var(--mid); }
#tabs button:hover { color: var(--white); }
#tabs button.on { background: var(--mid); border-color: var(--mid); color: var(--white); }
#tabs button:active { transform: none; }

#panel .tab { display: none; }
#panel .tab.on { display: block; }
.tab section { border: none; border-top: 1px dashed var(--dim); padding: 10px 2px 6px; margin: 0; }
.tab section:first-child { border-top: none; padding-top: 4px; }
.tab h2 { margin-bottom: 8px; }

.note { color: var(--mid); font-size: 7px; line-height: 1.9; margin-top: 4px; }
.feed { font-size: 8px; line-height: 1.9; color: var(--bright); }
.feed > div { padding: 3px 0 4px; border-bottom: 1px solid rgba(22, 58, 106, 0.55); overflow-wrap: anywhere; }
.feed > div:last-child { border-bottom: none; }
.feed .ago { color: var(--dim); display: inline-block; min-width: 30px; }
.feed .lbl { display: block; color: var(--mid); font-size: 6px; letter-spacing: 1px; }
.feed .dim { color: var(--mid); }
.feed b { font-weight: normal; color: var(--white); }

.act { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: center; font-size: 8px; color: var(--bright); }
.act b { font-weight: normal; color: var(--white); }
.act .bar { grid-column: 1 / -1; height: 4px; margin: 2px 0 6px; }

.chat-row { cursor: pointer; padding-left: 4px !important; }
.chat-row:hover { background: rgba(22, 58, 106, 0.35); }
.chat-row.on { background: rgba(46, 116, 207, 0.3); box-shadow: inset 3px 0 0 var(--bright); }
.chat-row .who { color: var(--white); }
.chat-row .who i { font-style: normal; color: var(--mid); }
.chat-row .said { color: var(--bright); padding-left: 30px; }

.power { display: grid; grid-template-columns: 78px 1fr; gap: 10px; align-items: center; margin: 2px 0 8px; }
.power button { flex: none; }
.power span { color: var(--bright); font-size: 7px; line-height: 1.8; }
#panel .tab .row { font-size: 8px; line-height: 1.9; }
#panel .tab .row span { color: var(--mid); }
.chat-row .who em.elder { font-style: normal; color: var(--bright); }

/* the panel put away: the field takes the whole window */
#panelToggle {
  position: fixed; top: 10px; z-index: 6; flex: none; min-width: 0; width: 26px; height: 26px; padding: 0;
  font-size: 9px; line-height: 1; box-shadow: 2px 2px 0 var(--dim); background: var(--bg);
  right: calc(var(--panel-w, 300px) + 18px);
}
body.panel-closed #panel, body.panel-closed #grip { display: none; }
body.panel-closed #panelToggle { right: 10px; }
@media (max-width: 700px) { #panelToggle { display: none; } }

/* the title screen asks a first-time visitor who they are */
#who { display: flex; flex-direction: column; align-items: center; gap: 10px; }
#who label { color: var(--white); font-size: 10px; letter-spacing: 2px; }
#who input { width: 220px; text-align: center; font-size: 10px; padding: 8px; }
#who button { flex: none; min-width: 120px; }
#who .msg { min-height: 12px; }
#welcome { color: var(--bright); font-size: 10px; letter-spacing: 2px; }
body.asking #boot { pointer-events: auto; animation: none; opacity: 1; visibility: visible; }

/* a shared world: visitors watch; the host's own controls are not theirs */
body.shared-view:not(.shared-host) #btnPause, body.shared-view:not(.shared-host) #btnSpeed, body.shared-view:not(.shared-host) #btnReset,
body.shared-view #btnRebirth, body.shared-view #btnImport, body.shared-view #btnBring { display: none; }
body.shared-view #tab-setup section:has(#cfgEnabled) { display: none; }
#toast {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 4;
  padding: 6px 10px; background: var(--bg); border: 2px solid var(--mid); color: var(--white); font-size: 8px;
  opacity: 0; transition: opacity .2s steps(3); pointer-events: none;
}
#toast.on { opacity: 1; }
body.shared-view:not(.shared-host) #tab-sky section:has(#btnPause) { display: none; }
