:root {
  --deep: #06243a;
  --mid: #0b4a6f;
  --shallow: #1a8bb3;
  --foam: #e8fbff;
  --sand: #f3d9a4;
  --coral: #ff6b6b;
  --sun: #ffd93d;
  --ink: #06243a;
  --card: rgba(255, 255, 255, 0.12);
  --radius: 18px;
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Baloo 2', system-ui, sans-serif;
  color: var(--foam);
  background: linear-gradient(180deg, var(--shallow) 0%, var(--mid) 45%, var(--deep) 100%) fixed;
  min-height: 100dvh;
  overflow-x: hidden;
}

.bubbles {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(circle at 15% 80%, rgba(255,255,255,.18) 0 6px, transparent 7px),
    radial-gradient(circle at 80% 60%, rgba(255,255,255,.14) 0 9px, transparent 10px),
    radial-gradient(circle at 60% 90%, rgba(255,255,255,.12) 0 4px, transparent 5px),
    radial-gradient(circle at 30% 30%, rgba(255,255,255,.1) 0 5px, transparent 6px);
  animation: rise 14s linear infinite;
}
@keyframes rise { from { background-position: 0 0; } to { background-position: 0 -100vh; } }

.screen {
  display: none;
  position: relative; z-index: 1;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  min-height: 100dvh;
}
.screen.active { display: flex; flex-direction: column; }

/* ---------- JOIN ---------- */
#screen-join { justify-content: center; gap: 14px; text-align: center; }
.logo {
  font-size: clamp(44px, 14vw, 72px); line-height: .9; margin: 0;
  font-weight: 800; letter-spacing: -1px;
  text-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.logo span { color: var(--sun); }
.tagline { margin: 0; opacity: .9; font-size: 18px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px; text-align: left;
  backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.18);
}
label { font-weight: 700; font-size: 15px; display: flex; flex-direction: column; gap: 4px; }
input {
  font: inherit; font-size: 20px; padding: 10px 14px; border-radius: 12px;
  border: 2px solid transparent; background: var(--foam); color: var(--ink); width: 100%;
}
input:focus { outline: none; border-color: var(--sun); }
#join-code { text-transform: uppercase; letter-spacing: 8px; font-weight: 800; font-size: 30px; text-align: center; }
.hint { opacity: .7; font-size: 14px; }
.error { color: #ffd0d0; min-height: 1.2em; margin: 0; font-weight: 700; }

.btn {
  font: inherit; font-weight: 800; border: 0; border-radius: 14px; cursor: pointer;
  padding: 12px 18px; font-size: 18px; color: var(--ink);
  background: var(--foam); box-shadow: 0 4px 0 rgba(0,0,0,.25);
  transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--sun); }
.btn.big { font-size: 22px; padding: 14px; }
.btn.feed { background: var(--coral); color: #fff; margin-top: 10px; }

/* ---------- DRAW ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; font-size: 16px; margin-bottom: 8px; }
.who { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; }
.room b { letter-spacing: 3px; color: var(--sun); }

.kinds { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.styles { display: flex; gap: 6px; margin: -2px 0 8px; }
.styles[hidden] { display: flex; visibility: hidden; } /* keep its space so the canvas doesn't jump */
.style-chip {
  flex: 1; font: inherit; font-weight: 700; font-size: 13px; padding: 5px 6px; border-radius: 999px;
  border: 2px solid rgba(255,255,255,.25); background: transparent; color: var(--foam);
}
.style-chip.active { background: rgba(255,255,255,.9); color: var(--ink); border-color: transparent; }
.kind {
  font: inherit; font-weight: 800; font-size: 15px; padding: 8px 2px; border-radius: 12px;
  border: 2px solid rgba(255,255,255,.25); background: transparent; color: var(--foam);
}
.kind.active { background: var(--foam); color: var(--ink); border-color: var(--foam); }

.canvas-wrap {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: var(--radius); overflow: hidden;
  background: #dfeff4;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  touch-action: none;
}
.stage {
  position: absolute; inset: 0; transform-origin: 0 0; will-change: transform;
  background:
    linear-gradient(rgba(6,36,58,.06) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(6,36,58,.06) 1px, transparent 1px) 0 0 / 32px 32px,
    #f6fdff;
}
#pad { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; z-index: 2; }
.guide { position: absolute; z-index: 1; display: none; color: rgba(6,36,58,.35); font-weight: 800; pointer-events: none; }
.canvas-wrap[data-kind="fish"]:not([data-style="up"]) .guide-fish { display: block; top: 8px; right: 12px; }
.canvas-wrap[data-kind="fish"][data-style="up"] .guide-jelly { display: block; top: 8px; right: 12px; }
.canvas-wrap[data-kind="plant"] .guide-plant,
.canvas-wrap[data-kind="critter"] .guide-critter,
.canvas-wrap[data-kind="structure"] .guide-structure {
  display: flex; left: 0; right: 0; bottom: 0; height: 12%;
  background: repeating-linear-gradient(-45deg, rgba(243,217,164,.7) 0 8px, rgba(243,217,164,.45) 8px 16px);
  border-top: 2px dashed rgba(6,36,58,.25);
  align-items: center; justify-content: center;
}

.tools { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch.wheel {
  position: relative;
  background: conic-gradient(#ff6b6b, #ffd93d, #6bcb77, #2ec4b6, #4d96ff, #c77dff, #f15bb5, #ff6b6b);
}
.swatch.wheel::after {
  content: ''; position: absolute; inset: 26%; border-radius: 50%;
  background: var(--custom, #fff); border: 2px solid #fff;
}
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid rgba(255,255,255,.35); padding: 0;
}
.swatch.active { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 2px var(--ink); }
.toolrow { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 5px; align-items: stretch; }
.tool {
  font: inherit; font-weight: 700; font-size: 11px; line-height: 1; width: 100%; height: 52px;
  border-radius: 12px; border: 0; padding: 4px 0 3px;
  background: rgba(255,255,255,.15); color: var(--foam);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
}
.tool .ico { font-size: 21px; line-height: 1; height: 24px; display: grid; place-items: center; }
.tool .ico canvas { width: 24px; height: 24px; }
.tool.active { background: var(--foam); color: var(--ink); }
.tool.toggle.active { background: var(--sun); color: var(--ink); }
.tool:disabled { opacity: .35; }
.size-slider {
  grid-column: span 4; display: flex; flex-direction: row; align-items: center; gap: 8px; height: 52px;
  background: rgba(255,255,255,.1); border-radius: 12px; padding: 0 10px; font-size: 0;
}
.size-preview { flex: none; width: 32px; height: 32px; display: grid; place-items: center; }
.size-preview i { display: block; border-radius: 50%; background: var(--foam); }
.size-slider input { flex: 1; min-width: 0; padding: 0; accent-color: var(--sun); background: transparent; height: 32px; }
#eyes { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; }
.csize { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.csize span { font-weight: 800; font-size: 14px; opacity: .8; margin-right: 2px; }
.csize-chip {
  flex: 1; font: inherit; font-weight: 800; font-size: 14px; padding: 6px 4px; border-radius: 999px;
  border: 2px solid rgba(255,255,255,.25); background: transparent; color: var(--foam);
}
.csize-chip.active { background: var(--foam); color: var(--ink); border-color: var(--foam); }
#ink { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }

/* ---------- QR scanner (#27) ---------- */
.scan-btn { font-size: 16px; padding: 10px; }
.scanner {
  position: fixed; inset: 0; z-index: 40; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 14px;
  padding: 24px 16px max(24px, env(safe-area-inset-bottom));
}
.scanner[hidden] { display: none; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame {
  position: absolute; top: 50%; left: 50%; width: min(70vw, 70vh); aspect-ratio: 1; transform: translate(-50%, -55%);
  border: 4px solid var(--sun); border-radius: 24px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45);
}
.scan-hint { position: relative; margin: 0; font-weight: 800; text-align: center; text-shadow: 0 2px 6px #000; }
.scanner .btn { position: relative; }
.size {
  width: 100%; height: 52px; padding: 0; border: 0; border-radius: 10px; background: rgba(255,255,255,.1);
  display: grid; place-items: center;
}
.size i { display: block; border-radius: 50%; background: var(--foam); }
.size.active { background: rgba(255,255,255,.35); }

.sendrow { display: flex; gap: 8px; margin-top: 10px; }
.sendrow input { font-size: 17px; flex: 1; min-width: 0; }
.sendrow .btn { white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 180%); opacity: 0;
  background: var(--foam); color: var(--ink); font-weight: 800; padding: 10px 18px; border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); transition: transform .25s, opacity .25s; z-index: 10; max-width: 90vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: #ffd0d0; }

.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9; text-align: center;
  background: var(--coral); color: #fff; font-weight: 800; padding: 6px; display: none;
}
.banner.show { display: block; }

@media (min-height: 860px) and (max-width: 699px) { .canvas-wrap { max-width: 520px; margin: 0 auto; } }

/* ---------- zoom ---------- */
#pad { z-index: 2; }
.zoombar {
  position: absolute; top: 8px; left: 8px; z-index: 5; display: flex; gap: 4px; align-items: center;
}
.zoombar button {
  width: 34px; height: 34px; border-radius: 10px; border: 0; font-size: 20px; font-weight: 800;
  background: rgba(6,36,58,.55); color: #fff; display: grid; place-items: center; padding: 0;
}
.zoombar button[hidden] { display: none; }
#zoom-level { color: var(--ink); font-weight: 800; font-size: 14px; background: rgba(255,255,255,.7); border-radius: 8px; padding: 2px 6px; }
#zoom-level:empty { display: none; }
.pinch-hint { margin: 6px 0 0; text-align: center; font-size: 13px; opacity: .6; }
@media (hover: hover) and (pointer: fine) {
  .pinch-hint { font-size: 0; }
  .pinch-hint::after { content: 'Scroll over the drawing to zoom'; font-size: 13px; }
}

/* ---------- my creations (saves) ---------- */
.topbar { gap: 8px; }
.mine-btn {
  font: inherit; font-weight: 800; font-size: 14px; border: 0; border-radius: 999px; padding: 4px 12px;
  background: rgba(255,255,255,.15); color: var(--foam); margin-left: auto;
}
.code-card { background: rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.code-has[hidden], #code-none[hidden], #device-note[hidden], #mine-empty[hidden], .use-code[hidden] { display: none; }
.code-label { font-size: 13px; opacity: .7; }
.code-row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.save-code { font-size: clamp(17px, 5.5vw, 22px); letter-spacing: 1px; color: var(--sun); overflow-wrap: anywhere; min-width: 0; }
.btn.small { font-size: 14px; padding: 6px 12px; border-radius: 10px; }
.save-toggle { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; }
.save-toggle input { width: 20px; height: 20px; accent-color: var(--sun); }
.mine-grid .art-btn { cursor: default; gap: 4px; position: relative; min-width: 0; padding: 6px 6px 8px; }
.mine-grid img { width: 100%; max-width: 110px; aspect-ratio: 1; object-fit: contain; }
.mine-grid .art-btn > span {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Send / Edit share the row under the picture; favourite and delete sit on the picture's corners (#47). */
.mine-grid .acts { display: flex; gap: 4px; width: 100%; min-width: 0; }
.mine-grid .acts button {
  flex: 1 1 0; min-width: 0; font: inherit; font-weight: 800; font-size: 12px; border: 0; border-radius: 8px;
  padding: 6px 0; background: #dfeff4; color: var(--ink);
}
.mine-grid .acts .send { background: var(--sun); }
.mine-grid .corner {
  position: absolute; top: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0;
  font: inherit; font-weight: 800; font-size: 14px; line-height: 28px; text-align: center;
  background: rgba(223, 239, 244, .92); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.mine-grid .corner.fav { left: 4px; }
.mine-grid .corner.fav.on { background: var(--sun); }
.mine-grid .corner.del { right: 4px; }
.mine-files { display: flex; gap: 8px; flex-wrap: wrap; }
.mine-files .btn { flex: 1 1 auto; text-align: center; cursor: pointer; }
.mine-files [hidden] { display: none; }
.mine-grid .acts .dl { flex: 0 0 26px; }
.use-code summary { cursor: pointer; font-weight: 700; font-size: 14px; opacity: .85; }
.use-code-row { display: flex; gap: 8px; margin-top: 8px; }
.use-code-row input { font-size: 16px; text-transform: uppercase; }
.link-btn { background: none; border: 0; color: var(--foam); opacity: .6; text-decoration: underline; font: inherit; font-size: 13px; margin-top: 6px; padding: 0; }

/* ---------- install (PWA) ---------- */
.install { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.install[hidden], .install-ios[hidden], .install button[hidden] { display: none; }
.install-ios { margin: 0; font-size: 14px; opacity: .8; }

/* ---------- join: host button ---------- */
.host-cta { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 4px; }
.host-cta span { opacity: .75; font-size: 14px; }
.btn.ghost {
  background: transparent; color: var(--foam); border: 2px solid rgba(255,255,255,.45);
  box-shadow: none; text-decoration: none; font-size: 16px; padding: 8px 16px;
}

/* ---------- bottom sheets ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(2,14,24,.55); z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 50%; bottom: 0; z-index: 21; width: min(560px, 100%);
  max-height: 85dvh; overflow-y: auto;
  background: var(--deep); border-radius: 22px 22px 0 0; border: 1px solid rgba(255,255,255,.15);
  padding: 14px 16px max(18px, env(safe-area-inset-bottom));
  transform: translate(-50%, 105%); transition: transform .25s ease;
  display: flex; flex-direction: column; gap: 10px;
}
.sheet.open { transform: translate(-50%, 0); }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-size: 22px; }
.sheet .close {
  width: 38px; height: 38px; border-radius: 50%; border: 0; font-size: 18px;
  background: rgba(255,255,255,.15); color: var(--foam);
}
.sheet-hint { margin: 0; opacity: .7; font-size: 14px; }
.art-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.art-btn {
  font: inherit; font-weight: 700; font-size: 13px; color: var(--ink);
  background: #f6fdff; border: 0; border-radius: 14px; padding: 6px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.art-btn canvas { width: 100%; max-width: 96px; aspect-ratio: 1; }
.wheel-row { display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; }
#wheel { width: 220px; height: 220px; touch-action: none; border-radius: 50%; }
.wheel-side { display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 140px; }
.wheel-preview { width: 72px; height: 72px; border-radius: 50%; border: 3px solid #fff; }
.wheel-hex { font-weight: 800; letter-spacing: 1px; }
.wheel-value { font-size: 14px; width: 100%; }
.wheel-value input { padding: 0; accent-color: var(--sun); }

/* ---------- tablets & desktops (#3) ---------- */
@media (min-width: 700px) and (max-aspect-ratio: 4/5) {
  .screen { max-width: 720px; }
  .tool { height: 60px; font-size: 13px; }
  .tool .ico { font-size: 26px; }
}
/* Side-by-side whenever the screen is roughly square or wider: landscape tablets, laptops,
   and unfolded foldables like the Pixel Fold (#31). */
@media (min-width: 740px) and (min-aspect-ratio: 4/5) {
  #screen-draw.active {
    max-width: 1400px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(300px, 38vw, 400px);
    grid-template-rows: auto auto auto auto auto auto 1fr;
    grid-template-areas:
      "top    top"
      "canvas kinds"
      "canvas styles"
      "canvas tools"
      "canvas csize"
      "canvas send"
      "canvas feed";
    column-gap: 24px;
    align-content: start;
  }
  .topbar { grid-area: top; }
  .kinds { grid-area: kinds; }
  .styles { grid-area: styles; }
  .tools { grid-area: tools; margin-top: 0; }
  .sendrow { grid-area: send; }
  .csize { grid-area: csize; }
  #feed { grid-area: feed; align-self: start; }
  .canvas-col { grid-area: canvas; display: flex; flex-direction: column; align-items: center; }
  .canvas-wrap { width: min(100%, calc(100dvh - 110px)); max-width: none; margin: 0; }
  .palette { grid-template-columns: repeat(8, 1fr); }
}
