* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', sans-serif;
  background: linear-gradient(180deg, #0e4d92 0%, #0a3d7a 60%, #072f5f 100%);
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- coloring page ---------- */

/* The grid outgrew the screen once there were more than a dozen creatures, and
   the body does not scroll, so this pane carries its own scrolling. Centring is
   done with auto margins: justify-content would push the first row out of reach
   past the top of the scroll box. */
#picker-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3vh;
  padding: 4vh 4vw;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

#picker-screen h1 {
  font-size: clamp(1.6rem, 5vw, 3rem);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  text-align: center;
  margin-top: auto;
  flex-shrink: 0;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 2.5vmin;
  width: min(92vw, 1000px);
  margin-bottom: auto;
  flex-shrink: 0;
}

.template-card {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 24px;
  padding: 2vmin;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1vmin;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  transition: transform 0.1s;
}

.template-card:active {
  transform: scale(0.94);
}

.template-card svg {
  width: 100%;
  height: 15vmin;
}

.template-card span {
  font-size: clamp(1rem, 3vmin, 1.6rem);
  font-weight: bold;
  color: #0e4d92;
}

#draw-screen {
  height: 100%;
  display: none;
  flex-direction: column;
}

#draw-screen.active {
  display: flex;
}

#canvas-area {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px;
}

#canvas-stack {
  position: relative;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

#canvas-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 20px;
}

#outline-layer {
  pointer-events: none;
}

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.25);
}

/* A grid rather than a wrapping row: with two dozen colours, auto-fit keeps the
   rows even at any width instead of leaving one swatch stranded on its own. */
#palette {
  --swatch: clamp(34px, 5vmin, 46px);
  display: grid;
  grid-template-columns: repeat(auto-fit, var(--swatch));
  justify-content: center;
  gap: 8px;
  max-width: min(100%, 720px);
}

.swatch {
  width: var(--swatch);
  height: var(--swatch);
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.55);
  transition: transform 0.1s;
}

.swatch.selected {
  border-color: #fff;
  transform: scale(1.2);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.8);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  min-width: clamp(44px, 7vmin, 60px);
  height: clamp(44px, 7vmin, 60px);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  font-size: clamp(1.1rem, 3vmin, 1.6rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: #0e4d92;
  font-weight: bold;
}

.tool-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.tool-btn.selected {
  background: #ffd93d;
  box-shadow: 0 0 10px rgba(255, 217, 61, 0.9);
}

.brush-dot {
  border-radius: 50%;
  background: #0e4d92;
  display: inline-block;
}

#done-btn {
  background: linear-gradient(180deg, #2ecc71, #27ae60);
  color: #fff;
  font-size: clamp(1rem, 3vmin, 1.5rem);
  font-weight: bold;
  border-radius: 18px;
  padding: 0 20px;
  height: clamp(48px, 8vmin, 64px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

#done-btn:active {
  transform: scale(0.95);
}

#back-btn {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

#splash-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 47, 95, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vh;
  z-index: 50;
  text-align: center;
  padding: 5vw;
}

#splash-overlay.active {
  display: flex;
}

#splash-overlay .big {
  font-size: clamp(3rem, 14vmin, 8rem);
  animation: swim-away 2.4s ease-in forwards;
}

#splash-overlay h2 {
  font-size: clamp(1.4rem, 5vmin, 2.6rem);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.5);
}

@keyframes swim-away {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translateX(60vw) scale(0.4);
    opacity: 0;
  }
}

/* ---------- aquarium ---------- */

#tank {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#empty-hint {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2vh;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
}

#empty-hint h1 {
  font-size: clamp(1.6rem, 5vw, 3.4rem);
}

#empty-hint p {
  font-size: clamp(1rem, 3vw, 1.8rem);
  opacity: 0.85;
}

/* ---------- tank: joining and pairing ---------- */

/* Several of the elements below are display:flex, which would otherwise
   beat the hidden attribute. */
[hidden] {
  display: none !important;
}

.qr {
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  line-height: 0;
}

.qr svg {
  width: 100%;
  height: auto;
  display: block;
}

.qr:empty {
  display: none;
}

#hint-qr {
  width: min(34vmin, 320px);
  margin-top: 1vh;
}

#join-corner {
  position: fixed;
  right: 2vmin;
  bottom: 2vmin;
  width: clamp(110px, 13vmin, 180px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: clamp(0.8rem, 1.6vmin, 1.1rem);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  opacity: 0.92;
}

#join-corner .qr {
  width: 100%;
}

#pair-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5vh;
  text-align: center;
  padding: 4vmin;
  background: rgba(7, 47, 95, 0.55);
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

#pair-screen h1 {
  font-size: clamp(1.8rem, 5vw, 3.4rem);
}

#pair-screen p {
  font-size: clamp(1rem, 2.6vmin, 1.6rem);
  max-width: 60ch;
}

#pair-qr {
  width: min(32vmin, 300px);
}

.pair-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: clamp(2rem, 7vmin, 4.5rem);
  letter-spacing: 0.12em;
  background: rgba(255, 255, 255, 0.95);
  color: #0b2545;
  border-radius: 16px;
  padding: 1vmin 3vmin;
  text-shadow: none;
}

/* ---------- kids' join screens ---------- */

#join-needed,
.kid-center {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3vh;
  text-align: center;
  padding: 6vw;
}

#join-needed .big,
.kid-center .big {
  font-size: clamp(3rem, 16vmin, 8rem);
}

#join-needed h1,
.kid-center h1 {
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

#join-needed p,
.kid-center p {
  font-size: clamp(1rem, 3vmin, 1.5rem);
  max-width: 40ch;
  opacity: 0.9;
}

.kid-button {
  background: linear-gradient(180deg, #2ecc71, #27ae60);
  color: #fff;
  font-size: clamp(1.3rem, 4vmin, 2rem);
  font-weight: bold;
  border-radius: 24px;
  padding: 2vmin 6vmin;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.kid-button:active {
  transform: scale(0.95);
}

/* ---------- grown-up pages ---------- */

/* The kids' pages are full-screen and never scroll; the parents' pages are
   ordinary documents. */
html.page,
html.page body {
  height: auto;
  min-height: 100%;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}

.grownup {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
}

.grownup h1,
.grownup h2,
.grownup h3 {
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI', sans-serif;
  line-height: 1.2;
}

.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: 5vh 20px 8vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.wrap.narrow {
  max-width: 520px;
}

.card {
  background: rgba(255, 255, 255, 0.95);
  color: #0b2545;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.card h2 {
  color: #0e4d92;
  margin-bottom: 12px;
  font-size: 1.4rem;
}

.card h3 {
  color: #0e4d92;
  margin-bottom: 6px;
}

.card p + p {
  margin-top: 10px;
}

.muted {
  opacity: 0.75;
  font-size: 0.95rem;
}

.error {
  color: #c0392b;
  font-weight: 600;
  margin-top: 12px;
}

.success {
  color: #1e8449;
  font-weight: 600;
  margin-top: 12px;
}

.link {
  color: inherit;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  background: #e8f1fb;
  color: #0e4d92;
  border: 2px solid transparent;
}

.btn:hover {
  border-color: #0e4d92;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: linear-gradient(180deg, #2ecc71, #27ae60);
  color: #fff;
}

.btn-danger {
  background: #fdecea;
  color: #c0392b;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.9rem;
  border-radius: 10px;
}

.btn-wide {
  width: 100%;
}

.btn-google {
  width: 100%;
  background: #fff;
  border-color: #c9d8ea;
  color: #0b2545;
}

.grownup input[type='email'],
.grownup input[type='text'] {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  border-radius: 12px;
  border: 2px solid #c9d8ea;
  color: #0b2545;
}

.grownup input:focus {
  outline: none;
  border-color: #0e4d92;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-weight: 600;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.check input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.row > input {
  flex: 1;
  min-width: 180px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.spaced {
  margin-top: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tabs button {
  flex: 1;
  padding: 10px;
  border-radius: 12px;
  background: #e8f1fb;
  color: #0e4d92;
  font-weight: 700;
  font-size: 1rem;
}

.tabs button.active {
  background: #0e4d92;
  color: #fff;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  opacity: 0.6;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: currentColor;
}

.hero {
  text-align: center;
  padding: 4vh 0 1vh;
}

.hero .emoji {
  font-size: clamp(3rem, 10vw, 5rem);
}

.hero h1 {
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
}

.hero .lead {
  font-size: 1.2rem;
  max-width: 560px;
  margin: 12px auto 24px;
}

.hero .row {
  justify-content: center;
}

.grid-3 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.site-footer {
  text-align: center;
  opacity: 0.8;
}

.site-footer a {
  color: inherit;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.top-bar h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
}

.join-panel {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  align-items: center;
}

@media (max-width: 560px) {
  .join-panel {
    grid-template-columns: 1fr;
  }

  .join-panel .qr {
    max-width: 240px;
  }
}

.join-panel .qr {
  border: 2px solid #e8f1fb;
}

.device-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #f3f7fc;
  border-radius: 12px;
  flex-wrap: wrap;
}

.device-list .name {
  font-weight: 700;
  flex: 1;
  min-width: 140px;
}

.token-box {
  font-family: ui-monospace, Consolas, monospace;
  background: #0b2545;
  color: #d6f5ff;
  padding: 12px;
  border-radius: 10px;
  word-break: break-all;
  font-size: 0.85rem;
  -webkit-user-select: all;
  user-select: all;
}

.prose h2 {
  margin-top: 20px;
}

.prose ul {
  padding-left: 22px;
  margin-top: 8px;
}

/* ---------- family page ---------- */

#bg-options {
  display: flex;
  flex-wrap: wrap;
  gap: 2vmin;
}

.bg-card {
  width: 180px;
  border-radius: 16px;
  overflow: hidden;
  background: #f3f7fc;
  color: #0e4d92;
  font-weight: bold;
  font-family: inherit;
  padding: 0 0 10px;
  border: 4px solid transparent;
  transition: transform 0.1s;
}

.bg-card:active {
  transform: scale(0.95);
}

.bg-card.selected {
  border-color: #ffd93d;
  box-shadow: 0 0 12px rgba(255, 217, 61, 0.8);
}

.bg-card .swatch-strip {
  height: 80px;
  display: block;
}

.bg-card span {
  display: block;
  padding-top: 8px;
}

.bg-reef .swatch-strip {
  background: linear-gradient(180deg, #1a6db5 0%, #0e4d92 55%, #d9b26f 88%, #d9b26f 100%);
}

.bg-deep .swatch-strip {
  background: linear-gradient(180deg, #0d2b55 0%, #081d3c 55%, #7d6f52 88%, #7d6f52 100%);
}

.bg-lagoon .swatch-strip {
  background: linear-gradient(180deg, #4fd4e7 0%, #1fa2d0 55%, #f0dca6 88%, #f0dca6 100%);
}

#fish-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 2vmin;
}

.fish-card {
  background: #f3f7fc;
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #0e4d92;
}

.fish-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
}

.fish-card .meta {
  font-size: 0.85rem;
  text-align: center;
}

.fish-card button {
  background: #e74c3c;
  color: #fff;
  border-radius: 10px;
  padding: 8px 16px;
  font-weight: bold;
}
