/* =============================================================================
 * Aquarium — phone drawing app styles
 * Bright, chunky, kid-friendly. Big touch targets, rounded everything.
 * ===========================================================================*/

:root {
  --bg-top: #000000;
  --bg-bottom: #000000;
  --panel: rgba(255, 255, 255, 0.92);
  --ink: #0b3d91;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  /* Prevent the page itself from scrolling/bouncing while drawing. */
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--ink);
}

#app {
  display: flex;
  flex-direction: column;
  /* dvh = dynamic viewport height: correctly fills the screen on iOS Safari
     even as the address bar shows/hides. */
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
  gap: 8px;
}
/* The `display:flex` above would otherwise override the `hidden` attribute's
   UA `display:none`, so make `hidden` authoritative: the drawing app stays
   fully hidden until a player is picked. */
#app[hidden] { display: none; }

/* -------------------------- Player select -------------------------------- */
/* The "Who's playing?" screen. Big tappable photo cards, one per character. */
.player-select {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}
.player-select.hidden { display: none; }
.ps-title {
  margin: 0;
  font-size: 30px;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
.ps-sub {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}
.ps-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  width: 100%;
  max-width: 440px;
}
.ps-card {
  --accent: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 10px;
  border: none;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.ps-card:active { transform: translateY(4px) scale(0.98); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14); }
.ps-avatar {
  width: 38vw; height: 38vw;
  max-width: 156px; max-height: 156px;
  border-radius: 50%;
  overflow: hidden;
  border: 5px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.5), 0 6px 18px rgba(0, 0, 0, 0.3);
  background: #fff;
}
.ps-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ps-name {
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

/* ----------------------------- Top bar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 0;
}
/* The "you are Ivy" badge — tap to switch characters. */
.player-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
}
.player-badge:active { transform: scale(0.96); }
.player-badge img {
  width: 38px; height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--player-accent, #fff);
  background: #fff;
}
.player-badge { flex: 0 0 auto; }
.player-badge span {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

/* Strip of your most recent still-alive fish, between the badge and the status.
   Takes the leftover middle space; JS renders only as many thumbs as fit. */
.my-fish {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  margin: 0 10px;
}
.fish-thumb {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  margin-right: 6px;            /* spacing as margin (not flex gap) so it can collapse */
  border-radius: 9px;
  padding: 3px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transform-origin: center;
  /* Springy pop on the scale; width/margin/padding animate so neighbors slide. */
  transition:
    transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity   0.22s ease,
    width     0.26s ease,
    margin    0.26s ease,
    padding   0.26s ease;
}
.fish-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
/* Collapsed/invisible state used both before a thumb enters and as it leaves. */
.fish-thumb.enter,
.fish-thumb.leaving {
  width: 0;
  margin-right: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  transform: scale(0.2);
}

.status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: rgba(0, 0, 0, 0.18);
  padding: 6px 10px;
  border-radius: 999px;
}
.status .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #ffd23f;
  box-shadow: 0 0 8px currentColor;
}
.status.connected .dot { background: #34e36b; }
.status.reconnecting .dot { background: #ffb020; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* --------------------------- Canvas area --------------------------------- */
.canvas-wrap {
  flex: 1 1 auto;
  margin: 0 12px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96); /* white drawing surface (canvas itself is transparent) */
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.6), 0 8px 24px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  position: relative;
}
#canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* Critical for smooth drawing on touch: disable browser pan/zoom gestures. */
  touch-action: none;
}

/* ----------------------------- Colors ------------------------------------ */
.colors {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 4px 12px;
}
.swatch {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease;
}
.swatch.active { transform: scale(1.18); border-color: #ffd23f; }
.swatch:active { transform: scale(0.92); }

/* ----------------------------- Tools row --------------------------------- */
.tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 10px;
}
.brushes { display: flex; gap: 8px; align-items: center; }
.brush {
  width: 52px; height: 52px;
  border: none; border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  line-height: 1;
}
.brush[data-size="6"]  { font-size: 14px; }
.brush[data-size="14"] { font-size: 24px; }
.brush[data-size="26"] { font-size: 38px; }
.brush.active { background: #ffd23f; }
.brush:active { transform: translateY(2px); box-shadow: none; }

/* Square icon-only action buttons (undo + clear), matching the brush buttons. */
.actions { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 52px; height: 52px;
  border: none; border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  padding: 0;
}
.icon-btn svg { width: 26px; height: 26px; display: block; }
.icon-btn:disabled { opacity: 0.4; }

.undo-btn { background: #ff9f1c; box-shadow: 0 6px 0 #d97e00; }
.undo-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #d97e00; }

.clear-btn { background: #ff6b6b; box-shadow: 0 6px 0 #d64545; }
.clear-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #d64545; }

/* ----------------------------- Send button ------------------------------- */
.send-btn {
  margin: 4px 14px 14px;
  border: none;
  background: #34e36b;
  color: #06371b;
  font-weight: 900;
  font-size: 26px;
  padding: 18px;
  border-radius: 22px;
  box-shadow: 0 8px 0 #1faa4c;
}
.send-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 #1faa4c; }
.send-btn:disabled { opacity: 0.5; box-shadow: 0 8px 0 #1faa4c; }

/* --------------------------- Red edge glow ------------------------------- */
/* Pulsing red vignette around the screen edges when your fish gets eaten.
   Sits above the eaten popup (z-index 100) and never blocks taps. */
.red-glow {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  box-shadow:
    inset 0 0 70px 12px rgba(255, 0, 0, 0.6),
    inset 0 0 180px 60px rgba(255, 0, 0, 0.45);
  transition: opacity 0.3s ease;
}
.red-glow.show {
  opacity: 1;
  animation: redPulse 0.85s ease-in-out infinite;
}
@keyframes redPulse {
  0%, 100% { opacity: 0.5; }
  50%      { opacity: 1; }
}

/* ----------------------------- Toast ------------------------------------- */
.toast {
  position: fixed;
  left: 50%; bottom: 110px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  padding: 14px 22px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------- Overlays ---------------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  color: #fff;
  padding: 24px;
}
.overlay.hidden { display: none; }
.eaten { background: linear-gradient(180deg, rgba(11, 98, 201, 0.92), rgba(6, 42, 92, 0.95)); }
.gameover { background: linear-gradient(180deg, #3a2a5c, #160c2c); }
.big-emoji { font-size: 88px; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-12px); } }
.overlay-title { font-size: 30px; font-weight: 900; }
.overlay-sub { font-size: 18px; opacity: 0.85; }

/* Fish-eaten popup card with the picture of the eaten fish. */
.eaten-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 26px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.1);
  animation: shake 0.5s ease;
}
.eaten-img {
  max-width: 64vw;
  max-height: 36vh;
  border-radius: 18px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.92); /* light card so the drawing reads */
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px) rotate(-2deg); }
  40% { transform: translateX(10px) rotate(2deg); }
  60% { transform: translateX(-7px) rotate(-1deg); }
  80% { transform: translateX(7px) rotate(1deg); }
}
