:root {
  --ink: #1b2a41;        /* the cartoon outline navy */
  --sand: #f5e6c4;
  --sand-deep: #e9d3a3;
  --lagoon: #2fb7c4;
  --puffer: #f7d44c;
  --coral: #e8604f;
  --water: #0b5f86;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Trebuchet MS", system-ui, sans-serif;
  --pad: max(12px, env(safe-area-inset-bottom));
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--water);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--font);
  color: var(--ink);
}
#tank { display: block; width: 100vw; height: 100vh; height: 100dvh; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--puffer); outline-offset: 3px; }

/* ---- bubble bar ---------------------------------------------------------- */
#bar {
  position: fixed; left: 50%; bottom: var(--pad);
  display: flex; gap: 14px; align-items: flex-end;
  transform: translate(-50%, 140%); opacity: 0;
  transition: transform .35s cubic-bezier(.2, 1.4, .4, 1), opacity .25s;
  z-index: 10;
}
#bar.shown { transform: translate(-50%, 0); opacity: 1; }

.bubble {
  position: relative;
  width: 72px; height: 72px; border-radius: 50%;
  border: 2.5px solid var(--ink);
  background:
    radial-gradient(circle at 32% 28%, #fff 0 9%, transparent 10%),
    radial-gradient(circle at 50% 45%, #e9fbff, #a9e4ee 70%, #7ccfdc);
  box-shadow: 0 3px 0 var(--ink);
  display: grid; place-items: center; align-content: center; gap: 1px;
  padding: 0;
  transition: transform .12s;
}
.bubble:active { transform: translateY(2px) scale(.96); box-shadow: 0 1px 0 var(--ink); }
.bubble svg { width: 30px; height: 30px; fill: var(--ink); }
.bubble svg .eye { fill: #e9fbff; }
.bubble svg .line { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.bubble svg rect { fill: none; stroke: var(--ink); stroke-width: 2.2; }
.bubble span { font-size: 10.5px; font-weight: 800; }
.bubble.small { width: 48px; height: 48px; }
.bubble.small svg { width: 22px; height: 22px; }
.bubble.active {
  background:
    radial-gradient(circle at 32% 28%, #fff 0 9%, transparent 10%),
    radial-gradient(circle at 50% 45%, #fff6cf, var(--puffer) 75%);
}

/* ---- panels ------------------------------------------------------------- */
.panel {
  position: fixed; left: 50%; bottom: calc(var(--pad) + 92px);
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 92px - var(--pad) - 16px);
  overflow-y: auto; overscroll-behavior: contain;
  box-sizing: border-box; padding: 14px 16px 16px;
  background: var(--sand);
  border: 2.5px solid var(--ink); border-radius: 22px;
  box-shadow: 0 4px 0 var(--ink);
  transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
  transition: transform .28s cubic-bezier(.2, 1.2, .4, 1), opacity .2s;
  z-index: 11;
}
.panel.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }

/* on/off switches (Sound panel) */
.switch { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 4px; font-size: 17px; font-weight: 800; cursor: pointer; }
.switch + .switch { border-top: 2px dashed var(--sand-deep); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { position: relative; flex: none; width: 56px; height: 32px; border-radius: 16px;
  border: 2.5px solid var(--ink); background: var(--sand-deep); box-shadow: 0 2px 0 var(--ink);
  transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; border: 2px solid var(--ink); background: #fff; transition: transform .15s; }
.switch input:checked + i { background: var(--lagoon); }
.switch input:checked + i::after { transform: translateX(24px); }
.switch input:focus-visible + i { outline: 3px solid var(--water); outline-offset: 2px; }
.panel header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.panel h2 { margin: 0; font-size: 22px; font-weight: 800; }
.panel header p { margin: 0; flex: 1; font-size: 14px; opacity: .75; }
.panel h3 { margin: 14px 0 8px; font-size: 15px; font-weight: 800; }
.close {
  margin-left: auto; width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--ink); background: #fff; font-size: 24px; line-height: 1;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile {
  display: grid; grid-template-rows: 64px auto auto; justify-items: center; gap: 4px;
  padding: 10px 8px; border-radius: 16px;
  background: var(--sand-deep); border: 2px solid transparent;
}
.tile.in-tank { background: #fff; border-color: var(--ink); }
.tile img { max-width: 100%; max-height: 64px; object-fit: contain; }
.tile .name { font-weight: 800; font-size: 15px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--ink); background: #fff; font-size: 24px; font-weight: 800; line-height: 1;
}
.stepper .plus { background: var(--lagoon); color: #fff; }
.stepper .minus { color: var(--coral); }
.stepper button:disabled { opacity: .3; cursor: default; }
.stepper .count {
  min-width: 26px; text-align: center; font-size: 20px; font-weight: 800;
}
footer { margin-top: 12px; text-align: center; }
.text-btn { background: none; border: none; text-decoration: underline; font-weight: 700; padding: 10px; min-height: 44px; }

.row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.pick { position: relative; flex: 0 0 auto; width: 120px; display: grid; gap: 4px; justify-items: center; }
.pick-btn {
  width: 120px; height: 68px; padding: 0; overflow: hidden;
  border-radius: 14px; border: 2px solid var(--ink); background: var(--sand-deep);
  display: grid; place-items: center;
}
.pick-btn img { width: 100%; height: 100%; object-fit: cover; }
.pick-btn.none {
  background:
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(27, 42, 65, .12) 8px 10px), var(--sand-deep);
}
.pick.selected .pick-btn { border-color: var(--lagoon); box-shadow: 0 0 0 3px var(--lagoon); }
.pick-name { font-size: 13px; font-weight: 700; text-align: center; max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plus-tile { font-size: 34px; font-weight: 800; background: #fff; cursor: pointer; }
.pick-del {
  position: absolute; top: -8px; right: -8px; width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--coral); color: #fff; font-size: 20px; line-height: 1;
}

/* ---- toast -------------------------------------------------------------- */
#toast {
  position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top));
  transform: translate(-50%, -150%); max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 14px;
  background: #fff; border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  font-weight: 700; font-size: 15px; transition: transform .3s; z-index: 20;
}
#toast.shown { transform: translate(-50%, 0); }

/* short landscape phones: smaller bar, panel to the right of it */
@media (max-height: 480px) and (orientation: landscape) {
  .bubble { width: 60px; height: 60px; }
  .bubble svg { width: 24px; height: 24px; }
  .bubble span { font-size: 9.5px; }
  .panel { bottom: calc(var(--pad) + 76px); max-height: calc(100dvh - 76px - var(--pad) - 12px);
    width: min(860px, calc(100vw - 24px)); padding: 10px 14px 12px; }
  .panel header { margin-bottom: 6px; }
  .panel h2 { font-size: 19px; }
  .panel h3 { margin: 6px 0 6px; }
  .close { width: 36px; height: 36px; font-size: 20px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
  .tile { grid-template-rows: 40px auto auto; padding: 6px; gap: 2px; }
  .tile img { max-height: 40px; }
  .tile .name { font-size: 13px; }
  .stepper { gap: 6px; }
  .stepper button { width: 40px; height: 40px; font-size: 21px; }
  .stepper .count { font-size: 17px; min-width: 20px; }
  footer { margin-top: 4px; }
  .pick, .pick-name { width: 104px; max-width: 104px; }
  .pick-btn { width: 104px; height: 54px; }
}

/* narrow portrait phones: the bar has up to 5 bubbles (Feed, Creatures, Scene, Sound, Full screen) */
@media (max-width: 400px) {
  #bar { gap: 8px; }
}
@media (max-width: 350px) {
  .bubble { width: 62px; height: 62px; }
  .bubble.small { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  #bar, .panel, #toast, .bubble { transition: none; }
}
