:root {
  --ink: #e7f0f2;
  --muted: #9eb4bc;
  --sea: #0c242e;
  --sea-2: #12323f;
  --line: #1e4654;
  --gold: #e4b15a;
  --paper: #f4efe6;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #07161c;
  color: var(--ink);
  font-family: "Ubuntu", "DejaVu Sans", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 18px 12px;
  background: var(--sea);
  border-bottom: 1px solid var(--line);
}

.map-field {
  margin: 0;
  min-width: 200px;
}

.open-species,
.close-species,
.species-backdrop {
  display: none;
}

.kicker {
  margin: 0;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
}

h1 {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 700;
}

.hint {
  margin: 0;
  max-width: 460px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
}

.sidebar {
  background: var(--sea-2);
  border-right: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
}

select, input {
  background: #0b1e26;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
}

.groups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.groups label {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

.groups label.off { opacity: 0.45; }

.count {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.species {
  overflow: auto;
  min-height: 0;
  padding-right: 4px;
}

.group-title {
  margin: 12px 0 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
}

.species button.row {
  width: 100%;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  background: transparent;
  color: inherit;
  border: 0;
  border-radius: 8px;
  padding: 5px 6px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}

.species button.row:hover,
.species button.row.active { background: #1a4554; }

.species button.row.off { opacity: 0.38; }

.species img, .dot {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.dot {
  border-radius: 50%;
  display: inline-block;
}

.dot.fish { background: #3ec6d6; }
.dot.creatures { background: #7dce7a; }
.dot.trash { background: #e2b15a; }
.dot.monsters { background: #e06b8a; }

.pins-n {
  color: var(--muted);
  font-size: 11px;
}

#viewport {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, #123844 0, transparent 28%),
    #07161c;
  cursor: grab;
  touch-action: none;
}

#viewport.dragging { cursor: grabbing; }

#stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#map-image {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

#pins { position: absolute; inset: 0; }

.pin {
  position: absolute;
  width: 0;
  height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.pin .glyph {
  width: 40px;
  height: 40px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  transform-origin: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  pointer-events: none;
}

.pin .glyph.dot {
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
}

.pin.active .glyph {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
}

.tools {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 6px;
}

.tools button {
  background: var(--paper);
  color: #102833;
  border: 0;
  border-radius: 8px;
  min-width: 36px;
  height: 36px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.empty {
  position: absolute;
  left: 16px;
  bottom: 16px;
  margin: 0;
  background: rgba(12, 36, 46, 0.92);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  max-width: 280px;
}

.popup {
  position: absolute;
  left: 16px;
  top: 16px;
  width: min(340px, calc(100% - 32px));
  background: var(--paper);
  color: #1c2430;
  border-radius: 14px;
  padding: 12px 78px 14px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.popup h2 {
  margin: 0;
  font-size: 18px;
}

.popup .latin {
  margin: 2px 0 0;
  color: #66707a;
  font-style: italic;
  font-size: 12px;
}

.popup .meta, .popup .where, .popup .how, .popup .note, .popup .flavor {
  margin: 6px 0 0;
  font-size: 13px;
}

.popup .where { font-weight: 700; }

.popup .flavor { font-style: italic; color: #5c5148; }

.popup .note { color: #8a6232; }

.popup-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: #e7e0d4;
  color: #1c2430;
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 860px) {
  .hint { display: none; }

  .top {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 10px;
    align-items: center;
    padding: 10px 12px;
  }

  .brand { grid-column: 1; }

  h1 { font-size: 20px; }

  .map-field {
    grid-column: 1;
    min-width: 0;
  }

  .open-species {
    display: inline-flex;
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: stretch;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: #1c2430;
    border: 0;
    border-radius: 12px;
    padding: 0 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }

  .app {
    display: flex;
    min-height: 0;
  }

  #viewport {
    flex: 1;
    min-height: 0;
  }

  .species-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(4, 12, 16, 0.62);
  }

  .species-backdrop[hidden] {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    inset: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px 14px 18px;
    transform: translateY(110%);
    visibility: hidden;
    transition: transform 0.22s ease;
    max-height: none;
  }

  .sidebar.open {
    transform: none;
    visibility: visible;
  }

  .sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
  }

  .sidebar-head h2 {
    margin: 0;
    font-size: 18px;
  }

  .close-species {
    display: inline-flex;
    border: 0;
    background: #0b1e26;
    color: var(--ink);
    border-radius: 999px;
    padding: 8px 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }

  .species button.row {
    padding: 10px 8px;
    font-size: 15px;
  }

  .species img, .dot {
    width: 28px;
    height: 28px;
  }

  .popup {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: 100%;
    max-height: min(48dvh, 420px);
    overflow: auto;
    border-radius: 18px 18px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }

  .tools {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }
}
