:root {
  --ink: #1d1d1b;
  --red: #e30613;
  --green: #009a44;
  --grey: #9a9a96;
  --line: #e4e4e0;
  --paper: #ffffff;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --tools-h: 72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
body[data-tool="food"] #world,
body[data-tool="drugs"] #world { cursor: copy; }
body[data-tool="pet"] #world { cursor: grab; }

/* ---------------------------------------------------------------- Kopfzeile */

#top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 4px 16px;
  font-size: 12px;
  color: var(--grey);
  pointer-events: none;
}
#news {
  flex: 1;
  min-width: 0;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
  opacity: 0;
  transition: opacity 0.35s;
}
#news.show { opacity: 1; }
#top button {
  pointer-events: auto;
  color: var(--grey);
  min-width: 36px;
  min-height: 32px;
  font-size: 13px;
}
#top button:hover { color: var(--ink); }

/* ---------------------------------------------------------------- Werkzeuge */

#tools {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--paper);
}
#tools button {
  font-weight: 700;
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0.01em;
  color: transparent;
  -webkit-text-stroke: 1px var(--ink);
  padding: 10px 8px 6px;
  border-bottom: 1px solid transparent;
}
#tools button.food { -webkit-text-stroke-color: var(--red); }
#tools button.drugs { -webkit-text-stroke-color: var(--green); }
#tools button.active { border-bottom-color: var(--ink); }
#tools button.food.active { border-bottom-color: var(--red); }
#tools button.drugs.active { border-bottom-color: var(--green); }

/* ---------------------------------------------------------------- Infoblatt */

#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--tools-h);
  max-width: 460px;
  margin: 0 auto;
  max-height: calc(100% - var(--tools-h) - 60px);
  overflow-y: auto;
  background: var(--paper);
  border-top: 1px solid var(--ink);
  padding: 14px 18px 16px;
  transform: translateY(calc(100% + var(--tools-h) + 4px));
  transition: transform 0.28s ease;
  font-size: 13px;
}
#sheet.open { transform: none; }
@media (min-width: 461px) {
  #sheet { border-left: 1px solid var(--ink); border-right: 1px solid var(--ink); }
}

#sheet .close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 36px;
  height: 36px;
  font-size: 22px;
  font-weight: 300;
  color: var(--grey);
}

.sheet-top {
  display: flex;
  gap: 16px;
  align-items: flex-end;
}
.portrait {
  flex: 0 0 auto;
  width: 120px;
  height: 140px;
}
.meta { padding-bottom: 14px; min-width: 0; }
.meta .name {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px var(--ink);
  overflow-wrap: anywhere;
}
.meta p { margin: 2px 0; color: var(--grey); }
.meta .state { color: var(--ink); }

.bars { margin: 12px 0 10px; }
.bar {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  height: 20px;
}
.bar span { color: var(--grey); }
.bar i {
  position: relative;
  display: block;
  height: 1px;
  background: var(--line);
}
.bar b {
  position: absolute;
  left: 0;
  top: -1px;
  height: 3px;
  width: 0;
  background: var(--ink);
  transition: width 0.3s;
}
.bar.red b { background: var(--red); }
.bar.green b { background: var(--green); }

.facts {
  display: grid;
  grid-template-columns: 76px 1fr;
  row-gap: 4px;
  margin: 0;
}
.facts dt { color: var(--grey); }
.facts dd { margin: 0; }
.facts [hidden] { display: none; }

/* ---------------------------------------------------------------- Stammbaum */

.family .tree-btn {
  margin-left: 8px;
  color: var(--grey);
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.family .tree-btn.on { color: var(--ink); border-bottom-color: var(--ink); }
.family .fam-text:empty + .tree-btn { margin-left: 0; }

.tree { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.tree-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  min-height: 52px;
}
.tree-label { color: var(--grey); font-size: 12px; }
.tree-nodes { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tree .node {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 56px;
  font-size: 11px;
  line-height: 1.2;
}
.tree .node canvas { width: 30px; height: 34px; display: block; }
.tree .node span { max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .node.dead span { color: var(--grey); }
.tree-row.self .node span { font-weight: 700; }

/* ---------------------------------------------------------------- Bestiarium */

#dex {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--paper);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 14px calc(env(safe-area-inset-bottom) + 24px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0s 0.2s;
}
#dex.open { opacity: 1; visibility: visible; transition: opacity 0.2s; }

.dex-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 0 8px;
  background: var(--paper);
  border-bottom: 1px solid var(--ink);
}
.dex-head h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: transparent;
  -webkit-text-stroke: 1px var(--ink);
}
.dex-count { color: var(--grey); font-size: 13px; flex: 1; }
.dex-head button { color: var(--grey); font-size: 13px; min-height: 32px; }
.dex-head button:hover { color: var(--ink); }
.dex-head .close { font-size: 22px; font-weight: 300; width: 32px; }

.dex-detail {
  position: sticky;
  top: 58px;
  z-index: 1;
  display: flex;
  gap: 14px;
  align-items: flex-end;
  padding: 12px 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.dex-detail[hidden] { display: none; }
.dex-big { flex: 0 0 auto; width: 110px; height: 130px; }
.dex-info { min-width: 0; padding-bottom: 4px; }
.dex-info .name {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px var(--ink);
  overflow-wrap: anywhere;
}
.dex-info p { margin: 2px 0; color: var(--grey); }
.dex-info .dex-stats { color: var(--ink); }
.dex-free {
  margin-top: 8px;
  font-weight: 700;
  font-size: 18px;
  color: transparent;
  -webkit-text-stroke: 1px var(--ink);
  border-bottom: 1px solid var(--ink);
  padding: 2px 0;
}
.dex-free:disabled { -webkit-text-stroke-color: var(--grey); border-bottom-color: var(--line); cursor: default; }

.dex-body h4 {
  margin: 18px 0 4px;
  font-size: 12px;
  font-weight: 400;
  color: var(--grey);
}
.dex-body h4 span { margin-left: 4px; }
.dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 2px 6px;
}
.dex-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0 6px;
  border-bottom: 1px solid transparent;
  font-size: 11px;
  color: var(--grey);
}
.dex-cell canvas { width: 100%; height: 64px; display: block; }
.dex-cell span { margin-top: 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dex-cell.known { color: var(--ink); }
.dex-cell.here span::after { content: ' ·'; }
.dex-cell.sel { border-bottom-color: var(--ink); }
