* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --topbar-h: 54px;

  /* structure — Midnight (the default scheme); swap via the tweak panel */
  --bg-deep:   #0a0813;
  --bg:        #100c1e;
  --surface:   #1e1836;
  --surface-2: #271f47;
  --line:      #3d3466;
  --line-hard: #070510;

  /* accent — violet */
  --accent:       #7b5cff;
  --accent-hover: #9578ff;
  --btn:          #3a2f6a;
  --btn-hover:    #4e408a;

  /* text — light to dim */
  --text:       #ece8ff;
  --text-title: #f4f1ff;
  --text-soft:  #d3ccf0;
  --text-muted: #a99fd8;
  --text-dim:   #8a7fbb;
  --text-faint: #6f66a0;

  /* sand tool (active) */
  --sand:      #d9b26a;
  --sand-line: #f2d79a;
  --sand-ink:  #2a1c08;

  /* reset button */
  --reset:       #3a2630;
  --reset-line:  #5a3a44;
  --reset-text:  #e6c9d2;
  --reset-hover: #4c313d;

  /* alert */
  --danger: #e2645a;
}

html, body {
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar (title spans the full width, always visible) ---------- */

#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  border-bottom: 3px solid var(--line-hard);
  z-index: 40;
}

#topbar h1 {
  font-family: "Sansita Swashed", "Segoe UI", cursive;
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-title);
  white-space: nowrap;
  cursor: default;      /* uniform across the whole title... */
  user-select: none;    /* ...so the secret "q" and "a" hotspots stay hidden */
}

/* the hidden hotspots share the title's cursor — no giveaway on hover */
#tweakA, #bestiaryQ { cursor: inherit; }

/* live tank-prestige readout (tap for the accounting), pinned to the right */
#prestige {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  color: var(--text-soft);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

#prestige:hover { background: rgba(255, 255, 255, 0.06); }
#prestige .prestige-star { color: var(--sand); font-size: 1rem; }
#prestige b { font-size: 1.15rem; color: var(--text-title); }

/* prestige accounting modal */
#prestigeOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 14, 22, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: card-fade 0.18s ease-out;
}
#prestigeOverlay[hidden] { display: none; }

.ledger {
  width: min(420px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 22px 64px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  color: var(--text-soft);
}

.ledger-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-family: "Sansita Swashed", "Segoe UI", cursive;
  font-size: 1.3rem;
  color: var(--text-title);
}

.ledger-close { background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; }

.ledger-cols, .ledger-row {
  display: grid;
  grid-template-columns: 1fr auto 50px 42px;
  gap: 10px;
  align-items: center;
  padding: 7px 16px;
}

.ledger-cols {
  font-size: 0.64rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--line);
}

.ledger-cols span:nth-child(n + 2),
.ledger-row span:nth-child(n + 2) { text-align: right; }

.ledger-rows { overflow-y: auto; }
.ledger-row { font-size: 0.82rem; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }
.ledger-row .l-name { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; }
.ledger-row .l-name em { color: var(--text-dim); font-style: normal; font-size: 0.78rem; }
.ledger-row .l-rarity { color: var(--sand); font-size: 0.7rem; letter-spacing: 1px; white-space: nowrap; }
.ledger-row .l-health { font-variant-numeric: tabular-nums; }
.ledger-row .l-pts { font-weight: 700; color: var(--text-title); font-variant-numeric: tabular-nums; }

.ledger-empty { padding: 22px 16px; text-align: center; color: var(--text-dim); }

/* prestige-over-time sparkline */
.ledger-spark { padding: 10px 16px 2px; }
.ledger-spark .sparkline { width: 100%; height: 42px; display: block; overflow: visible; }
.spark-line {
  fill: none;
  stroke: var(--sand);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.spark-area { fill: var(--sand); opacity: 0.12; stroke: none; }
.spark-dot { fill: var(--sand); stroke: var(--bg); stroke-width: 1.5; }

.ledger-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-weight: 700;
  color: var(--text-title);
}
.ledger-total b { font-size: 1.35rem; color: var(--sand); }
.ledger-best { padding: 8px 16px 14px; text-align: right; font-size: 0.76rem; color: var(--text-dim); }
.ledger-best b { color: var(--text-soft); }

/* content row: sidebar + tank stage sit below the bar */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---------- Sidebar ---------- */

#sidebar {
  width: 260px;
  min-width: 260px;
  height: 100%;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
  color: var(--text-soft);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  overflow-y: auto;
  border-right: 3px solid var(--line-hard);
  z-index: 20;
  user-select: none;
  -webkit-user-select: none;
}

#sidebar #shareCode { user-select: text; -webkit-user-select: text; }

.panel h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.panel.grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.panel.hint p {
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-faint);
}

/* water toggle */
.water-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.toggle-btn {
  flex: 1;
  padding: 8px 0;
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.2s;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* tank size toggle */
.size-toggle {
  display: flex;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.size-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 0;
  background: var(--surface);
  color: var(--text-muted);
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s;
}

.size-btn.active {
  background: var(--accent);
  color: #fff;
}

/* scoop / dump / feed tools, all on one row */
.tool-row {
  display: flex;
  gap: 6px;
}

.tool-btn {
  flex: 1;
  background: var(--btn);
  border: 1px solid transparent;
  color: var(--text);
  padding: 7px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  white-space: nowrap;
}

.tool-btn:hover { background: var(--btn-hover); }

.tool-btn.active {
  background: var(--sand);
  color: var(--sand-ink);
  border-color: var(--sand-line);
  font-weight: 600;
}

/* tank action buttons */
.tank-actions, .share-actions {
  display: flex;
  gap: 8px;
}

.tank-actions button, .share-actions button {
  flex: 1;
  background: var(--btn);
  border: none;
  color: var(--text);
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.tank-actions button:hover, .share-actions button:hover { background: var(--btn-hover); }

/* reset lives at the very bottom of the sidebar, below the catalog */
.reset-btn {
  width: 100%;
  background: var(--reset);
  border: 1px solid var(--reset-line);
  color: var(--reset-text);
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.reset-btn:hover { background: var(--reset-hover); }

/* save & share */
.small-note {
  font-size: 0.68rem;
  color: var(--text-faint);
  margin-bottom: 6px;
}

#shareCode {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 0.7rem;
  padding: 6px 8px;
  margin-bottom: 6px;
  font-family: ui-monospace, monospace;
}

/* tabs — sit on top of the catalog panel like real folder tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: -1px;   /* overlap the catalog's top border */
  position: relative;
  z-index: 1;            /* so the active tab can paint over that border */
}

.tab {
  flex: 1;
  padding: 8px 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}

.tab.active {
  background: var(--surface-2);
  border-bottom-color: var(--surface-2); /* dissolve the seam into the panel */
  color: #fff;
  font-weight: 600;
}

/* catalog — a distinct bordered panel the tabs open into */
#catalog {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-content: start;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 0 0 8px 8px; /* flat top — tabs cover it, so any active tab connects cleanly */
}

.catalog-item {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 4px 4px;
  text-align: center;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y; /* let vertical swipes scroll the list; horizontal drags still place */
  transition: border-color 0.15s, transform 0.1s;
}

.catalog-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.catalog-item svg {
  width: 100%;
  height: 44px;
  pointer-events: none;
}

.catalog-item .cname {
  display: block;
  font-size: 0.66rem;
  color: var(--text-soft);
  margin-top: 2px;
  pointer-events: none;
}

/* water-type badge (💧/🌊) — everything is placeable, this just says "home" */
.catalog-item .wbadge {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 0.62rem;
  pointer-events: none;
  opacity: 0.85;
}

/* a species that isn't native to the current water is dimmed, not blocked */
.catalog-item.away { opacity: 0.62; }
.catalog-item.away:hover { opacity: 0.85; }

/* ---------- Tank ---------- */

#stage {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  padding: 20px;
  min-width: 0;
}

#tank {
  position: relative;
  overflow: hidden;
  border: 9px solid #131f28;
  border-radius: 125px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.55), inset 0 0 30px rgba(0, 0, 0, 0.2);
  transition: background 0.6s, width 0.35s ease, height 0.35s ease;
}

#tank.size-nano     { width: 46%;  height: 58%; }
#tank.size-standard { width: 78%;  height: 84%; }
#tank.size-large    { width: 100%; height: 100%; }

#tank.fresh {
  background: linear-gradient(180deg, #7ec8d8 0%, #3a8fa8 35%, #1f6478 75%, #174e5e 100%);
}

#tank.salt {
  background: linear-gradient(180deg, #5aa7d8 0%, #2a6fb0 35%, #174e88 75%, #0e3560 100%);
}

/* light rays — oversized so they can drift/sway without exposing an edge */
#tank::before {
  content: "";
  position: absolute;
  inset: -8% -20%;
  background:
    linear-gradient(100deg, transparent 12%, rgba(255,255,255,0.11) 16%, transparent 22%),
    linear-gradient(100deg, transparent 38%, rgba(255,255,255,0.08) 43%, transparent 50%),
    linear-gradient(100deg, transparent 66%, rgba(255,255,255,0.10) 70%, transparent 77%);
  pointer-events: none;
  z-index: 1;
  transform-origin: 50% 0;
  filter: opacity(var(--ray-strength, 1));
  animation: rays var(--ray-speed, 10s) ease-in-out infinite alternate;
}

@keyframes rays {
  from { transform: translateX(calc(var(--ray-sway, 7%) * -1)) skewX(2deg);  opacity: 0.45; }
  to   { transform: translateX(var(--ray-sway, 7%))            skewX(-6deg); opacity: 1; }
}

#sandLayer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 2;
  pointer-events: none;
}

#sandLayer svg { display: block; width: 100%; }

/* caustics — soft light dappling the sand (rendered inside the sand SVG,
   clipped to the substrate; drifts sideways and loops seamlessly) */
.sand-caustics {
  mix-blend-mode: screen;
  animation: caustics var(--caustic-speed, 16s) ease-in-out infinite alternate;
}

@keyframes caustics {
  from { transform: translateX(-16px); }
  to   { transform: translateX(16px); }
}

#items { position: absolute; inset: 0; z-index: 3; }

.placed {
  position: absolute;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.placed svg { display: block; overflow: visible; }

.placed.dragging { cursor: grabbing; opacity: 0.85; z-index: 9; }

.placed.plant { transform-origin: bottom center; }

.placed.plant .sway {
  transform-origin: 50% 100%;
  animation: sway 4.5s ease-in-out infinite alternate;
}

@keyframes sway {
  from { transform: rotate(-3.5deg); }
  to   { transform: rotate(3.5deg); }
}

.placed.fish { will-change: transform; }

.placed.fish .bob {
  animation: bob 3.2s ease-in-out infinite alternate;
}

@keyframes bob {
  from { transform: translateY(-2px); }
  to   { transform: translateY(2px); }
}

/* tail swish while propelling — flaps in a burst, then glides straight; the
   transition eases the tail back to neutral when the fish stops to rest */
.placed.fish .tail {
  transform-box: fill-box;
  transform-origin: right center;
  transition: transform 0.3s ease;
}

.placed.fish.swimming .tail {
  animation: swim 1.6s ease-in-out infinite;
}

@keyframes swim {
  0%   { transform: rotate(0deg); }
  10%  { transform: rotate(-8deg); }
  20%  { transform: rotate(8deg); }
  30%  { transform: rotate(-7deg); }
  40%  { transform: rotate(6deg); }
  48%  { transform: rotate(0deg); }
  100% { transform: rotate(0deg); } /* glide — tail held straight for the rest of the cycle */
}

/* bubbles */
.bubble {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.55);
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.5), rgba(255,255,255,0.05));
  pointer-events: none;
  z-index: 4;
  animation: rise linear forwards;
}

@keyframes rise {
  from { transform: translateY(0) translateX(0); opacity: 0.9; }
  60%  { transform: translateY(calc(var(--rise) * -0.6)) translateX(8px); }
  to   { transform: translateY(calc(var(--rise) * -1)) translateX(-4px); opacity: 0; }
}

/* food flakes */
.flake {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 40% 60% 55% 45%;
  background: #e8b96a;
  box-shadow: 0 0 2px rgba(0,0,0,0.25);
  pointer-events: none;
  z-index: 6;
}

.flake.rest { opacity: 0.8; }

/* emotes (drama & reactions) */
/* reaction indicator: a green ++ (good) or red -- (bad) above a fish */
.emote {
  position: absolute;
  z-index: 8;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -1px;
  pointer-events: none;
  transform: translate(-50%, -100%);
  animation: emote-pop 0.25s ease-out;
  text-shadow: 0 1px 3px rgba(0,0,0,0.55);
}

.emote.good { color: #46d17a; }
.emote.bad  { color: #ff5a52; }

@keyframes emote-pop {
  from { scale: 0.3; opacity: 0; }
  to   { scale: 1; opacity: 1; }
}

/* ---------- combat & death animations (played on a fish's <svg>) ---------- */

.placed.fish > svg { transform-origin: 50% 50%; }

/* a nip: quick lunge-bite */
.placed.fish > svg.nipping { animation: nip 0.32s ease; }
@keyframes nip {
  0%, 100% { transform: scale(1); }
  45%      { transform: scale(1.17); }
}

/* the kill: a bigger chomp by the predator */
.placed.fish > svg.chomp { animation: chomp 0.42s ease; }
@keyframes chomp {
  0%, 100% { transform: scale(1); }
  25%      { transform: scale(1.3); }
  55%      { transform: scale(0.9); }
}

/* being eaten: gulped down to nothing */
.placed.fish > svg.eaten { animation: eaten 0.34s ease-in forwards; }
@keyframes eaten {
  from { transform: scale(1);    opacity: 1; }
  to   { transform: scale(0.08); opacity: 0; }
}

/* took a hit: the bitten fish flashes red and recoils */
.placed.fish > svg.hit { animation: hit 0.45s ease; }
@keyframes hit {
  0%   { filter: none; transform: translateX(0); }
  12%  { filter: drop-shadow(0 0 4px #ff3b30) drop-shadow(0 0 9px #ff3b30) brightness(1.6); transform: translateX(-4px); }
  38%  { transform: translateX(4px); }
  62%  { transform: translateX(-2px); }
  82%  { transform: translateX(1px); }
  100% { filter: none; transform: translateX(0); }
}

/* the belly-up death (flip → rise → bob → fade) is driven from JS via the
   Web Animations API so the tweak panel can retime each phase */

/* bite spark at the point of contact — fiery, to read as a strike */
.spark {
  position: absolute;
  z-index: 8;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255,236,190,0.95) 0%, rgba(255,90,55,0.7) 45%, transparent 72%);
  animation: spark-pop 0.32s ease-out forwards;
}

@keyframes spark-pop {
  from { transform: scale(0.3); opacity: 1; }
  to   { transform: scale(1.7); opacity: 0; }
}

/* ---------- HP meters above fish ---------- */
.hpbar {
  position: absolute;
  z-index: 7;
  width: 26px;
  height: 4px;
  margin-left: -13px;
  border-radius: 2px;
  background: rgba(6, 18, 26, 0.6);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  pointer-events: none;
  transform: translateY(-100%);
}

.hpfill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.2s linear, background 0.3s;
}

/* ---------- tool mode (scoop/dump/feed) ---------- */
/* objects stay clickable so clicking one puts the active tool away; each tool
   gets its own cursor: down-dip = scoop, up-mound = dump, flakes = feed */
#tank.tool-active { cursor: crosshair; }
#tank.tool-scoop { cursor: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIzMCIgdmlld0JveD0iMCAwIDMwIDMwIj4gPHBhdGggZD0iTTQgNiBRMTUgMTMgMjYgNiIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMTExIiBzdHJva2Utd2lkdGg9IjQiLz4gPHBhdGggZD0iTTQgNiBRMTUgMTMgMjYgNiIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZmZmIiBzdHJva2Utd2lkdGg9IjEuOCIvPiA8cGF0aCBkPSJNMTUgMjYgTDIzIDE2IEwxOCAxNiBMMTggOSBMMTIgOSBMMTIgMTYgTDcgMTYgWiIgZmlsbD0iI2ZmZiIgc3Ryb2tlPSIjMTExIiBzdHJva2Utd2lkdGg9IjEuNiIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIvPjwvc3ZnPg==") 15 15, crosshair; }
#tank.tool-dump { cursor: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIzMCIgdmlld0JveD0iMCAwIDMwIDMwIj4gPHBhdGggZD0iTTQgMjQgUTE1IDE3IDI2IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiMxMTEiIHN0cm9rZS13aWR0aD0iNCIvPiA8cGF0aCBkPSJNMTUgNCBMMjMgMTQgTDE4IDE0IEwxOCAyMSBMMTIgMjEgTDEyIDE0IEw3IDE0IFoiIGZpbGw9IiNmZmYiIHN0cm9rZT0iIzExMSIgc3Ryb2tlLXdpZHRoPSIxLjYiIHN0cm9rZS1saW5lam9pbj0icm91bmQiLz4gPHBhdGggZD0iTTQgMjQgUTE1IDE3IDI2IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS13aWR0aD0iMS44Ii8+PC9zdmc+") 15 15, crosshair; }
#tank.tool-feed { cursor: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIzMCIgdmlld0JveD0iMCAwIDMwIDMwIj4gPGcgc3Ryb2tlPSIjM2EyYTEyIiBzdHJva2Utd2lkdGg9IjEuMiI+IDxjaXJjbGUgY3g9IjkiIGN5PSIxMSIgcj0iMyIgZmlsbD0iI2YwYjk1YSIvPjxjaXJjbGUgY3g9IjE4IiBjeT0iOCIgcj0iMi40IiBmaWxsPSIjZThhOTRhIi8+IDxjaXJjbGUgY3g9IjE0IiBjeT0iMTciIHI9IjMiIGZpbGw9IiNmMGI5NWEiLz48Y2lyY2xlIGN4PSIyMiIgY3k9IjE1IiByPSIyLjQiIGZpbGw9IiNlOGE5NGEiLz4gPGNpcmNsZSBjeD0iMTEiIGN5PSIyMiIgcj0iMi40IiBmaWxsPSIjZWViNDU3Ii8+PC9nPjwvc3ZnPg==") 15 15, crosshair; }

/* toast messages */
#toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 16;
  background: rgba(8, 24, 34, 0.92);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.85rem;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* tooltip */
#tooltip {
  position: absolute;
  z-index: 15;
  background: rgba(8, 24, 34, 0.92);
  color: #fff;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  pointer-events: none;
  white-space: nowrap;
  font-size: 0.85rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

#tooltip span { display: block; font-weight: 600; }

#tooltip em {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* drop hint shown while dragging plants/decor */
#dropHint {
  position: absolute;
  left: 0; right: 0;
  border-top: 2px dashed rgba(255,255,255,0.55);
  z-index: 5;
  pointer-events: none;
}

/* drag ghost */
#dragGhost {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  opacity: 0.8;
  transform: translate(-50%, -50%);
}

#dragGhost svg { display: block; }

/* ---------- Pokémon-style fish cards ---------- */

#cardOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 14, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: card-fade 0.18s ease-out;
}

#cardOverlay[hidden] { display: none; }

@keyframes card-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.pcard {
  position: relative;
  width: 280px;
  border-radius: 16px;
  padding: 11px;
  background: linear-gradient(135deg, #f4d97a 0%, #c9962e 30%, #f8e9ae 50%, #b8860b 70%, #f4d97a 100%);
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  animation: card-pop 0.22s ease-out;
  font-family: "Segoe UI", system-ui, sans-serif;
}

.pcard.salt {
  background: linear-gradient(135deg, #9ecfe8 0%, #3a7fb4 30%, #d4ecf8 50%, #2a6494 70%, #9ecfe8 100%);
}

.pcard.decor {
  background: linear-gradient(135deg, #c2cace 0%, #6e7a82 30%, #dde2e5 50%, #58636a 70%, #c2cace 100%);
}

@keyframes card-pop {
  from { transform: scale(0.85) rotate(-2deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* holo sheen */
.pcard::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,0.35) 45%, transparent 60%);
  pointer-events: none;
}

.pcard-in {
  background: #f8f4e6;
  border-radius: 10px;
  padding: 10px 12px 9px;
  color: #232323;
}

/* every card region has a FIXED height so all cards are pixel-identical;
   overflow is clamped rather than allowed to reflow the layout */
.pcard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  height: 40px; /* room for a 1- or 2-line name */
}

.pcard-name {
  font-weight: 700;
  font-size: 1.02rem;
  line-height: 1.13;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pcard-hp { color: #c62828; font-weight: 700; font-size: 0.92rem; white-space: nowrap; flex-shrink: 0; }
.pcard-tag { color: #5a5a4e; font-weight: 700; font-size: 0.82rem; white-space: nowrap; flex-shrink: 0; }

.pcard-art {
  margin: 7px 0 6px;
  height: 128px;
  border: 3px solid #d9c26a;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #8fd0de 0%, #3a8fa8 70%, #e2ca92 100%);
}

.pcard.salt .pcard-art {
  border-color: #7ab4d4;
  background: linear-gradient(180deg, #6cb4e0 0%, #1d5a96 70%, #e8dcbe 100%);
}

.pcard.decor .pcard-art {
  border-color: #9aa4ab;
  background: linear-gradient(180deg, #b4bec4 0%, #6a757c 70%, #d2d8db 100%);
}

/* fits wide fish and tall plants/decor alike inside the 128px art box */
.pcard-art svg { max-width: 66%; max-height: 96%; width: auto; height: auto; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.25)); }

.pcard-sci {
  font-style: italic;
  font-size: 0.74rem;
  color: #5a5a52;
  text-align: center;
  margin-bottom: 6px;
  height: 1.05rem;
  line-height: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pcard-stats {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 27px;
  font-size: 0.72rem;
  color: #444;
  background: #efe8cf;
  border-radius: 5px;
  margin-bottom: 7px;
  overflow: hidden;
}

.pcard-stats span { white-space: nowrap; }

/* dot separators between the stats */
.pcard-stats span:not(:first-child)::before {
  content: "·";
  margin: 0 10px;
  color: #c9962e;
  font-weight: 700;
}

.pcard.salt .pcard-stats span:not(:first-child)::before { color: #3a7fb4; }

/* fish temperament on its own tidy line */
.pcard-trait {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: #5a5a4e;
  margin-bottom: 6px;
  height: 1.15rem;
  line-height: 1.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* two real facts, each in its own colored box (fixed height, clamped) */
.pcard-facts {
  height: 88px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

.pcard-facts .fact {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 7px;
  background: #dfeeda;      /* freshwater: soft sage */
  font-size: 0.78rem;
  line-height: 1.24;
  color: #33402f;
}

.pcard.salt .pcard-facts .fact {
  background: #d9e8f4;      /* saltwater: soft sky */
  color: #2c3945;
}

.pcard-facts .fact span {
  display: block;
  max-height: 2.6em;
  overflow: hidden;
  text-wrap: balance; /* even the two lines & pull orphan words up */
}

.pcard-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  height: 18px;
  margin-top: 10px; /* breathing room between the facts and the diet/stars */
  font-size: 0.7rem;
  color: #444;
}

.pcard-foot .pcard-diet {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pcard-foot .stars { color: #c9962e; letter-spacing: 1px; font-size: 0.8rem; white-space: nowrap; flex-shrink: 0; }

/* add-to-tank button under the card */
.pcard-add {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.pcard-add:hover { background: var(--accent-hover); }
.pcard-add:active { transform: translateY(1px); }

.pcard-close {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  z-index: 1;
}

/* sidebar trash highlight while dragging a placed item over it */
#sidebar.trash-target {
  outline: 3px dashed var(--danger);
  outline-offset: -6px;
}

/* ---------- Responsive: collapse controls behind a hamburger ---------- */

/* the hamburger lives in the top bar, shown only when the sidebar collapses */
#hamburger {
  display: none;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

body.nav-open #hamburger { background: var(--accent); }

#navScrim { display: none; }

@media (max-width: 760px) {
  #hamburger { display: block; }

  /* full-width drawer that slides in below the title bar */
  #sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    width: 100%;
    height: calc(100% - var(--topbar-h));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 30;
    box-shadow: 0 0 44px rgba(0, 0, 0, 0.65);
  }

  body.nav-open #sidebar { transform: translateX(0); }

  #stage { padding: 10px; }

  /* give the tank room on small screens */
  #tank.size-nano     { width: 82%; height: 60%; }
  #tank.size-standard { width: 94%; height: 82%; }
  #tank.size-large    { width: 100%; height: 100%; }
}

/* ---------- hidden tweak panel (opened by the title's final "a") ---------- */

#tweak {
  position: fixed;
  top: calc(var(--topbar-h) + 8px);
  left: 8px;
  z-index: 60;
  width: 264px;
  max-height: calc(100vh - var(--topbar-h) - 24px);
  overflow-y: auto;
  padding: 10px 12px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.6);
  color: var(--text-soft);
  font-size: 0.75rem;
  backdrop-filter: blur(6px);
}

#tweak[hidden] { display: none; }

.tweak-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-title);
}

.tweak-x {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
}

.tweak-sec {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  margin-top: 8px;
}

.tweak-sec h4 {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 7px;
}

.tweak-row {
  display: grid;
  grid-template-columns: 74px 1fr 30px;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.tweak-row.toggle { grid-template-columns: 1fr auto; }
.tweak-row span { color: var(--text-muted); }
.tweak-row b { text-align: right; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.tweak-row input[type="range"] { width: 100%; accent-color: var(--accent); }

.tweak-pals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tweak-pals button {
  padding: 7px 6px;
  border-radius: 6px;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.72rem;
}

.tweak-pals button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- kill-all button in the tweak panel ---------- */
.tweak-btn {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  background: var(--reset);
  border: 1px solid var(--reset-line);
  color: var(--reset-text);
  font-size: 0.78rem;
  font-weight: 600;
}
.tweak-btn:hover { background: var(--reset-hover); }

/* ---------- bestiary (all fish cards, opened by the title's "q") ---------- */

#bestiaryOverlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 14, 22, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: card-fade 0.18s ease-out;
}
#bestiaryOverlay[hidden] { display: none; }

.bestiary {
  width: min(920px, 100%); /* fits exactly 3 cards (280px) with equal 18px gaps */
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 22px 64px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.bestiary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  font-family: "Sansita Swashed", "Segoe UI", cursive;
  font-size: 1.4rem;
  color: var(--text-title);
}

.bestiary-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.bestiary-grid {
  overflow-y: auto;
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, 280px); /* fixed-width cards → equal h & v gaps */
  gap: 18px;
  justify-content: center;
  align-content: start;
}

/* cards in the grid: no close/add button, no pop-in stagger */
.bestiary .pcard.flat { animation: none; }
