:root {
  --bg: #f3f1ec;
  --bg-soft: #faf8f3;
  --ink: #151515;
  --ink-soft: #54524c;
  --ink-muted: #7b7972;
  --line: rgba(21, 21, 21, 0.18);
  --line-soft: rgba(21, 21, 21, 0.1);
  --panel: rgba(252, 250, 246, 0.78);
  --surface: rgba(255, 255, 255, 0.86);
  --surface-soft: rgba(255, 255, 255, 0.66);
  --accent: #1f1f1f;
  --success: #27573d;
  --error: #7b2f37;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1400px 720px at -8% -10%, rgba(255, 255, 255, 0.95), transparent 62%),
    radial-gradient(1100px 700px at 108% 108%, rgba(255, 255, 255, 0.82), transparent 68%),
    repeating-radial-gradient(
      circle at 25% 22%,
      rgba(21, 21, 21, 0.015) 0,
      rgba(21, 21, 21, 0.015) 1px,
      transparent 1px,
      transparent 6px
    ),
    linear-gradient(180deg, #fcfbf7 0%, #f4f2ee 100%);
  color: var(--ink);
  font-family: "Roboto Flex", "IBM Plex Sans", "Segoe UI", sans-serif;
  font-variation-settings:
    "opsz" 16,
    "GRAD" 40;
  letter-spacing: 0.003em;
}

#app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1rem 1rem 1.45rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  letter-spacing: 0.011em;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.9rem);
  font-weight: 700;
  line-height: 1.02;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  max-width: 66ch;
}

.language-switch {
  display: grid;
  gap: 0.36rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

select,
input,
button {
  font: inherit;
}

.language-switch select,
.field select,
.field input,
.button,
.upload-zone {
  border-radius: 0;
}

.language-switch select,
.field select,
.field input {
  min-height: 2.4rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.93);
  padding: 0 0.72rem;
}

.field input[aria-invalid="true"] {
  border-color: rgba(139, 49, 59, 0.8);
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(8px);
  padding: 0.95rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

.muted {
  color: var(--ink-soft);
  line-height: 1.35;
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.78rem;
}

.upload-zone {
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.76);
  min-height: 6.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0.95rem;
  margin-top: 0.78rem;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease;
}

.upload-zone:hover {
  border-color: rgba(21, 21, 21, 0.34);
  background: rgba(255, 255, 255, 0.9);
}

.upload-zone input {
  display: none;
}

.upload-status {
  margin: 0.56rem 0 0;
  min-height: 1.2rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.button {
  min-height: 2.45rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  padding: 0.45rem 0.92rem;
  cursor: pointer;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    border-color 180ms ease;
}

.button:hover {
  border-color: rgba(21, 21, 21, 0.4);
}

.button.primary,
.button.accent {
  background: var(--accent);
  color: #f4f4f4;
  border-color: var(--accent);
}

.button.primary:hover,
.button.accent:hover {
  background: #0d0d0d;
  border-color: #0d0d0d;
}

.game-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-bottom: 0.72rem;
}

.toolbar-bank {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.toolbar-actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.board {
  position: relative;
  /* Alto atado al viewport menos la cabecera, la barra y el pie: si el tablero
     se sale, hay que desplazar la pagina justo cuando estas arrastrando. */
  height: clamp(360px, calc(100vh - 17rem), 820px);
  height: clamp(360px, calc(100dvh - 17rem), 820px);
  overflow: hidden;
  border: 1px solid rgba(18, 18, 18, 0.24);
  background: linear-gradient(180deg, #eaf5fa 0%, #dceaf3 60%, #f5f4f0 100%);
}

.water-canvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.board::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 255, 255, 0.38), transparent 46%),
    radial-gradient(circle at 84% 40%, rgba(255, 255, 255, 0.16), transparent 52%);
  mix-blend-mode: screen;
}

/* Por encima de .bucket-area (4): los peces pescados se ven DENTRO del cubo, y
   el que se arrastra no desaparece al pasar sobre la zona de cubos. */
.text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 5;
  /* La capa esta por encima de los cubos, asi que no puede interceptar el raton:
     solo los peces reciben eventos, y soltar sobre un cubo llega al cubo. */
  pointer-events: none;
  contain: layout style paint;
}

.text-fish[hidden] {
  display: none;
}

.text-fish {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  white-space: pre;
  font-family: "Roboto Flex", "IBM Plex Sans", sans-serif;
  letter-spacing: 0.005em;
  color: hsl(206 16% 26%);
  pointer-events: auto;
  cursor: grab;
  user-select: none;
  touch-action: none;
  will-change: transform, color;
  transform-origin: 50% 50%;
  z-index: 7;
  transition: opacity 180ms ease;
}

/* El cuerpo se dibuja en SVG detras del texto y se voltea con el sentido de la
   marcha. Solo se espeja el SVG: la frase se sigue leyendo de izquierda a
   derecha nade el pez hacia donde nade. */
.fish-body {
  position: absolute;
  left: 50%;
  top: 50%;
  overflow: visible;
  pointer-events: none;
  transform: translate(-50%, -50%) scaleX(var(--fish-facing, 1));
}

.fish-shape {
  fill: rgba(255, 255, 255, 0.5);
  stroke: currentColor;
  stroke-width: 1.15;
  stroke-linejoin: round;
}

.fish-tail,
.fish-fin {
  fill: rgba(255, 255, 255, 0.34);
  stroke: currentColor;
  stroke-width: 1;
  stroke-linejoin: round;
}

.fish-tail {
  transform-box: view-box;
  transform-origin: var(--tail-origin-x, 0px) var(--tail-origin-y, 0px);
  animation: tailBeat var(--beat-duration, 800ms) ease-in-out infinite alternate;
  animation-delay: var(--beat-delay, 0ms);
}

.fish-fin-pectoral {
  animation: finBeat calc(var(--beat-duration, 800ms) * 1.6) ease-in-out infinite alternate;
  animation-delay: var(--beat-delay, 0ms);
  transform-box: view-box;
  transform-origin: var(--tail-origin-x, 0px) var(--tail-origin-y, 0px);
}

.fish-gill {
  fill: none;
  stroke: currentColor;
  stroke-width: 0.9;
  opacity: 0.55;
}

.fish-eye {
  fill: currentColor;
}

.text-fish.long .fish-shape {
  fill: rgba(255, 250, 242, 0.58);
}

.text-fish.hovered .fish-shape {
  fill: rgba(255, 255, 255, 0.78);
  stroke-width: 1.5;
}

.text-fish.hooked {
  z-index: 14;
  cursor: grabbing;
}

.text-fish.hooked .fish-shape {
  fill: rgba(255, 255, 255, 0.9);
  stroke-width: 1.6;
}

/* Forcejeo: la cola bate mas rapido cuando el pez esta enganchado. */
.text-fish.hooked .fish-tail {
  animation-duration: calc(var(--beat-duration, 800ms) * 0.42);
}

.fish-lines {
  position: relative;
  z-index: 1;
  display: block;
  text-align: center;
}

.fish-line {
  display: block;
}

@keyframes tailBeat {
  from {
    transform: rotate(-11deg);
  }
  to {
    transform: rotate(11deg);
  }
}

@keyframes finBeat {
  from {
    transform: rotate(-7deg);
  }
  to {
    transform: rotate(6deg);
  }
}

.long-fish-panel {
  position: absolute;
  top: 0.62rem;
  left: 0.7rem;
  max-width: min(560px, calc(100% - 1.4rem));
  max-height: min(30vh, 250px);
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 0.68rem;
  z-index: 16;
}

.long-fish-panel h3 {
  font-size: 1rem;
  margin-bottom: 0.36rem;
}

.long-fish-text {
  display: grid;
  gap: 0.11rem;
  color: var(--ink);
}

.long-fish-text span {
  display: block;
}

.bucket-peek-panel {
  position: absolute;
  top: 0.62rem;
  right: 0.7rem;
  width: min(430px, calc(100% - 1.4rem));
  max-height: min(36vh, 290px);
  overflow: auto;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  padding: 0.62rem;
  z-index: 17;
}

.bucket-peek-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.58rem;
}

.bucket-peek-head h3 {
  font-size: 1.04rem;
  line-height: 1.08;
}

.bucket-peek-close {
  min-height: 2rem;
  padding: 0.22rem 0.56rem;
  font-size: 0.82rem;
}

.bucket-peek-meta {
  margin: 0.36rem 0 0.42rem;
  color: var(--ink-soft);
  font-size: 0.87rem;
}

.bucket-peek-list {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.24rem;
  font-size: 0.96rem;
  line-height: 1.3;
}

.bucket-peek-empty {
  color: var(--ink-soft);
  font-style: italic;
}

.bucket-area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 27%;
  z-index: 4;
  border-top: 1px solid rgba(18, 18, 18, 0.16);
  padding: 0.5rem 0.56rem 0.4rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  background: linear-gradient(180deg, rgba(240, 238, 231, 0.9), rgba(246, 244, 238, 0.96));
}

.bucket {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.3rem 0.34rem 0;
  border-radius: 4px;
  cursor: pointer;
  transition:
    background 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

.bucket:hover,
.bucket:focus-visible {
  background: hsl(var(--bucket-hue, 200) 40% 94%);
  outline: none;
}

.bucket.active {
  background: hsl(var(--bucket-hue, 200) 42% 91%);
  transform: translateY(-2px);
}

.board.inspecting-bucket .bucket {
  opacity: 0.5;
}

.board.inspecting-bucket .bucket.active {
  opacity: 1;
}

.bucket-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}

.bucket-vessel {
  position: relative;
  flex: 1;
  min-height: 96px;
}

.bucket-svg {
  position: absolute;
  inset: 0;
}

.bucket-body,
.bucket-mouth {
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.bucket-handle {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.bucket-stave {
  fill: none;
  stroke-width: 1;
  opacity: 0.7;
}

.bucket-label {
  font-family: "Newsreader", Georgia, serif;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.12;
  color: hsl(var(--bucket-hue, 200) 34% 26%);
}

.bucket-label span {
  display: block;
}

.bucket-count {
  flex: none;
  font-size: 0.72rem;
  white-space: nowrap;
  color: rgba(18, 18, 18, 0.6);
}

.results-summary {
  margin: 0.38rem 0 0;
  color: var(--ink-soft);
  line-height: 1.35;
}

.results-metrics {
  margin-top: 0.78rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.52rem;
}

.result-metric {
  border: 1px solid var(--line-soft);
  background: var(--surface);
  padding: 0.5rem 0.56rem;
  display: grid;
  gap: 0.16rem;
}

.result-metric-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.result-metric-value {
  font-family: "Newsreader", Georgia, serif;
  font-size: clamp(1.05rem, 2vw, 1.34rem);
  font-weight: 700;
  line-height: 1;
}

.result-metric.ok .result-metric-value {
  color: var(--success);
}

.result-metric.bad .result-metric-value {
  color: var(--error);
}

.results-buckets {
  margin-top: 0.88rem;
  display: grid;
  gap: 0.62rem;
}

.result-card {
  border: 1px solid var(--line-soft);
  background: var(--surface-soft);
  padding: 0.64rem;
}

.result-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.66rem;
}

.result-card h3 {
  font-size: 1.2rem;
  line-height: 1.03;
}

.result-card-stats {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.result-pill {
  border: 1px solid var(--line-soft);
  padding: 0.16rem 0.42rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.68);
}

.result-pill.ok {
  color: var(--success);
}

.result-pill.bad {
  color: var(--error);
}

.result-items {
  list-style: none;
  margin: 0.56rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.24rem;
}

.result-items li {
  line-height: 1.28;
}

.result-item-ok {
  color: #1f5c3f;
}

.result-item-bad {
  color: #8b313b;
}

.result-empty {
  color: var(--ink-soft);
  font-style: italic;
}

.app-footer {
  margin-top: 0.95rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line-soft);
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.35;
}

.app-footer p {
  margin: 0;
}

.app-footer a {
  color: var(--ink);
}

.app-footer a:hover {
  color: #000;
}

body.exporting-pdf #resultsScreen .actions {
  display: none;
}

body.exporting-pdf #resultsScreen {
  border-color: rgba(18, 18, 18, 0.1);
  background: #ffffff;
}

@media (max-width: 960px) {
  .setup-grid {
    grid-template-columns: 1fr;
  }

  .board {
    height: clamp(320px, calc(100vh - 18rem), 700px);
    height: clamp(320px, calc(100dvh - 18rem), 700px);
  }

  .bucket-area {
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    min-height: 32%;
  }

  .bucket-peek-panel {
    width: min(370px, calc(100% - 1.4rem));
    max-height: min(40vh, 270px);
  }
}

@media (max-width: 700px) {
  #app {
    padding: 0.72rem;
  }

  .topbar {
    flex-direction: column;
    margin-bottom: 0.7rem;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .panel {
    padding: 0.75rem;
  }

  /* En estrecho los cubos van en rejilla de dos columnas y mas bajos, para que
     todos quepan dentro del tablero sin empujar la pagina. */
  .bucket-area {
    grid-template-columns: repeat(2, 1fr);
    min-height: 38%;
  }

  .bucket {
    min-height: 0;
  }

  .bucket-vessel {
    min-height: 62px;
  }

  .board {
    height: clamp(300px, calc(100vh - 21rem), 620px);
    height: clamp(300px, calc(100dvh - 21rem), 620px);
  }

  .bucket-label {
    font-size: 0.84rem;
  }

  .bucket-peek-panel,
  .long-fish-panel {
    position: absolute;
    top: auto;
    left: 0.45rem;
    right: 0.45rem;
    bottom: calc(34% + 0.4rem);
    width: auto;
    max-width: none;
  }

  .result-card-head {
    flex-direction: column;
  }

  .result-card-stats {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fish-tail,
  .fish-fin-pectoral {
    animation: none;
  }
}

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

.boot-error {
  margin: 1rem 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--error);
  background: rgba(123, 47, 55, 0.06);
  color: var(--error);
  line-height: 1.4;
}

.button.subtle {
  align-self: flex-start;
  margin-top: 0.4rem;
  font-size: 0.82rem;
  padding: 0.3rem 0.6rem;
}

/* Pez cogido con el teclado: tiene que cantar sin depender del color. */
.text-fish:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.text-fish.selected .fish-shape {
  fill: rgba(255, 255, 255, 0.95);
  stroke-width: 2;
}

.text-fish.selected {
  z-index: 15;
}

.board.picking-fish .bucket {
  outline: 1px dashed rgba(18, 18, 18, 0.4);
  outline-offset: -3px;
}

.bucket:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
