:root {
  --green-900: #1f4720;
  --green-700: #2f6b2f;
  --green-500: #4fa43a;
  --green-300: #9ccc6b;
  --sky: #c4e8fa;
  --bark: #745a48;
  --sun: #ffcc33;
  --orange: #ff8a1f;
  --cream: #fffbea;
  --ink: #233023;
  --radius: 22px;
  --font: "Baloo 2", "Trebuchet MS", "Segoe UI Rounded", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink);
  user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; background: var(--green-700); }
button { font-family: inherit; cursor: pointer; border: 0; touch-action: manipulation; }
input { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: none; opacity: 0; transition: opacity .35s ease; }
.screen.active { display: block; opacity: 1; }
.screen.enter { animation: screenIn .45s cubic-bezier(.2,1.3,.4,1) both; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

#scr-start, #scr-pick, #scr-send {
  background: url("img/bg-tab.png") center / cover no-repeat, var(--green-500);
}

/* ---------- start ---------- */
.start-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.2vmin; padding: 4vmin; text-align: center; }
.logo { width: min(62vw, 640px); max-height: 30vh; object-fit: contain;
  filter: drop-shadow(0 6px 0 rgba(31,71,32,.55)) drop-shadow(0 10px 24px rgba(0,0,0,.35)); animation: logoFloat 4s ease-in-out infinite; }
@keyframes logoFloat { 50% { transform: translateY(-1.4vmin) rotate(-1deg); } }
.title { margin: 1vmin 0 0; font-size: clamp(30px, 6vmin, 72px); color: #fff; line-height: 1;
  -webkit-text-stroke: 2px var(--green-900); text-shadow: 0 5px 0 var(--green-900), 0 10px 20px rgba(0,0,0,.35); }
.subtitle { margin: 0 0 2vmin; font-size: clamp(16px, 2.6vmin, 28px); color: #fff; font-weight: 700;
  background: rgba(31,71,32,.75); padding: .4em 1.1em; border-radius: 999px; }
.btn-start { font-size: clamp(28px, 6vmin, 64px); font-weight: 900; letter-spacing: .05em; color: #fff;
  padding: .35em 1.6em; border-radius: 999px; background: linear-gradient(#ffb43d, var(--orange));
  box-shadow: 0 .14em 0 #b85500, 0 .3em .5em rgba(0,0,0,.3), inset 0 .08em 0 rgba(255,255,255,.6);
  text-shadow: 0 3px 0 #b85500; animation: pulse 1.6s ease-in-out infinite; transition: transform .1s; }
.btn-start:active { transform: translateY(.1em) scale(.97); box-shadow: 0 .04em 0 #b85500; }
.btn-start.small { font-size: clamp(20px, 3.6vmin, 36px); animation: none; }
@keyframes pulse { 50% { transform: scale(1.07); } }
.floaties span { position: absolute; font-size: 6vmin; animation: floaty 9s linear infinite; opacity: .9; pointer-events: none; }
.floaties span:nth-child(1) { left: 8%;  top: 70%; animation-delay: 0s; }
.floaties span:nth-child(2) { left: 85%; top: 25%; animation-delay: -2s; animation-duration: 11s; }
.floaties span:nth-child(3) { left: 20%; top: 15%; animation-delay: -4s; }
.floaties span:nth-child(4) { left: 78%; top: 78%; animation-delay: -1s; animation-duration: 7s; }
.floaties span:nth-child(5) { left: 50%; top: 8%;  animation-delay: -6s; }
.floaties span:nth-child(6) { left: 35%; top: 82%; animation-delay: -3s; animation-duration: 8s; }
@keyframes floaty { 0%,100% { transform: translate(0,0) rotate(0); } 25% { transform: translate(3vmin,-4vmin) rotate(15deg); }
  50% { transform: translate(-2vmin,-7vmin) rotate(-10deg); } 75% { transform: translate(-4vmin,-2vmin) rotate(8deg); } }

/* ---------- floating gear / back ---------- */
.gear, .back { position: absolute; top: max(14px, env(safe-area-inset-top)); z-index: 5; width: 64px; height: 64px; border-radius: 50%;
  font-size: 32px; background: rgba(255,255,255,.88); box-shadow: 0 4px 0 rgba(0,0,0,.2); transition: transform .3s; }
.gear { right: 14px; } .back { left: 14px; font-weight: 900; color: var(--green-700); }
.gear:active { transform: rotate(90deg); }

/* ---------- pick ---------- */
#scr-pick { display: none; flex-direction: column; align-items: center; justify-content: center; padding: 90px 3vw 3vh; }
#scr-pick.active { display: flex; }
.pick-title { margin: 0 0 2vmin; font-size: clamp(24px, 4.4vmin, 52px); color: #fff; text-align: center;
  -webkit-text-stroke: 1.5px var(--green-900); text-shadow: 0 4px 0 var(--green-900); }
/* flex-wrap + centre so a short last row sits in the middle, not on the left */
.animal-grid { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 1.6vmin; width: min(100%, 1250px); }
.animal-card { flex: 0 0 clamp(104px, 13vw, 160px); background: var(--cream); border-radius: var(--radius); padding: 1.4vmin .5vmin 1vmin; display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 6px 0 var(--green-900), 0 10px 18px rgba(0,0,0,.2); transition: transform .15s; animation: cardIn .5s both cubic-bezier(.2,1.4,.4,1); }
.animal-card:active { transform: translateY(4px) scale(.96); box-shadow: 0 2px 0 var(--green-900); }
.animal-card .emo { font-size: clamp(40px, 7vmin, 78px); line-height: 1.1; }
.animal-card .nm { font-weight: 800; font-size: clamp(15px, 2.2vmin, 24px); color: var(--green-900); }
.animal-card .mv { font-size: clamp(11px, 1.5vmin, 15px); color: #6b7b5f; font-weight: 600; }
.animal-card.random { background: linear-gradient(135deg, #fff3b0, #ffd0f0, #c8f0ff); }
@keyframes cardIn { from { opacity: 0; transform: translateY(30px) scale(.8); } }
.name-row { margin-top: 2.4vmin; display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.9); padding: 10px 18px; border-radius: 999px; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.name-row label { font-weight: 700; color: var(--green-900); }
.name-row input { font-size: 22px; padding: 6px 14px; border-radius: 999px; border: 3px solid var(--green-300); outline: none; width: 220px; }
.name-row input:focus { border-color: var(--orange); }

/* ---------- draw ---------- */
#scr-draw { background: #e9f4d9 radial-gradient(circle at 20% 10%, #f6fbe9, #d9ecc0); }
#scr-draw.active { display: flex; flex-direction: column; }
.topbar { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--green-700); box-shadow: 0 4px 0 var(--green-900); z-index: 2; }
.topbar .back { position: static; width: 54px; height: 54px; font-size: 28px; }
.draw-label { flex: 1; color: #fff; font-weight: 800; font-size: clamp(18px, 3vmin, 30px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facing { display: flex; align-items: center; gap: 6px; color: #fff; font-weight: 700; }
.face-btn { width: 50px; height: 50px; border-radius: 14px; font-size: 24px; background: rgba(255,255,255,.25); }
.face-btn.active { background: #fff; box-shadow: 0 0 0 3px var(--sun); }
.gear-inline { width: 54px; height: 54px; border-radius: 50%; font-size: 28px; background: rgba(255,255,255,.88); }
.btn-done { font-size: clamp(18px, 2.8vmin, 28px); font-weight: 900; color: #fff; padding: 10px 26px; border-radius: 999px;
  background: linear-gradient(#ffb43d, var(--orange)); box-shadow: 0 5px 0 #b85500; text-shadow: 0 2px 0 #b85500; }
.btn-done:active { transform: translateY(4px); box-shadow: 0 1px 0 #b85500; }
.btn-done.wiggle { animation: wiggle .6s ease; }
@keyframes wiggle { 20%,60% { transform: rotate(-6deg) scale(1.08); } 40%,80% { transform: rotate(6deg) scale(1.08); } }

.workspace { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 12px; }
.tools { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding: 4px; }
.tool { width: 74px; min-height: 70px; border-radius: 18px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 #b7cfa0; transition: transform .15s, background .15s; padding: 4px 2px; }
.tool .ico { font-size: 32px; line-height: 1; }
.tool .lbl { font-size: 12px; font-weight: 800; color: var(--green-900); margin-top: 2px; }
.tool.active { background: var(--sun); box-shadow: 0 4px 0 #c08f00; transform: translateX(6px) scale(1.06); }

.paper-wrap { flex: 1; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
.paper { position: relative; background: #fff; border-radius: 18px; box-shadow: 0 0 0 6px #fff, 0 0 0 10px var(--green-300), 0 14px 30px rgba(0,0,0,.18); overflow: hidden;
  background-image: radial-gradient(#e8efe0 1.2px, transparent 1.2px); background-size: 26px 26px; }
.paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#cv-stroke { pointer-events: none; }
.hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  font-size: clamp(20px, 3.4vmin, 36px); color: #b7c7a8; font-weight: 800; pointer-events: none; transition: opacity .4s; }
.hint small { font-size: .55em; font-weight: 600; }
.hint.gone { opacity: 0; }

.side { flex: 0 0 auto; width: 200px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; padding: 4px; }
.colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.swatch { aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), 0 2px 0 rgba(0,0,0,.15); transition: transform .15s; }
.swatch.active { transform: scale(1.18); box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--ink); }
.swatch.rainbow { background: conic-gradient(red, orange, yellow, lime, cyan, blue, magenta, red); }
.custom-color { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #fff; border-radius: 16px; padding: 6px 10px; font-weight: 800; color: var(--green-900); box-shadow: 0 3px 0 #b7cfa0; }
.custom-color input { width: 48px; height: 40px; border: 0; padding: 0; background: none; }
.size-box { background: #fff; border-radius: 16px; padding: 10px; box-shadow: 0 3px 0 #b7cfa0; }
.size-preview { height: 84px; display: flex; align-items: center; justify-content: center; }
#size-dot { display: block; border-radius: 50%; background: #333; transition: width .1s, height .1s; }
.size-box input { width: 100%; accent-color: var(--orange); height: 36px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions button { height: 62px; border-radius: 16px; background: #fff; font-size: 30px; font-weight: 900; color: var(--green-900); box-shadow: 0 4px 0 #b7cfa0; }
.actions button:active, .tool:active, .swatch:active { transform: translateY(3px); }
.actions button:disabled { opacity: .35; }

/* portrait: tools/colors move to bottom */
@media (orientation: portrait) {
  .workspace { flex-direction: column; }
  .tools { flex-direction: row; overflow-x: auto; order: 2; }
  .tool.active { transform: translateY(-6px) scale(1.06); }
  .side { width: auto; order: 3; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .colors { grid-template-columns: repeat(10, 40px); }
  .size-box { width: 220px; } .size-preview { height: 50px; }
  .actions { width: 220px; }
  .facing span { display: none; }
}

/* ---------- send ---------- */
.send-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 4vmin; gap: 1vmin; }
.send-stage { width: min(50vmin, 460px); height: min(50vmin, 460px); border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(255,255,255,.95) 40%, rgba(255,255,255,0) 70%); }
#send-preview { max-width: 80%; max-height: 80%; filter: drop-shadow(0 0 4px #fff) drop-shadow(0 8px 10px rgba(0,0,0,.25)); }
#scr-send.sending #send-preview { animation: sendBob .5s ease-in-out infinite alternate; }
#scr-send.flying #send-preview { animation: flyUp 1s cubic-bezier(.55,-0.35,.75,.25) forwards; }
#scr-send.flying .send-stage { background: radial-gradient(circle, rgba(255,255,255,.55) 20%, rgba(255,255,255,0) 70%); transition: background .6s; }
@keyframes sendBob { to { transform: translateY(-14px) scale(1.04, .96); } }
/* straight up to top-centre: squash, stretch, shrink into a spark */
@keyframes flyUp {
  0%   { transform: none; opacity: 1; }
  25%  { transform: translateY(4vh) scale(1.15, .85); }
  45%  { transform: translateY(-8vh) scale(.9, 1.15); filter: drop-shadow(0 0 10px #fff) drop-shadow(0 0 30px #fff6a0); }
  100% { transform: translateY(-75vh) scale(.08, .2); opacity: 0; filter: drop-shadow(0 0 20px #fff) drop-shadow(0 0 60px #ffe46a); }
}

/* magic glow in the centre after sending */
.glow { position: absolute; inset: 0; pointer-events: none; display: none; }
#scr-send.glowing .glow { display: block; }
#scr-send.glowing .send-stage { visibility: hidden; }
.glow-orb { position: absolute; left: 50%; top: 42%; width: 0; height: 0; animation: orbWander 3.2s ease-in-out infinite; }
.glow-orb::before, .glow-orb::after, .glow-core { content: ""; position: absolute; left: 50%; top: 50%; border-radius: 50%; transform: translate(-50%, -50%); }
.glow-orb::before { width: 62vmin; height: 62vmin; background: radial-gradient(circle, rgba(255,246,160,.55) 0%, rgba(255,214,74,.25) 35%, rgba(255,214,74,0) 68%); animation: orbPulse 1.6s ease-in-out infinite; }
.glow-orb::after  { width: 30vmin; height: 30vmin; background: radial-gradient(circle, rgba(255,255,255,.9) 0%, rgba(255,240,150,.6) 40%, rgba(255,240,150,0) 70%); animation: orbPulse 1.1s ease-in-out infinite reverse; }
.glow-core { width: 7vmin; height: 7vmin; background: #fff; box-shadow: 0 0 4vmin 2vmin #fff, 0 0 10vmin 5vmin #ffe46a; animation: coreIn .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes orbWander {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-9vmin, -4vmin); }
  40% { transform: translate(6vmin, -8vmin); }
  60% { transform: translate(10vmin, 2vmin); }
  80% { transform: translate(-5vmin, 5vmin); }
}
@keyframes orbPulse { 50% { transform: translate(-50%, -50%) scale(1.18); opacity: .8; } }
@keyframes coreIn { from { transform: translate(-50%, -50%) scale(0); } }
.glow-sparks { position: absolute; left: 50%; top: 42%; }
.glow-sparks i { position: absolute; width: 1.4vmin; height: 1.4vmin; margin: -.7vmin; border-radius: 50%; background: #fff; box-shadow: 0 0 1.5vmin .5vmin #ffe46a;
  opacity: 0; animation: spark ease-out infinite; }
@keyframes spark { 0% { transform: translate(0, 0) scale(.4); opacity: 0; } 20% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.2); opacity: 0; } }
#scr-send.glowing #send-title, #scr-send.glowing #send-sub { position: relative; top: 26vh; animation: cardIn .5s both cubic-bezier(.2,1.4,.4,1); }

/* confirm popup */
.confirm-card { width: min(560px, 100%); text-align: center; padding: 26px 28px 30px; }
.confirm-card h3 { font-size: clamp(26px, 4.4vmin, 40px); }
.confirm-preview { margin: 0 auto 10px; width: min(44vmin, 320px); height: min(32vmin, 230px); display: flex; align-items: center; justify-content: center;
  border-radius: 20px; background: #fff; box-shadow: inset 0 0 0 3px var(--green-300); }
.confirm-preview img { max-width: 88%; max-height: 88%; animation: sendBob .7s ease-in-out infinite alternate; }
.confirm-sub { margin: 0 0 18px; font-weight: 700; font-size: clamp(16px, 2.4vmin, 22px); color: var(--green-700); }
.confirm-btns { display: flex; gap: 16px; }
.confirm-btns button { flex: 1; font-size: clamp(20px, 3.4vmin, 32px); font-weight: 900; padding: .55em .8em; border-radius: 999px; color: #fff; }
.btn-cancel { background: #a3a89c; box-shadow: 0 6px 0 #6b7066; }
.btn-confirm { background: var(--orange); box-shadow: 0 6px 0 #b85500; animation: pulse 1.2s ease-in-out infinite; }
.confirm-btns button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.3); }
#send-title { margin: 0; color: #fff; font-size: clamp(26px, 5.4vmin, 60px); -webkit-text-stroke: 1.5px var(--green-900); text-shadow: 0 5px 0 var(--green-900); }
#send-sub { margin: 0; color: #fff; font-weight: 700; font-size: clamp(16px, 2.6vmin, 28px); background: rgba(31,71,32,.75); padding: .3em 1em; border-radius: 999px; }
.send-actions { display: flex; gap: 16px; margin-top: 2vmin; }
.btn-retry { font-size: clamp(18px, 3vmin, 30px); font-weight: 900; padding: .4em 1.2em; border-radius: 999px; color: #fff; background: #d9443b; box-shadow: 0 5px 0 #8c231d; }
.send-count { color: #fff; font-weight: 700; text-shadow: 0 2px 0 var(--green-900); min-height: 1.4em; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,35,15,.6); display: flex; align-items: center; justify-content: center; padding: 16px; backdrop-filter: blur(3px); }
.modal-card { width: min(640px, 100%); max-height: 100%; overflow-y: auto; background: var(--cream); border-radius: 26px; padding: 22px 26px; box-shadow: 0 10px 0 var(--green-900), 0 20px 40px rgba(0,0,0,.4); animation: cardIn .35s both cubic-bezier(.2,1.4,.4,1); user-select: text; }
.modal h3 { margin: 0 0 12px; font-size: 30px; color: var(--green-900); }
.row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.row.two { flex-direction: row; gap: 20px; align-items: center; flex-wrap: wrap; }
.row small { font-weight: 500; color: #5b6b52; }
.row input[type=text], .row input:not([type]), .row input[type=number] { font-size: 20px; padding: 10px 14px; border-radius: 14px; border: 3px solid var(--green-300); outline: none; width: 100%; }
.row input[type=number] { width: 90px; margin-left: 6px; }
.row input[type=checkbox] { width: 24px; height: 24px; vertical-align: middle; accent-color: var(--orange); }
.row-btns { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-btns button { font-size: 18px; font-weight: 800; padding: 10px 16px; border-radius: 14px; background: #fff; color: var(--green-900); box-shadow: 0 4px 0 #b7cfa0; }
.row-btns.big button { flex: 1; padding: 14px; }
.row-btns.end { justify-content: flex-end; margin-top: 16px; }
.row-btns .primary { background: var(--orange); color: #fff; box-shadow: 0 4px 0 #b85500; }
.row-btns .ghost { background: transparent; box-shadow: none; }
.status { font-weight: 700; }
.status.ok { color: #2a8a2a; } .status.bad { color: #c0392b; }

.toast { position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 150%); background: var(--ink); color: #fff; font-weight: 800; font-size: 22px;
  padding: 12px 26px; border-radius: 999px; z-index: 60; transition: transform .35s cubic-bezier(.2,1.4,.4,1); pointer-events: none; }
.toast.show { transform: translate(-50%, 0); }
