* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #0d1520;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 8px;
}
#wrap {
  width: min(960px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  border-radius: 12px;
  overflow: hidden;
  background: #1e3a5f;
}
.game-stage {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  line-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
#gameCanvas {
  display: block;
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  background: #2c5282;
  touch-action: none;
}
#ui {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 200px;
  flex: 0 0 auto;
  overflow: auto;
}
.panel {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.panel.p1 { background: #c8f0c8; }
.panel.p2 { background: #b8e0f5; }
.problem {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 800;
  color: #333;
  letter-spacing: 0.02em;
}

.count-problem{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.pirate-block{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.7);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
}
.pirate-icon{
  font-size: 0.945em;
  line-height: 1;
}
.pirate-block.is-a{
  filter: saturate(0.25) contrast(1.35) brightness(0.7);
}
.pirate-block.is-b{
  filter: hue-rotate(250deg) saturate(2.2) brightness(1.05) contrast(1.05);
  opacity: 0.95;
}
.count-op{
  font-weight: 900;
  padding: 0 4px;
}

.sr-only{
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.answers {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.tomato {
  width: 72px;
  height: 72px;
  border-radius: 50% 50% 48% 48%;
  border: none;
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
  position: relative;
  transition: transform .08s ease, filter .15s;
  box-shadow: 0 4px 0 rgba(0,0,0,.2), inset 0 -6px 0 rgba(0,0,0,.12);
}
.tomato:hover:not(:disabled) { transform: scale(1.05); filter: brightness(1.05); }
.tomato:active:not(:disabled) { transform: scale(.98); }
.tomato:disabled { cursor: default; opacity: .55; filter: grayscale(.2); }
.tomato.p1 { background: radial-gradient(circle at 30% 28%, #ff6b6b, #d63031 55%, #a82828); }
.tomato.p2 { background: radial-gradient(circle at 30% 28%, #74b9ff, #0984e3 55%, #0652a5); }
.tomato::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 8px;
  background: rgba(40,120,40,.35);
  border-radius: 50%;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
}
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.show { display: flex; }
#overlay .box {
  background: #fff;
  padding: 28px 36px;
  border-radius: 16px;
  text-align: center;
  max-width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
#overlay h2 { font-size: 1.6rem; margin-bottom: 12px; color: #222; }
#overlay button {
  margin-top: 16px;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: #6c5ce7;
  color: #fff;
  cursor: pointer;
}
#overlay button:hover { background: #5b4cdb; }

#wrap.hidden {
  display: none;
}

.btn-menu {
  position: absolute;
  top: max(10px, 1.2vw);
  right: max(10px, 1.2vw);
  z-index: 2;
  padding: 8px 14px;
  font-size: clamp(0.78rem, 2vw, 0.88rem);
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 10px;
  background: rgba(15, 40, 55, 0.55);
  color: #f8fcff;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(6px);
  transition: background 0.15s, transform 0.08s, border-color 0.15s;
}
.btn-menu:hover {
  background: rgba(25, 55, 75, 0.72);
  border-color: rgba(255, 255, 255, 0.6);
}
.btn-menu:active {
  transform: scale(0.98);
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 20px 20px 28px;
  overflow-y: auto;
  /* Cielo → mar (con bandas tipo olas) → espuma → arena */
  background:
    repeating-linear-gradient(
      92deg,
      transparent 0,
      transparent 28px,
      rgba(255, 255, 255, 0.07) 28px,
      rgba(255, 255, 255, 0.07) 30px
    ),
    linear-gradient(
      180deg,
      #b8e6ff 0%,
      #7ec8f0 10%,
      #4eb3e0 22%,
      #2d9bc4 34%,
      #1f87b5 44%,
      #1779a8 52%,
      #156b96 58%,
      #145f86 64%,
      #1a6d8a 70%,
      #2a8a9a 76%,
      #4aa3a8 80%,
      #7ec4c8 83%,
      #a8dce0 85%,
      #c8eef2 87%,
      #d8e8ec 88.5%,
      #c9b896 91%,
      #e0cfa8 94%,
      #edd9b8 96.5%,
      #f2e4c8 99%,
      #f7ecd4 100%
    );
}
.start-logo {
  flex-shrink: 0;
  width: min(400px, 97.5vw);
  max-height: min(175px, 27.5vh);
  height: auto;
  object-fit: contain;
  margin-top: 8px;
  filter: drop-shadow(0 6px 18px rgba(0, 40, 60, 0.35));
}
.start-screen.hidden {
  display: none;
}
.start-box {
  width: min(520px, 100%);
  background: rgba(255, 255, 255, 0.97);
  border-radius: 20px;
  padding: 28px 24px 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.start-title {
  font-size: clamp(1.5rem, 4vw, 1.85rem);
  font-weight: 800;
  color: #1e3a5f;
  text-align: center;
  margin-bottom: 8px;
}
.start-sub {
  text-align: center;
  color: #555;
  font-size: 0.98rem;
  margin-bottom: 22px;
}
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mode-btn {
  padding: 14px 12px;
  font-size: 0.92rem;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: linear-gradient(180deg, #4a90c8 0%, #2d6a9e 100%);
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  box-shadow: 0 4px 0 #1a4a6e, inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: transform 0.08s ease, filter 0.12s;
}
.mode-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.mode-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #1a4a6e;
}
.start-footer {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.start-credit {
  text-align: center;
  font-size: 0.88rem;
  color: #666;
  font-style: italic;
}
.start-author-photo {
  width: min(80px, 21vw);
  max-height: 100px;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.start-counter{
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(45, 106, 158, 0.1);
  border: 1px solid rgba(45, 106, 158, 0.18);
  color: #1e3a5f;
}
.start-counter-label{
  font-size: 0.9rem;
  font-weight: 700;
  opacity: 0.85;
}
.start-counter-value{
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}
.start-author-link {
  font-size: 0.92rem;
  font-weight: 600;
  color: #2d6a9e;
  text-decoration: none;
}
.start-author-link:hover {
  text-decoration: underline;
  color: #1e5080;
}
@media (max-width: 520px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}
