/* =============================================================================
 * 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;
  /* Center the whole stack so spare vertical space splits above the header and
     below the send button, instead of opening a gap between canvas and controls. */
  justify-content: center;
}
/* 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; }

/* ----------------------------- Setup screen ------------------------------ */
/* Type a name + pick a profile image (gallery character or your own upload). */
.setup {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  /* Scrollable: the gallery + note can be taller than the screen. */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 22px) 20px
           calc(env(safe-area-inset-bottom) + 22px);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}
.setup.hidden { display: none; }
.setup-title {
  margin: 0;
  font-size: 28px;
  color: #fff;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
}
.setup-sub {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
}

/* Big round preview of the currently-chosen image. */
.setup-avatar {
  position: relative;
  flex: none;                  /* never squish in the scrolling flex column */
  width: 120px; height: 120px;
  border-radius: 50%;
  overflow: hidden;
  border: 5px solid var(--player-accent, #4aa3ff);   /* blue ring only */
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);        /* soft drop shadow, no grey outline */
  background: #fff;            /* white behind any transparent character art */
  display: grid;
  place-items: center;
}
.setup-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;        /* shown once an image is chosen */
}
.setup-avatar img.show { display: block; }
.avatar-placeholder { font-size: 52px; opacity: 0.8; }

/* Name field. */
.name-input {
  width: 100%;
  max-width: 360px;
  border: none;
  border-radius: 16px;
  padding: 15px 18px;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  text-align: center;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.name-input::placeholder { color: rgba(11, 61, 145, 0.45); font-weight: 700; }
.name-input:focus { outline: 3px solid #ffd23f; }

.setup-label {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.85);
}

/* Gallery of character images — a single horizontally-scrolling row. */
.char-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding-bottom: 6px;         /* breathing room for the scrollbar */
}
.char-tile {
  flex: 0 0 auto;              /* keep each tile its full size; scroll instead of shrink */
  width: 84px; height: 84px;
  scroll-snap-align: start;
  padding: 0;
  border: 3px solid transparent;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.12s ease;
}
.char-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.char-tile:active { transform: scale(0.94); }
.char-tile.selected { border-color: #ffd23f; transform: scale(1.04); }

/* "Upload your own" button (wraps a hidden <input type=file>). */
.upload-btn {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 11px 18px;
  cursor: pointer;
}
.upload-btn:active { transform: scale(0.96); }

.privacy-note {
  max-width: 360px;
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

/* The setup screen's start button isn't fixed to the bottom like the drawing
   screen's send button; give it room and a sensible width. */
.setup .send-btn { width: 100%; max-width: 360px; margin: 8px 0 0; }

/* ----------------------------- Top bar ----------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 0;
}
/* The "this is you" badge — tap to change your name / look. */
.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 --------------------------------- */
/* Holds a square drawing surface sized to the available width. It only takes the
   height the square needs (no flex-grow), so the canvas and the controls below it
   stay grouped together — the leftover vertical slack is centered by #app instead
   of pooling as a gap between the canvas and the buttons. */
.canvas-area {
  flex: 0 1 auto;
  min-height: 0;
  padding: 0 12px;
  display: flex;
  justify-content: center;
}
.canvas-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;            /* square drawing surface, always */
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96); /* white drawing surface (canvas itself is transparent) */
  /* The tracing template (set via JS) sits centered on the white, behind the
     transparent canvas. It's a guide only — never part of the exported fish. */
  background-image: none;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  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%;
  position: relative; /* sit above the template background */
  /* Critical for smooth drawing on touch: disable browser pan/zoom gestures. */
  touch-action: none;
}

/* Tracing-template switch arrows — live in the tools row, styled to match the
   undo/clear icon buttons. */
.templates { display: flex; gap: 2px; align-items: center; }
.tpl-arrow {
  width: 52px; height: 52px;
  border: none; border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 0;
}
.tpl-arrow svg { width: 26px; height: 26px; display: block; }
.tpl-arrow:active { transform: translateY(2px); box-shadow: none; }

/* -------------------- Colors + joystick row ------------------------------ */
.palette-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 4px 12px;
}
.colors {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  gap: 10px;
}
.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); }

/* Joystick that flies your most-recently-drawn fish around the tank on the TV. */
.joystick {
  position: relative;
  flex: none;
  width: 104px; height: 104px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, rgba(255,255,255,0.18), rgba(255,255,255,0.05));
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: var(--shadow), inset 0 2px 10px rgba(0,0,0,0.28);
  display: grid;
  place-items: center;
  touch-action: none;            /* we drive it from pointer events; no scrolling */
}
.joystick.active { border-color: #ffd23f; }
.joy-knob {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff, #d4dde8);
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  pointer-events: none;          /* the base element captures the pointer */
  will-change: transform;
}

/* ----------------------------- Tools row --------------------------------- */
.tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 10px;
}
/* Square icon-only action buttons (undo + clear). */
.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; }
.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; }
