/* Atoll. The palette follows nautical charts: white for deep water, a blue
   tint for shallows, buff for land, and magenta for anything you can act on.
   Dark mode is the chart plotter's night palette. Living things are set in
   italics, the way charts letter the water. */
:root {
  --paper: #f7f9f8;
  --paper-a: rgba(247, 249, 248, .93);
  --shoal: #d5e7f0;
  --buff: #ecdcae;
  --ink: #18262f;
  --soft: #55666f;
  --line: rgba(24, 38, 47, .20);
  --hair: rgba(24, 38, 47, .10);
  --magenta: #a8247f;
  --magenta-ink: #fff;
  --danger: #a33a22;
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Alegreya", Georgia, "Times New Roman", serif;
  --top: 44px; --rail: 64px; --side: 304px; --foot: 72px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b151d;
    --paper-a: rgba(11, 21, 29, .90);
    --shoal: #15303f;
    --buff: #574c2c;
    --ink: #d3dcd8;
    --soft: #8496a0;
    --line: rgba(190, 215, 225, .22);
    --hair: rgba(190, 215, 225, .10);
    --magenta: #e678bf;
    --magenta-ink: #1a0b15;
    --danger: #ee9a80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background: #05090d; color: var(--ink);
  font: 400 13px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#gl.tooling { cursor: crosshair; }
#gl.dragging { cursor: grabbing; }

button, input, select { font: inherit; color: inherit; }
button {
  appearance: none; border: 1px solid var(--line); background: transparent; border-radius: 4px;
  padding: 5px 10px; cursor: pointer; line-height: 1.2;
}
button:hover { border-color: var(--ink); }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
button.ghost { border-color: transparent; }
button.ghost:hover { background: var(--shoal); border-color: transparent; }
button.primary { background: var(--magenta); color: var(--magenta-ink); border-color: var(--magenta); font-weight: 600; }
button.danger { color: var(--danger); }
button[disabled] { opacity: .45; cursor: default; }
.spacer { flex: 1; }
.only-narrow { display: none; }

/* ---- top strip: the worlds */
#top {
  position: fixed; left: 0; right: 0; top: 0; height: var(--top); z-index: 5;
  display: flex; align-items: center; gap: 4px; padding: 0 10px 0 14px;
  background: var(--paper-a); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { font: italic 700 21px/1 var(--serif); letter-spacing: .01em; margin-right: 12px; }
#worlds { display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; align-self: stretch; align-items: stretch; }
#worlds::-webkit-scrollbar { display: none; }
.world {
  display: flex; align-items: center; gap: 8px; padding: 0 10px 0 12px; border: 0; border-radius: 0;
  border-bottom: 2px solid transparent; white-space: nowrap; color: var(--soft);
}
.world:hover { color: var(--ink); border-color: transparent; border-bottom-color: var(--line); }
.world[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--magenta); }
.world .wname { font: italic 500 16px/1 var(--serif); }
.world .wpop { font-size: 11.5px; color: var(--soft); min-width: 2.2em; text-align: right; }
.world .wmenu { border: 0; padding: 2px 4px; margin-left: -2px; border-radius: 3px; color: var(--soft); font-size: 15px; line-height: 1; }
.world .wmenu:hover { background: var(--shoal); color: var(--ink); }
.world.fork .wname::before { content: "\2937"; font-style: normal; font-family: var(--sans); margin-right: 5px; color: var(--soft); }
#clock { color: var(--soft); padding: 0 8px; white-space: nowrap; }
#clock b { color: var(--ink); font-weight: 500; }

/* ---- left rail: powers */
#tools {
  position: fixed; left: 10px; top: calc(var(--top) + 10px); z-index: 4; width: var(--rail);
  background: var(--paper-a); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 4px; max-height: calc(100% - var(--top) - var(--foot) - 30px); overflow-y: auto; scrollbar-width: none;
}
#toolList { display: flex; flex-direction: column; gap: 1px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px;
  border: 0; border-radius: 4px; font-size: 11px; color: var(--soft); width: 100%;
}
.tool svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: var(--shoal); color: var(--ink); }
.tool[aria-checked="true"] { background: var(--magenta); color: var(--magenta-ink); }
.brush { display: block; padding: 8px 4px 4px; border-top: 1px solid var(--hair); margin-top: 4px; font-size: 11px; color: var(--soft); text-align: center; }
.brush input { width: 100%; margin: 4px 0 0; accent-color: var(--magenta); }

/* ---- right sheet */
#panel {
  position: fixed; right: 10px; top: calc(var(--top) + 10px); bottom: calc(var(--foot) + 10px); width: var(--side); z-index: 4;
  display: flex; flex-direction: column;
  background: var(--paper-a); border: 1px solid var(--line); border-radius: 6px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  user-select: text; -webkit-user-select: text;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 6px; flex: none; }
.tabs button { border: 0; border-radius: 0; padding: 10px 8px 8px; color: var(--soft); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--magenta); font-weight: 500; }
.tab { overflow-y: auto; padding: 12px 14px 16px; flex: 1; scrollbar-width: thin; }
.tab h3 { font: 600 12px/1.3 var(--sans); margin: 16px 0 6px; color: var(--soft); }
.tab h3:first-child { margin-top: 0; }
.tab p { margin: 0 0 8px; }
.muted { color: var(--soft); }
.name { font: italic 500 16px/1.2 var(--serif); }
.big-name { font: italic 500 22px/1.15 var(--serif); margin: 0 0 2px; }

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; margin-bottom: 12px; }
.totals div { display: flex; flex-direction: column; }
.totals b { font: 500 19px/1.1 var(--sans); }
.totals span { color: var(--soft); font-size: 11.5px; }

.species { list-style: none; margin: 0; padding: 0; }
.species li { display: grid; grid-template-columns: 14px 1fr auto; align-items: baseline; gap: 8px; padding: 5px 4px; border-radius: 4px; cursor: pointer; }
.species li:hover { background: var(--shoal); }
.species .dot { width: 10px; height: 10px; border-radius: 50%; align-self: center; }
.species .kind { display: block; font: 400 11.5px/1.2 var(--sans); color: var(--soft); }
.species .n { font-weight: 500; text-align: right; }
.species .plague { color: var(--danger); font-size: 12px; margin-left: 4px; }
.vitals { margin: -4px 0 12px; font-size: 12px; line-height: 1.5; }
.species .n small { display: block; font-weight: 400; color: var(--soft); font-size: 11px; }

.bars { display: grid; grid-template-columns: auto 1fr auto; gap: 5px 8px; align-items: center; margin: 10px 0; }
.bar { height: 6px; background: var(--shoal); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink); border-radius: 3px; }
.bar.energy i { background: #c98a12; } .bar.health i { background: #3c9a5a; } .bar.age i { background: var(--soft); }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; margin: 0; }
.facts dt { color: var(--soft); } .facts dd { margin: 0; text-align: right; }
.organs { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0 2px; }
.organs span { display: inline-flex; align-items: center; gap: 4px; }
.organs i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; border: 1px solid var(--line); }
.acts { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.brain { width: 100%; height: auto; display: block; margin-top: 4px; }

.law { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; margin-bottom: 10px; }
.law label { grid-column: 1; } .law output { grid-column: 2; color: var(--soft); }
.law input[type=range] { grid-column: 1 / 3; width: 100%; accent-color: var(--magenta); margin: 3px 0 0; }
.law small { grid-column: 1 / 3; color: var(--soft); font-size: 11.5px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.check input { accent-color: var(--magenta); margin-top: 2px; }
.check small { display: block; color: var(--soft); font-size: 11.5px; }

.log { list-style: none; margin: 0; padding: 0; }
.log li { display: grid; grid-template-columns: 4.6em 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--hair); }
.log time { color: var(--soft); }
.log .species-ev { font-style: italic; font-family: var(--serif); font-size: 14.5px; }

/* ---- bottom strip: time and the record */
#bottom {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--foot); z-index: 5;
  display: flex; align-items: stretch; gap: 12px; padding: 0 14px 0 10px;
  background: var(--paper-a); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.time { display: flex; align-items: center; gap: 8px; flex: none; }
#playBtn { width: 38px; height: 38px; border-radius: 50%; padding: 0; display: grid; place-items: center; border-color: var(--ink); }
#playBtn svg { width: 16px; height: 16px; fill: currentColor; }
#speeds { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
#speeds button { border: 0; border-radius: 0; padding: 6px 8px; min-width: 34px; color: var(--soft); }
#speeds button + button { border-left: 1px solid var(--hair); }
#speeds button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
#ribbonWrap { flex: 1; min-width: 0; position: relative; margin: 8px 0; }
#ribbon { width: 100%; height: 100%; display: block; border-radius: 3px; }
#ribbonTip {
  position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 5px 8px; z-index: 6;
}
#readout { flex: none; display: flex; flex-direction: column; justify-content: center; text-align: right; color: var(--soft); min-width: 9.5em; }
#readout b { color: var(--ink); font-weight: 500; }

/* ---- floating bits */
#tip {
  position: fixed; z-index: 7; pointer-events: none; transform: translate(14px, 14px);
  background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; max-width: 260px;
}
#toast {
  position: fixed; left: 50%; bottom: calc(var(--foot) + 18px); transform: translateX(-50%); z-index: 8;
  background: var(--ink); color: var(--paper); border-radius: 4px; padding: 8px 14px; max-width: min(92vw, 520px);
}
#veil { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--paper); transition: opacity .5s ease; }
#veil p { font: italic 500 24px var(--serif); margin: 0; }
#veil.gone { opacity: 0; pointer-events: none; }

.menu {
  position: fixed; z-index: 9; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 4px; min-width: 180px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; padding: 7px 10px; }
.menu button:hover { background: var(--shoal); }
.menu hr { border: 0; border-top: 1px solid var(--hair); margin: 4px 0; }

.tile-label {
  position: fixed; z-index: 3; pointer-events: none; padding: 6px 10px;
  font: italic 500 17px/1.1 var(--serif); color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .7);
}
.tile-label small { display: block; font: 400 12px/1.3 var(--sans); opacity: .85; }

dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 20px 22px; width: min(92vw, 440px); user-select: text; }
dialog::backdrop { background: rgba(4, 10, 14, .55); }
dialog h2 { font: italic 500 24px/1.1 var(--serif); margin: 0 0 14px; }
dialog label, dialog legend { display: block; font-weight: 500; margin-bottom: 12px; padding: 0; }
dialog .hint { font-weight: 400; color: var(--soft); margin-left: 6px; }
dialog input[type=text], dialog input[type=number] { display: block; width: 100%; margin-top: 5px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 4px; background: transparent; }
dialog input[type=range] { display: block; width: 100%; margin-top: 6px; accent-color: var(--magenta); }
dialog fieldset { border: 0; padding: 0; margin: 0 0 12px; }
#nwPresets { display: grid; gap: 4px; }
#nwPresets label { display: flex; gap: 8px; font-weight: 400; margin: 0; padding: 6px 8px; border: 1px solid var(--hair); border-radius: 4px; cursor: pointer; }
#nwPresets label:has(input:checked) { border-color: var(--magenta); }
#nwPresets input { accent-color: var(--magenta); }
#nwPresets small { display: block; color: var(--soft); }
#helpDialog { width: min(94vw, 560px); }
#helpDialog p { margin: 0 0 12px; line-height: 1.5; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 0 0 14px; }
.keys dt { font-weight: 600; white-space: nowrap; }
.keys dd { margin: 0; line-height: 1.5; }
kbd { font: 500 12px var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; margin: 0 1px; background: var(--shoal); }
@media (max-width: 560px) { .keys { grid-template-columns: 1fr; gap: 2px; } .keys dd { margin-bottom: 8px; } }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }

/* Chinese has no italic: headings fall back to the sans, only Latin names stay slanted */
:lang(zh) dialog h2, :lang(zh) #veil p { font: 600 21px/1.3 var(--sans); }
:lang(zh) body { line-height: 1.55; }
:lang(zh) .tool { font-size: 11.5px; }

/* ---- every world at once */
body.grid #tools, body.grid #panel { display: none; }

.tree-wrap { position: relative; }
.tree { width: 100%; display: block; }
.tree-note { min-height: 2.9em; margin: 0 0 8px; }

/* ---- narrow screens: the sheet slides up from the bottom */
@media (max-width: 820px) {
  :root { --side: 100%; --foot: 60px; --rail: 56px; }
  .only-narrow { display: inline-block; }
  #gridBtn, #clock { display: none; }
  #panel { left: 8px; right: 8px; width: auto; top: auto; height: 46vh; display: none; }
  body.panel-open #panel { display: flex; }
  #ribbonWrap { display: none; }
  #bottom { justify-content: space-between; }
  .brand { font-size: 18px; margin-right: 4px; }
  #tools { top: calc(var(--top) + 8px); left: 8px; }
}
@media (max-width: 560px) {
  #readout { display: none; }
  #speeds button { min-width: 30px; padding: 6px 6px; }
  .world .wpop { display: none; }
  #forkBtn, #newBtn { padding: 5px 7px; }
}
@media (prefers-reduced-motion: reduce) { #veil { transition: none; } }
