* { box-sizing: border-box; }

/* Must come before the layout rules below so a hidden flex or grid section
   cannot keep occupying space. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; line-height: 1.15; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--deep);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ══════════════════════════════════ shell ══════════════════════════════════ */

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-display); font-size: 19px; color: var(--deep);
  white-space: nowrap;
}
.brand svg { flex: none; }

.topbar-spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; padding: 0 15px;
  border-radius: var(--r-pill);
  background: var(--mint); color: var(--deep);
  font-weight: 700; font-size: 14px;
  transition: background .15s var(--ease), transform .15s var(--ease);
}
.chip:hover { background: #c9ebda; }
.chip:active { transform: scale(.96); }
.chip[disabled] { opacity: .35; cursor: default; }
.chip.ghost { background: transparent; border: 2px solid var(--line); }

/* ═══════════════════════ category tiles (fish/plants/decor) ════════════════ */

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 10px; }
.cat {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 4px; border-radius: var(--r-md);
  background: var(--canvas); border: 2px solid var(--line);
  font-size: 12px; font-weight: 800; color: var(--muted);
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease);
}
.cat .cemoji { font-size: 21px; line-height: 1; }
.cat:hover { border-color: var(--lagoon); }
.cat[aria-selected="true"] { background: var(--deep); border-color: var(--deep); color: #fff; }
.cat .ccount { font-size: 9.5px; font-weight: 700; opacity: .7; }

.category-empty {
  grid-column: 1 / -1; min-height: 170px; padding: 24px 14px;
  display: grid; place-content: center; gap: 5px; text-align: center;
  background: var(--canvas); border: 1.5px dashed var(--line); border-radius: var(--r-md);
}
.category-empty strong { color: var(--deep); font-family: var(--font-display); font-size: 17px; }
.category-empty span { color: var(--muted); font-size: 12.5px; }

/* ─── the quiz entry point ─── */
.quiz-open {
  display: flex; align-items: center; gap: 10px; text-align: left; width: 100%;
  margin-top: 10px; padding: 10px 12px; border-radius: var(--r-md);
  background: linear-gradient(120deg, #fff6e0, #ffeec6);
  border: 2px solid #f0dca8; color: var(--ink); font-size: 13px; line-height: 1.3;
}
.quiz-open:hover { border-color: var(--sun); }
.quiz-open .qi { font-size: 22px; flex: none; }
.quiz-open small { color: var(--muted); }

/* ═══════════════════════ tank size slider (always on) ══════════════════════ */

.tank-sizer {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end;
}

.scale-ruler {
  position: relative; flex: none; height: 34px; margin-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: 9px; opacity: .78; pointer-events: none;
  transition: width .35s var(--ease);
}
.ruler-mark {
  position: absolute; top: -1px; width: 1px; height: 7px;
  background: currentColor;
}
.ruler-mark span {
  position: absolute; top: 7px; left: 0; transform: translateX(-50%);
  white-space: nowrap;
}
.ruler-mark.at-end span { transform: translateX(-100%); }
.ruler-length { position: absolute; right: 0; bottom: 0; white-space: nowrap; font-weight: 700; }

.sizer-bar {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 11px 14px 8px;
}
.sizer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
              margin-bottom: 4px; flex-wrap: wrap; }
.sizer-name { font-family: var(--font-display); font-size: 19px; color: var(--deep); font-weight: 700; }
.sizer-dims { font-size: 12.5px; color: var(--muted); margin-left: 8px; }
.sizer-note { font-size: 12px; color: var(--muted); text-align: right; flex: 1; min-width: 140px; }

.sizer-range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 34px;
  background: transparent; cursor: pointer; margin: 0;
}
.sizer-range::-webkit-slider-runnable-track {
  height: 10px; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--mint), var(--lagoon));
}
.sizer-range::-moz-range-track {
  height: 10px; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--mint), var(--lagoon));
}
.sizer-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px; margin-top: -10px; border-radius: 50%;
  background: var(--card); border: 4px solid var(--deep);
  box-shadow: var(--shadow-sm); transition: transform .12s var(--ease);
}
.sizer-range::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--card); border: 4px solid var(--deep); box-shadow: var(--shadow-sm);
}
.sizer-range:active::-webkit-slider-thumb { transform: scale(1.14); }
.sizer-range:focus-visible { outline: 3px solid var(--deep); outline-offset: 2px; }

.sizer-ticks { display: flex; justify-content: space-between; font-size: 10px;
               color: var(--muted); font-weight: 700; padding: 0 2px; }
.sizer-ticks span { flex: 1; min-width: 0; text-align: center; }
.sizer-ticks span:first-child { text-align: left; }
.sizer-ticks span:last-child { text-align: right; }
.sizer-ticks .on { color: var(--deep); }

/* ═══════════════════════════════ builder ═══════════════════════════════════ */

.builder { flex: 1; display: grid; gap: 14px; padding: 14px; align-items: start;
           grid-template-columns: 300px minmax(0, 1fr); max-width: 1500px; width: 100%; margin: 0 auto; }

/* ---- shelf ---- */
.shelf {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 12px; position: sticky; top: 74px; max-height: calc(100dvh - 92px);
  display: flex; flex-direction: column;
}
.shelf h2 { font-size: 16px; color: var(--deep); margin-bottom: 2px; }
.shelf .hint { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.filter {
  min-height: 32px; padding: 0 11px; border-radius: var(--r-pill);
  background: var(--canvas); border: 1.5px solid var(--line);
  font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.filter[aria-pressed="true"] { background: var(--deep); border-color: var(--deep); color: #fff; }

.fish-list { overflow-y: auto; display: grid; gap: 8px;
             grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); padding-right: 4px; }

.fish-tile {
  position: relative; background: var(--canvas); border: 1.5px solid var(--line);
  border-radius: var(--r-md); padding: 6px 4px 7px; text-align: center;
  min-height: var(--tap);
  /* Let the shelf scroll normally; the hold-to-drag timer takes over from there. */
  touch-action: pan-y;
  transition: transform .15s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.fish-tile:hover { border-color: var(--lagoon); background: #fff; transform: translateY(-2px); }
.fish-tile:active { transform: scale(.95); }
.fish-tile .tile-name { font-size: 10.5px; font-weight: 700; line-height: 1.2; margin-top: 2px;
                        display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fish-tile .tile-sub { font-size: 9.5px; color: var(--muted); }
.fish-tile svg { display: block; margin: 0 auto; }
.tile-size {
  display: block; width: 34px; height: 3px; margin: 3px auto 0;
  overflow: hidden; border-radius: var(--r-pill); background: var(--line);
}
.tile-size span {
  display: block; width: max(2px, var(--species-size)); height: 100%;
  border-radius: inherit; background: var(--lagoon); opacity: .72;
}

.fish-tile.is-blocked { opacity: .42; }
.fish-tile.is-blocked::after {
  content: ''; position: absolute; inset: 0; border-radius: var(--r-md);
  background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(224,80,63,.16) 6px 12px);
  pointer-events: none;
}
.fish-tile.is-trap { border-color: #f3c4bd; }
.tile-flag {
  position: absolute; top: -6px; right: -4px; background: var(--coral); color: #fff;
  font-size: 8.5px; font-weight: 800; padding: 2px 6px; border-radius: var(--r-pill);
  letter-spacing: .03em;
}
.tile-count {
  position: absolute; top: -7px; left: -5px; min-width: 22px; height: 22px;
  background: var(--deep); color: #fff; border-radius: var(--r-pill);
  font-size: 11.5px; font-weight: 800; display: grid; place-items: center; padding: 0 5px;
}

/* ---- stage ---- */
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.tank-wrap { position: relative; display: flex; gap: 10px; align-items: stretch; min-width: 0; }

.tank {
  position: relative; flex: none; min-width: 0; max-width: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(178deg, var(--water-top) 0%, var(--water-mid) 46%, var(--water-deep) 100%);
  box-shadow: inset 0 0 60px rgba(6, 60, 70, .22), var(--shadow-md);
  border: 5px solid #eef6f4;
  outline: 1px solid var(--line);
  touch-action: none;
  /* Deliberately NOT transitioning width/height.
     The tank's width is a percentage that JS recomputes as the slider moves.
     Transitioning it meant the layout never settled on the target: every tank
     size rendered at an identical 476x191 regardless of the inline style, so a
     5 gallon looked the same as a 125. Showing the true size honestly matters
     far more than a smooth tween. Border colour still animates. */
  transition: border-color .15s var(--ease);
}
.tank.is-target { border-color: var(--lagoon); }
.tank.is-refuse { border-color: var(--coral); }

/* sunlight shafts */
.tank::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(102deg, transparent 12%, rgba(255,255,255,.34) 15%, transparent 21%),
    linear-gradient(97deg, transparent 40%, rgba(255,255,255,.26) 44%, transparent 50%),
    linear-gradient(107deg, transparent 66%, rgba(255,255,255,.3) 70%, transparent 76%);
  mix-blend-mode: soft-light;
}
/* surface shimmer */
.tank::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 12%;
  background: linear-gradient(rgba(255,255,255,.5), transparent);
  pointer-events: none;
}

.gravel {
  position: absolute; left: 0; right: 0; bottom: 0; height: 13%;
  background:
    radial-gradient(circle at 12% 40%, rgba(255,255,255,.3) 0 3px, transparent 4px),
    radial-gradient(circle at 38% 65%, rgba(255,255,255,.24) 0 3px, transparent 4px),
    radial-gradient(circle at 62% 35%, rgba(255,255,255,.28) 0 3px, transparent 4px),
    radial-gradient(circle at 84% 60%, rgba(255,255,255,.22) 0 3px, transparent 4px),
    linear-gradient(var(--gravel), #ad9878);
  border-radius: 0 0 9px 9px;
}
.plants { position: absolute; left: 0; right: 0; bottom: 0; height: 46%; pointer-events: none; }

.tank-empty {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 6px;
  text-align: center; color: var(--deep); pointer-events: none; padding: 20px;
}
.tank-empty .big { font-family: var(--font-display); font-size: clamp(20px, 3vw, 30px); }
.tank-empty .small { font-size: 13.5px; opacity: .8; }
.tank-empty .arrow { animation: nudge 2.4s var(--ease) infinite; }
@keyframes nudge { 0%,100% { transform: translateX(0); opacity:.5 } 50% { transform: translateX(-9px); opacity:1 } }

/* ---- swimming fish ---- */
.swimmer { position: absolute; will-change: transform; pointer-events: auto; cursor: pointer; }
.swimmer .fish-svg { display: block; }
.swimmer .bob { animation: bob var(--bob, 4s) ease-in-out infinite; }
.swimmer .lane { animation: swim var(--dur, 18s) linear infinite; animation-delay: var(--delay, 0s); }

@keyframes swim {
  0%   { transform: translateX(0) scaleX(1); }
  46%  { transform: translateX(var(--range, 200px)) scaleX(1); }
  50%  { transform: translateX(var(--range, 200px)) scaleX(-1); }
  96%  { transform: translateX(0) scaleX(-1); }
  100% { transform: translateX(0) scaleX(1); }
}
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.swimmer.is-flagged .bob { filter: drop-shadow(0 0 0 var(--coral)); }
.swimmer.is-flagged::after {
  content: ''; position: absolute; inset: -8px; border-radius: 50%;
  border: 2.5px dashed var(--coral); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity:.45; transform: scale(1); } 50% { opacity:.95; transform: scale(1.06); } }
.swimmer.is-selected::after {
  content: ''; position: absolute; inset: -8px; border-radius: 50%;
  border: 3px solid var(--sun);
}
.swimmer.is-too-large .lane,
.swimmer.is-too-large .bob { animation: none; }
.swimmer.is-too-large::after {
  content: ''; position: absolute; inset: -5px; border-radius: 10px;
  border: 3px dashed var(--coral); animation: none;
}
.swimmer.is-too-large::before {
  content: 'TOO BIG'; position: absolute; z-index: 2; top: 5px; left: 5px;
  padding: 2px 6px; border-radius: var(--r-pill);
  background: var(--coral); color: #fff; font-size: 9px; font-weight: 800;
  letter-spacing: .04em; line-height: 1.3; white-space: nowrap;
}

/* ---- fullness meter ---- */
.meter {
  width: 62px; flex: none; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 8px 7px; display: flex; flex-direction: column;
  align-items: center; gap: 6px;
}
.meter-label { font-size: 9.5px; font-weight: 800; letter-spacing: .05em; color: var(--muted);
               text-transform: uppercase; }
.meter-tube {
  flex: 1; width: 26px; min-height: 120px; border-radius: var(--r-pill);
  background: linear-gradient(#eaf4f2, #dbeae8); position: relative; overflow: hidden;
  border: 1px solid var(--line);
}
.meter-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--fill, var(--ok)); transition: height .45s var(--ease), background .45s var(--ease);
  height: 0%;
}
.meter-fill::before {
  content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 7px, rgba(255,255,255,.28) 7px 9px);
}
.meter-pct { font-size: 14px; font-weight: 800; color: var(--deep); }
.meter-word { font-size: 9.5px; text-align: center; color: var(--muted); line-height: 1.25; font-weight: 700; }

/* ---- residents ---- */
.residents { display: flex; gap: 8px; flex-wrap: wrap; }
.res {
  display: flex; align-items: center; gap: 6px; background: var(--card);
  border: 1.5px solid var(--line); border-radius: var(--r-pill); padding: 4px 5px 4px 8px;
}
.res.is-flagged { border-color: var(--coral); background: #fff5f3; }
.res .rname { font-size: 12.5px; font-weight: 700; }
.res .step {
  width: 30px; height: 30px; border-radius: 50%; background: var(--mint); color: var(--deep);
  font-size: 17px; font-weight: 800; display: grid; place-items: center; line-height: 1;
}
.res .step[disabled] { opacity: .3; }
.res .rcount { min-width: 22px; text-align: center; font-weight: 800; font-size: 14px; }
.res .rkill { width: 30px; height: 30px; border-radius: 50%; color: var(--coral); font-size: 15px; }

/* ---- verdict / problems ---- */
.verdict {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px;
}
.verdict.is-bad { border-color: #f5cdc7; background: #fff7f6; }
.verdict.is-warn { border-color: #f2e2b6; background: #fffdf5; }
.verdict.is-good { border-color: #bfe8d3; background: #f6fdf9; }

.verdict h2 { font-size: 16px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.problem { display: flex; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.problem:first-of-type { border-top: 0; }
.problem .picon { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid;
                  place-items: center; font-size: 15px; }
.problem.block .picon { background: #fde3df; }
.problem.warn .picon { background: #fdf2d8; }
.problem .ptext { font-size: 13.5px; line-height: 1.45; }
.problem .pwho { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.all-good { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.all-good .tick { width: 30px; height: 30px; border-radius: 50%; background: #d6f5e4;
                  display: grid; place-items: center; flex: none; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: var(--r-pill);
  font-size: 13.5px; font-weight: 700; box-shadow: var(--shadow-lg); z-index: 90;
  transition: transform .3s var(--ease); max-width: min(92vw, 460px); text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.bad { background: #a33325; }

/* ---- drag preview (deliberately not called .ghost: that's the toolbar button style) ---- */
.drag-ghost { position: fixed; z-index: 80; pointer-events: none; transform: translate(-50%, -60%) scale(1.1);
              filter: drop-shadow(0 8px 14px rgba(14,102,114,.35)); }

/* ---- sheets ---- */
.sheet-bg { position: fixed; inset: 0; background: rgba(9,45,52,.45); z-index: 60;
            opacity: 0; pointer-events: none; transition: opacity .25s var(--ease); }
.sheet-bg.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 70; background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); padding: 20px;
  left: 50%; top: 50%; transform: translate(-50%,-46%) scale(.97);
  width: min(560px, 94vw); max-height: 86dvh; overflow-y: auto;
  opacity: 0; pointer-events: none; transition: opacity .25s var(--ease), transform .25s var(--ease);
}
.sheet.show { opacity: 1; pointer-events: auto; transform: translate(-50%,-50%) scale(1); }
.sheet h2 { font-size: 21px; color: var(--deep); margin-bottom: 4px; }
.sheet .close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px;
                border-radius: 50%; background: var(--canvas); font-size: 18px; }

.factgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 8px; margin: 14px 0; }
.fact { background: var(--canvas); border-radius: var(--r-md); padding: 9px 11px; }
.fact .fk { font-size: 10.5px; font-weight: 800; letter-spacing: .04em; color: var(--muted);
            text-transform: uppercase; }
.fact .fv { font-size: 14.5px; font-weight: 700; }

.recipe-list { display: grid; gap: 10px; }
.recipe {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  background: var(--canvas); border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 11px;
}
.recipe:hover { border-color: var(--lagoon); }
.recipe .rtitle { font-weight: 800; font-size: 14.5px; }
.recipe .rblurb { font-size: 12.5px; color: var(--muted); }
.recipe .rtank { font-size: 11px; font-weight: 800; color: var(--deep); background: var(--mint);
                 padding: 2px 8px; border-radius: var(--r-pill); display: inline-block; margin-top: 4px; }

/* ═══════════════════════════════ mobile ════════════════════════════════════ */

@media (max-width: 900px) {
  .builder { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .shelf { position: static; max-height: none; order: 3; }
  .fish-list { max-height: 40dvh; }
  .stage { order: 1; }
  .meter { width: 54px; }
  .brand span { display: none; }
}

@media (max-width: 560px) {
  .fish-list { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}
