/* Doodle Alive accounts: the sketchbook's own desk. Sheets of paper taped to kraft, tomato-crayon buttons with an
   ink outline, the credit balance printed on the crayon box, and credit packs as Polaroids, the same picture
   that develops while a doodle comes to life. Colours, fonts, tape, buttons and fields are Doodle Alive's
   (3d-drawing-board public/style.css); keep them in step with it. Text colours pass WCAG AA: white on tomato
   only at 24px and up, and the darker leaf and tomato for small text. */

:root {
  --desk: #e8d4ae;
  --desk-dark: #c9ab7a;
  --paper: #fffdf6;
  --ink: #2a1f17;
  --soft: #6e5a46;
  --accent: #ff5a36;        /* tomato crayon */
  --accent-dark: #c63b1c;   /* small text and links: 5.1:1 on paper */
  --leaf: #2fa66a;
  --leaf-ink: #1f7a4c;      /* green small text: 5.2:1 on paper */
  --spark: #ffe066;
  --box: #ffd23f;           /* the crayon box */
  --tape: rgb(255 214 102 / 0.78);
  --tape-2: rgb(142 202 230 / 0.8);
  --rule: rgb(62 143 176 / 0.28);   /* a notebook's blue lines */
  --desk-red: #9e2a10;      /* small text straight on the desk: 5.2:1 */
  --desk-green: #155c38;    /* 5.5:1 on the desk */
  /* Gochi Hand and Andika have no Chinese: ZCOOL KuaiLe and the system's Chinese fonts take over for it */
  --hand: "Gochi Hand", "ZCOOL KuaiLe", "Comic Sans MS", cursive;
  --body: "Andika", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Trebuchet MS", sans-serif;
  --gutter: max(16px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.nw { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html { -webkit-text-size-adjust: 100%; }
html:lang(zh) { font-synthesis: none; }
body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font: 400 1.05rem/1.55 var(--body);
  -webkit-tap-highlight-color: transparent;
  background-color: var(--desk);
  /* Kraft-paper grain, as on the sketchbook's desk */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .24 0 0 0 0 .12 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  overflow-x: hidden;
}
h1, h2, h3 { font-family: var(--hand); font-weight: 400; line-height: 1.05; margin: 0; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--accent-dark); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 6px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 16px; z-index: 99; background: var(--ink); color: var(--paper); padding: 0.5rem 0.9rem; border-radius: 10px; }
/* The hand-drawn icons (each page's <svg> defs) */
.i { width: 26px; height: 26px; flex: none; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.i.spark { fill: var(--spark); stroke: var(--ink); stroke-width: 2; }

/* ---------- Header: the sketchbook's name, the account's tabs, the language sticker ---------- */
.top {
  position: relative;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1rem;
  width: 100%;
  max-width: calc(52rem + 2 * 16px);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter) 0;
}
.brand {
  flex: none;
  font: 400 2.1rem/1 var(--hand);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  transform: rotate(-1.5deg);
}
.brand span { color: var(--accent); }
.brand.small { font-size: 1.6rem; }
.nav { display: flex; gap: 0.4rem; margin-left: auto; }
.nav a {
  padding: 0.35rem 0.85rem 0.25rem;
  border: 2.5px solid transparent;
  border-radius: 12px;
  color: var(--ink);
  font: 400 1.3rem/1.1 var(--hand);
  text-decoration: none;
  white-space: nowrap;
}
.nav a:hover { background: rgb(255 253 246 / 0.55); }
.nav a[aria-current="page"] { background: var(--paper); border-color: var(--ink); box-shadow: 0 3px 0 var(--ink); transform: rotate(-2deg); }
/* English / 中文: a two-way sticker */
.lang-switch {
  flex: none;
  display: inline-flex;
  padding: 3px;
  border: 2.5px solid var(--ink);
  border-radius: 13px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--ink);
  transform: rotate(2deg);
}
.lang-switch button {
  min-width: 3rem;
  padding: 0.35rem 0.7rem 0.25rem;
  border: 0;
  border-radius: 9px;
  background: none;
  font: 400 1.15rem/1 var(--hand);
  cursor: pointer;
}
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
@media (max-width: 559px) {
  .nav { order: 3; width: 100%; margin: 0; justify-content: center; }
  .lang-switch { margin-left: auto; }
}

/* Sparks floating over the desk, as on the sketchbook's working screen */
.doodles { position: absolute; inset: 0 0 auto; height: 420px; pointer-events: none; overflow: hidden; }
.doodles .i { position: absolute; animation: float 4s ease-in-out infinite; }
.doodles .i:nth-child(1) { top: 92px; left: 7%; width: 34px; height: 34px; }
.doodles .i:nth-child(2) { top: 150px; right: 9%; width: 26px; height: 26px; animation-delay: -1.3s; }
.doodles .i:nth-child(3) { top: 300px; left: 12%; width: 20px; height: 20px; animation-delay: -2.6s; }
@keyframes float { 50% { transform: translateY(-12px) rotate(18deg) scale(1.1); } }
@media (max-width: 559px) { .doodles .i:nth-child(3) { display: none; } .doodles .i:nth-child(1) { top: 120px; left: 3%; } }

/* ---------- Page ---------- */
main { position: relative; flex: 1; width: 100%; max-width: calc(46rem + 2 * 16px); margin: 0 auto; padding: 2rem var(--gutter) 0; }
main.narrow { max-width: calc(26rem + 2 * 16px); }
.page-head { text-align: center; margin-bottom: 1.8rem; }
h1 { font-size: clamp(2.6rem, 9vw, 3.6rem); transform: rotate(-1.5deg); text-wrap: balance; }
h1 .mark { color: var(--accent); }
.lede { max-width: 30rem; margin: 0.7rem auto 0; color: #57442f; }   /* on the desk: 6:1, where --soft is only 4.5:1 */
/* A dashed tag, like the sketchbook's mode tag */
.tag {
  display: inline-block;
  margin-bottom: 0.8rem;
  padding: 0.3rem 0.75rem 0.15rem;
  border: 2px dashed var(--desk-green);
  border-radius: 8px;
  color: var(--desk-green);
  font: 400 1.15rem/1.1 var(--hand);
  transform: rotate(3deg);
}

/* A sheet of paper taped to the desk; the sign-in sheet has one strip of tape, the others two */
.sheet {
  position: relative;
  padding: clamp(1.4rem, 5vw, 2rem) clamp(1.1rem, 5vw, 1.8rem);
  border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 1px 0 rgb(0 0 0 / 0.08), 0 14px 28px -10px rgb(70 40 10 / 0.45);
}
.sheet::before, .sheet::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 92px;
  height: 26px;
  pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 7px, rgb(255 255 255 / 0.28) 7px 12px), var(--tape);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.12);
}
.sheet::before { left: 14px; transform: rotate(-7deg); }
.sheet::after { right: 14px; transform: rotate(6deg); background: repeating-linear-gradient(90deg, transparent 0 7px, rgb(255 255 255 / 0.3) 7px 12px), var(--tape-2); }
.sheet.gate { transform: rotate(-1deg); }
.sheet.gate::before { left: 50%; margin-left: -48px; width: 96px; transform: rotate(-4deg); }
.sheet.gate::after { display: none; }
.sheet + .sheet, .stack > .sheet + .sheet { margin-top: 1.8rem; }
.box + .stack { margin-top: 2.4rem; }
.sheet > h2 { font-size: 2rem; transform: rotate(-1deg); }
.sheet-lede { margin-top: 0.3rem; color: var(--soft); }
@media (min-width: 640px) {
  .stack > .sheet:nth-child(odd) { transform: rotate(-0.5deg); }
  .stack > .sheet:nth-child(even) { transform: rotate(0.4deg); }
}
.alt { margin-top: 1.4rem; text-align: center; }
.alt a { color: var(--desk-red); }

/* Things arrive the way the sketchbook's Polaroid does: dropped onto the desk, one after another */
.arrive { animation: drop 0.55s cubic-bezier(.3, 1.4, .5, 1) both; animation-delay: calc(var(--n, 0) * 90ms); }
@keyframes drop { from { opacity: 0; translate: 0 -24px; rotate: 4deg; } }
/* While a page asks who's signed in: nothing jumps about */
.loading main > :not(.page-head) { visibility: hidden; animation-play-state: paused; }
/* The top-up page's heading waits too, so "Top up credits" never flashes before "coming soon" */
.loading #headOn, .loading #ledeOn { visibility: hidden; }

/* ---------- Buttons (the sketchbook's) ---------- */
.big {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  padding: 0.35rem 1.4rem 0.2rem;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font: 400 1.6rem/1 var(--hand);   /* 24px+: white on tomato passes for large text */
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.08s, box-shadow 0.08s;
}
.big .i { width: 28px; height: 28px; }
.big:hover { transform: translateY(-1px) rotate(-0.4deg); box-shadow: 0 6px 0 var(--ink); }
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.big[disabled] { opacity: 0.55; cursor: wait; }
.big.wide { width: 100%; }
.big.ghost { background: var(--paper); color: var(--ink); font-size: 1.4rem; min-height: 50px; }
.big.ghost .i { stroke: var(--ink); }
.link { padding: 0; border: 0; background: none; color: var(--accent-dark); font: inherit; text-decoration: underline; cursor: pointer; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.9rem 1.2rem; margin-top: 1.2rem; }

/* ---------- Fields: a sentence to finish, on a dashed line ---------- */
form { display: grid; gap: 1.2rem; margin-top: 1.2rem; }
.field { display: grid; gap: 0.1rem; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span { font: 400 1.35rem/1.2 var(--hand); }
.field small { font: 400 0.85rem var(--body); color: var(--soft); }
.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.2rem;
  border: 0;
  border-bottom: 2px dashed var(--soft);
  border-radius: 0;
  background: transparent;
  font: 400 1.1rem/1.3 var(--body);
}
.field select { cursor: pointer; }
.field input:focus, .field select:focus { outline: none; border-bottom: 2px solid var(--accent); }
.field input::placeholder { color: rgb(110 90 70 / 0.6); }
.field input[readonly] { color: var(--soft); border-bottom-style: dotted; }
.code-input { text-align: center; font: 400 2.4rem/1.1 var(--hand) !important; letter-spacing: 0.35em; padding-left: 0.6em !important; }
.check { display: flex; align-items: flex-start; gap: 0.6rem; font-size: 0.95rem; color: var(--soft); }
.check input { flex: none; width: 1.3rem; height: 1.3rem; margin-top: 0.15rem; accent-color: var(--accent); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.grid-2 { display: grid; gap: 1.2rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
/* What a form or page has to say: tomato for trouble (it shakes), green for good news */
.form-msg { min-height: 1.4em; color: var(--accent-dark); font-weight: 700; text-align: center; }
.form-msg:empty { min-height: 0; }
.form-msg.ok { color: var(--leaf-ink); }
/* Messages straight on the desk (the top-up page's, signing out's), and the link beside them */
.form-msg.left { text-align: left; }
/* Messages straight on the desk (the top-up page's) */
main > .form-msg { color: var(--desk-red); }
main > .form-msg.ok { color: var(--desk-green); }
.shake { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.sent-to { color: var(--soft); text-align: center; }
.sent-to b { color: var(--ink); word-break: break-all; }
.code-help { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.4rem; font-size: 0.95rem; }
/* A note pinned on the desk: a dashed card */
.note {
  margin: 0 auto 1.6rem;
  max-width: 34rem;
  padding: 0.7rem 1rem;
  border: 2px dashed var(--desk-dark);
  border-radius: 10px;
  background: rgb(255 253 246 / 0.94);
  text-align: center;
  font-weight: 700;
}
.note.ok { border-color: var(--leaf); color: var(--leaf-ink); }

/* ---------- My account: the balance on the crayon box ---------- */
.box { position: relative; padding-top: 44px; }
/* The crayons standing in the box, behind its printed front */
.box-crayons { position: absolute; left: 22px; right: 22px; top: 0; height: 64px; display: flex; justify-content: flex-end; gap: 8px; }
.box-crayons i {
  width: 26px;
  height: 64px;
  background: var(--c);
  clip-path: polygon(32% 0, 68% 0, 100% 24%, 100% 100%, 0 100%, 0 24%);
  border-radius: 0 0 4px 4px;
  transform: translateY(var(--y, 8px));
  animation: rise 0.6s cubic-bezier(.3, 1.6, .5, 1) both;
  animation-delay: calc(0.2s + var(--n) * 60ms);
}
@keyframes rise { from { transform: translateY(60px); } }
.box-front {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.4rem;
  padding: 1.3rem 1.4rem 2rem;
  border: 3px solid var(--ink);
  border-radius: 6px 6px 22px 22px;
  box-shadow: 0 6px 0 var(--ink);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='12'%3E%3Cpath d='M0 12V6q6.5-7 13 0t13 0v6z' fill='%23ff5a36'/%3E%3C/svg%3E") left bottom / 26px 12px repeat-x, var(--box);
}
.box-front::before {   /* its lip, where the crayons go in */
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 8px;
  background: rgb(42 31 23 / 0.1);
  border-bottom: 2px dashed rgb(42 31 23 / 0.3);
}
.box-label { font: 400 1.6rem/1 var(--hand); transform: rotate(-3deg); text-shadow: 2px 2px 0 #fff; }
.balance { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.3rem; font: 400 1.4rem/1 var(--hand); }
.balance b { font: 400 clamp(3.8rem, 14vw, 5rem)/0.9 var(--hand); text-shadow: 3px 3px 0 #fff; }
.balance .i { width: 44px; height: 44px; animation: twinkle 2.6s ease-in-out infinite; }
@keyframes twinkle { 0%, 70%, 100% { transform: none; } 80% { transform: scale(1.3) rotate(20deg); } 90% { transform: scale(0.92) rotate(-6deg); } }
.box-text { flex-basis: 100%; order: 3; margin-top: -0.4rem; font-weight: 700; }
.box .note { margin: 1.4rem 0 0; }

/* The history, on lined notebook paper */
.history { list-style: none; padding: 0; margin: 0.8rem 0 0; }
.history li { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 0.2rem; border-bottom: 1.5px solid var(--rule); }
.history li:first-child { border-top: 1.5px solid var(--rule); }
.history .mark-icon { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border: 2.5px solid var(--ink); border-radius: 50% 45% 50% 48%; background: var(--paper); }
.history .mark-icon .i { width: 20px; height: 20px; }
.history .up .mark-icon { background: #e3f4ea; }
.history .what { flex: 1; min-width: 0; font: 400 1.3rem/1.15 var(--hand); }
.history .what small { display: block; font: 400 0.85rem/1.4 var(--body); color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .change { flex: none; font: 400 1.6rem/1 var(--hand); }
.history .up .change { color: var(--leaf-ink); }
.empty { margin-top: 0.8rem; color: var(--soft); font-style: italic; }

/* Settings: its parts (devices, deleting) under dashed rules, like sections of a notebook page */
.part { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 2px dashed rgb(201 171 122 / 0.75); }
.part > h3 { font-size: 1.5rem; }
.part .row { margin-top: 0.8rem; }
.danger summary { display: inline-block; cursor: pointer; color: var(--accent-dark); text-decoration: underline; list-style: none; }
.danger summary::-webkit-details-marker { display: none; }
.danger p { margin-top: 0.7rem; color: var(--soft); }
.big.danger-btn { background: var(--ink); font-size: 1.5rem; }

/* ---------- Top up: each pack a Polaroid ---------- */
.packs { display: grid; gap: 2.2rem 1.6rem; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); margin-top: 0.4rem; }
.pack { display: flex; flex-direction: column; gap: 1.1rem; align-items: stretch; }
.polaroid {
  position: relative;
  margin: 0;
  padding: 12px 12px 0;
  background: #fff;
  box-shadow: 0 2px 0 rgb(0 0 0 / 0.06), 0 22px 40px -14px rgb(60 35 10 / 0.55);
  transform: rotate(var(--tilt, -2deg));
}
.pack:nth-child(3n + 2) .polaroid { --tilt: 1.5deg; }
.pack:nth-child(3n + 3) .polaroid { --tilt: -1deg; }
.snap {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: var(--shot, #fbe8b0);
  overflow: hidden;
}
.pack:nth-child(3n + 2) .snap { --shot: #d4ebf5; }
.pack:nth-child(3n + 3) .snap { --shot: #ffd9cd; }
.snap .count { display: flex; align-items: center; gap: 0.3rem; font: 400 4rem/1 var(--hand); }
.snap .i { width: 48px; height: 48px; animation: twinkle 2.6s ease-in-out infinite; }
.pack:nth-child(2) .snap .i { animation-delay: 0.4s; }
.pack:nth-child(3) .snap .i { animation-delay: 0.8s; }
.polaroid figcaption { padding: 0.8rem 0.4rem 0.9rem; text-align: center; }
/* Phones: a wide, short picture, so the packs aren't a screen each */
@media (max-width: 559px) {
  .snap { aspect-ratio: 5 / 2; }
  .snap .count { font-size: 3.2rem; }
  .polaroid figcaption { padding: 0.6rem 0.4rem 0.7rem; }
}
.polaroid .price { display: block; font: 400 2rem/1 var(--hand); }
.polaroid .per { display: block; margin-top: 0.35rem; color: var(--soft); font-size: 0.92rem; }
/* "Save 13%" on a strip of tape across the corner */
.save {
  position: absolute;
  z-index: 1;
  top: -12px;
  right: -14px;
  padding: 0.3rem 0.8rem 0.15rem;
  background: repeating-linear-gradient(90deg, transparent 0 7px, rgb(255 255 255 / 0.3) 7px 12px), var(--tape);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
  font: 400 1.2rem/1.1 var(--hand);
  transform: rotate(8deg);
}
.how { list-style: none; padding: 0; margin: 0.9rem 0 0; display: grid; gap: 0.65rem; }
.how li { display: flex; gap: 0.7rem; align-items: flex-start; }
.how .i { width: 22px; height: 22px; margin-top: 0.15rem; }
.fine { margin-top: 1.1rem; font-size: 0.92rem; color: var(--soft); }

/* ---------- Footer, on the desk ---------- */
.foot { margin-top: clamp(3rem, 9vw, 5rem); padding: 2rem var(--gutter) calc(2rem + env(safe-area-inset-bottom)); text-align: center; border-top: 2px dashed var(--desk-dark); }
.foot p { margin-top: 0.4rem; font-size: 0.95rem; }
.foot a { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
