/* ---------- Write it!: Ink Pop ----------
   Home's Ink Splash look in Write it!'s violet: 田字格 paper, chunky ink-outlined cards with hard shadows.
   The practice screen (games/write.js) is three columns on an iPad held sideways: the word card and Pao Pao on
   the left, the word's characters and one big 米字格 box in the middle, Today's words with their dots on the
   right. Held upright, Today's words run along the top and the box goes under the word card.
   A right stroke pops a few ink drops, a finished character gets a red seal, and Pao Pao coaches.
   The new characters' stories have their own styles (css/charstory.css). Everything is scoped to #write so
   the other games' .box and .big-btn stay as they were. */
#write {
  --ink: #1d2233;
  --violet: #7a5cff; --violet-deep: #5134d0; --violet-soft: #efe9ff; --violet-ring: #e3dbff;
  --pink: #ff3d7f; --yellow: #ffc22e; --cyan: #19b6d6; --green: #2ec27e; --green-deep: #1f7a4c; --coral: #ff7a59;
  --seal: #e0362c;
  --paper: #fdfbf7;
  --f-display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  --f-body: "Nunito", -apple-system, "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --f-kai: "Kaiti SC", "STKaiti", "KaiTi", "PingFang SC", serif;
  position: relative; isolation: isolate;
  font-family: var(--f-body); font-weight: 800; color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 88% 8%, rgba(122, 92, 255, .10), transparent 32%),
    radial-gradient(circle at 6% 96%, rgba(255, 61, 127, .07), transparent 30%),
    linear-gradient(rgba(220, 70, 70, .10) 2px, transparent 2px), linear-gradient(90deg, rgba(220, 70, 70, .10) 2px, transparent 2px),
    linear-gradient(rgba(220, 70, 70, .06) 1px, transparent 1px), linear-gradient(90deg, rgba(220, 70, 70, .06) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 120px 120px, 120px 120px, 60px 60px, 60px 60px;
  background-position: 0 0, 0 0, -2px -2px, -2px -2px, -2px -2px, -2px -2px;
}
#write.watering { --violet: #3d9cf0; --violet-deep: #1c64a8; --violet-soft: #e6f4ff; --violet-ring: #cfe8ff; }
#write .w-zh { font-family: var(--f-kai); font-weight: 400; }
#write [hidden] { display: none !important; }

/* ---- top bar ---- */
#write .game-head { gap: 14px; padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
#write .icon-btn {
  width: 56px; height: 56px; border-radius: 50%; font-size: 26px; display: grid; place-items: center; padding: 0; flex: none; color: var(--ink);
  background: #fff; border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
}
#write .icon-btn .ic { width: 28px; height: 28px; }
#write .icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-head-gap { flex: 1; }
#write .w-can { display: flex; align-items: center; gap: 6px; }
#write .w-can .can-svg { width: 74px; height: auto; }
#write .w-can b {
  font-family: var(--f-display); font-weight: 400; font-size: 22px; font-variant-numeric: tabular-nums; white-space: nowrap;
  background: var(--yellow); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); border-radius: 999px; padding: 6px 16px;
}

/* ---- buttons ---- */
#write .w-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 60px; padding: 0 26px;
  font-family: var(--f-display); font-weight: 400; font-size: 24px; color: var(--ink); background: #fff;
  border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); cursor: pointer;
  transition: transform .08s, box-shadow .08s; -webkit-tap-highlight-color: transparent;
}
#write .w-btn svg { width: 26px; height: 26px; flex: none; }
#write .w-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#write .w-btn:disabled { opacity: .45; }
#write .w-btn.primary { background: var(--violet); color: #fff; }
#write .w-btn.primary svg { color: #fff; }
#write .w-dict { min-height: 52px; padding: 0 20px; font-size: 21px; }
#write .w-mini { min-height: 44px; padding: 0 12px 0 10px; font-size: 17px; gap: 6px; border-width: 2.5px; box-shadow: 0 3px 0 var(--ink); border-radius: 14px; }
#write .w-mini svg { width: 18px; height: 18px; color: var(--violet); }

/* ---- the practice screen: word card | the box | Today's words ---- */
#write .w-main {
  flex: 1; min-height: 0; display: grid; grid-template-columns: 262px minmax(0, 1fr) 246px; gap: 24px; align-items: start;
  padding: 10px max(28px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
}
#write .w-side { display: flex; flex-direction: column; gap: 22px; min-width: 0; padding-top: 4px; }

#write .w-card {
  position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 24px; box-shadow: 0 6px 0 var(--ink);
  padding: 22px 18px 20px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
}
#write .w-card-text { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 2px; min-width: 0; max-width: 100%; }
/* 💡 Help me remember: the character's story, opened at its parts (history and a memory trick follow); full width
   under Hear it (Justin 2026-10-11: "Story" didn't say what it offers) */
#write .w-remember {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 48px; padding: 0 14px;
  font: 800 18px/1.1 var(--f-body); color: var(--ink); background: #fff; border: 2.5px solid var(--ink); border-radius: 14px;
  box-shadow: 0 3px 0 var(--ink); cursor: pointer;
}
#write .w-remember[hidden] { display: none; }
#write .w-remember svg { width: 24px; height: 24px; flex: none; }
#write .w-remember:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
#write .w-card.w-quiz .w-card-text { margin-top: 2px; }
#write .pinyin, #write .meaning { width: auto; margin: 0; text-align: inherit; }
#write .pinyin { font-family: var(--f-display); font-weight: 400; font-size: 46px; line-height: 1.02; color: var(--violet); overflow-wrap: anywhere; }
#write .meaning { font-family: var(--f-display); font-weight: 400; font-size: 30px; line-height: 1.1; overflow-wrap: anywhere; }
#write .pinyin:empty, #write .meaning:empty { display: none; }
#write .w-card.w-quiz .meaning { font-size: 40px; }
#write .w-flag {
  align-self: center; margin-top: -40px; font-family: var(--f-display); font-weight: 400; font-size: 22px; white-space: nowrap;
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 16px; padding: 8px 16px; box-shadow: 0 4px 0 var(--ink);
  transform: rotate(-2deg); animation: w-pop .45s cubic-bezier(.3, 1.6, .5, 1);
}
#write .w-flag.last { background: #d3f9e3; }
#write .w-flag.free { background: #e3efff; }
#write .w-pill { font-size: 16px; font-weight: 900; color: #3a22a8; background: var(--violet-soft); border-radius: 999px; padding: 6px 14px; }
#write .w-hear {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 58px; padding: 0 18px;
  font-family: var(--f-display); font-weight: 400; font-size: 24px; color: var(--ink); background: var(--yellow);
  border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 5px 0 var(--ink); cursor: pointer; transition: transform .08s, box-shadow .08s;
}
#write .w-hear svg { width: 28px; height: 28px; flex: none; }
#write .w-hear:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#write .w-hear.round { order: -1; width: 92px; height: 92px; min-height: 0; padding: 0; border-radius: 50%; }
#write .w-card.w-quiz .w-flag { order: -2; }
#write .w-hear.round svg { width: 46px; height: 46px; }
#write .w-hear.round span { display: none; }

/* Pao Pao and the bubble */
#write .w-coach { display: flex; align-items: flex-start; gap: 12px; }
#write .w-pao { width: 62px; height: 68px; flex: none; animation: w-bob 2.6s ease-in-out infinite; }
#write .w-pao.happy { animation: w-hop .5s cubic-bezier(.3, 1.6, .5, 1); }
#write .w-pao.oops { animation: w-shake .4s; }
#write .w-bubble {
  position: relative; flex: 1; min-width: 0; background: #fff; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 4px 0 var(--ink);
  padding: 13px 15px; font-weight: 800; font-size: 20px; line-height: 1.35;
}
#write .w-bubble::before {
  content: ""; position: absolute; left: -11px; top: 22px; width: 16px; height: 16px;
  background: #fff; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg);
}
#write .w-bubble:empty { visibility: hidden; }
#write .w-bubble.bump { animation: w-pop .35s cubic-bezier(.3, 1.6, .5, 1); }

/* the middle: the word's characters, the big box, how it's going */
#write .w-center { position: relative; height: 100%; min-height: 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; }
#write .w-strip { display: flex; justify-content: center; gap: 16px; flex: none; flex-wrap: wrap; }
#write .w-tl { position: relative; width: 76px; height: 76px; flex: none; border-radius: 16px; border: 3px solid var(--ink); background: #fffdf8; display: grid; place-items: center; }
#write .w-tl svg { width: 100%; height: 100%; display: block; }
#write .w-tl .w-tl-ink { position: absolute; inset: 4px; display: grid; place-items: center; font-size: 52px; line-height: 1; }
#write .w-tl.done { animation: w-pop .4s cubic-bezier(.3, 1.6, .5, 1); }
#write .w-tl.cur { border-color: var(--violet); background: #f4f0ff; box-shadow: 0 0 0 4px var(--violet-ring); color: var(--violet-deep); }
#write .w-tl.cur svg { width: 34px; height: 34px; }
#write .w-tl.todo { border-style: dashed; border-color: #9aa0ad; background: #f6f3ec; }
#write .w-ok {
  position: absolute; right: -9px; bottom: -9px; width: 27px; height: 27px; border-radius: 50%; display: grid; place-items: center;
  background: var(--green-deep); border: 2.5px solid #fff; color: #fff;
}
#write .w-ok svg { width: 15px; height: 15px; }
#write .w-boxes { flex: none; gap: 0; }
#write .w-below { flex: none; display: flex; flex-direction: column; align-items: center; gap: 12px; min-height: 40px; max-width: 100%; text-align: center; }
#write .w-help { font-family: var(--f-display); font-weight: 400; font-size: 26px; line-height: 1.2; }
#write .w-help:empty { display: none; }
#write .w-help.hint { color: #8a6200; }
#write .w-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; }
#write .w-actions:empty { display: none; }
#write .w-know { font: 800 18px/1 var(--f-body); color: var(--violet); background: none; border: 0; padding: 12px 14px; min-height: 48px; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }
#write .w-know:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; border-radius: 10px; }
/* "We marked this wrong?" is a quiet link on its own line under Try again / Next, not a third button (Justin) */
#write .w-actions .report-btn { order: 3; flex: 0 0 100%; font: 800 16px/1.2 var(--f-body); padding: 6px 12px; min-height: 44px; border: 0; background: none; color: #5b5f6b; text-decoration: underline; text-underline-offset: 4px; }
#write .w-free { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; gap: 12px; }
#write .w-free .dict-tools .big-btn { font-family: var(--f-display); font-weight: 400; }
#write .w-actions .w-tool { padding: 0 20px; }
#write .w-free .dict-tools:not(:has(> :not([hidden]))) { display: none; }
/* a phone sideways: the writing box gets the height (Justin 2026-10-11: "the stuff on the side needs to shrink,
   not the character"); the main button says what to do, so the line above it goes */
html.phone-side #write[data-phase="free"]:not(.w-after) .w-help { display: none; }
html.phone-side #write[data-phase="free"] .w-center { gap: 10px; }
/* a short, wide screen (a phone sideways in Safari, with its bars: Rebecca, idea #113): the help line and the
   buttons go beside the box instead of under it, so the box gets the height (games/write.js boxSize) */
@media (max-height: 520px) and (min-width: 900px) {
  #write .w-center { display: grid; grid-template-columns: auto auto minmax(0, 260px); grid-template-rows: minmax(0, 1fr); column-gap: 22px; align-content: center; justify-content: center; align-items: center; }
  #write .w-center > .w-strip { grid-column: 1; grid-row: 1; flex-direction: column; flex-wrap: nowrap; gap: 10px; }
  #write .w-center > .w-strip .w-tl { width: 60px; height: 60px; }
  #write .w-center > .w-boxes, #write .w-center > .w-free { grid-column: 2; grid-row: 1; }
  #write .w-center > .w-below { grid-column: 3; grid-row: 1; align-self: center; }
  #write .w-center > .w-below .w-help { font-size: 21px; }
  #write.w-after .w-actions { position: static; }
}

/* ---- the writing box: a 米字格 practice square ---- */
#write .box {
  border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 9px 0 var(--ink);
  background-color: #fffdf8;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cg stroke='%23e0573e' stroke-opacity='.32' stroke-width='.5' stroke-dasharray='2.2 1.6' vector-effect='non-scaling-stroke' fill='none'%3E%3Cpath d='M50 0V100M0 50H100'/%3E%3Cpath d='M0 0L100 100M100 0L0 100' stroke-opacity='.18'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 100% 100%;
  transition: border-color .2s, opacity .25s, transform .25s, box-shadow .2s;
}
#write .box::after {   /* the practice square's inner frame, like a 田字格 exercise book */
  content: ""; position: absolute; inset: 7px; border: 2px solid rgba(224, 87, 62, .28); border-radius: 18px; pointer-events: none;
}
#write .box.w-big { border-color: var(--violet); box-shadow: 0 8px 0 var(--violet-deep), 0 0 0 6px var(--violet-ring); touch-action: none; }
#write .box.w-big.done { border-color: var(--green-deep); box-shadow: 0 8px 0 var(--green-deep), 0 0 0 8px rgba(46, 194, 126, .25); }
#write[data-phase="watch"] .box.w-big { cursor: pointer; }
#write .box.miss { animation: w-shake .35s; }
#write .box.error { font-weight: 800; font-size: 20px; color: #6b7083; }
#write .box.inkpad.pass { border-color: var(--ink); box-shadow: 0 9px 0 var(--ink), 0 0 0 10px rgba(46, 194, 126, .25); }
#write .box.inkpad.fail { border-color: var(--ink); box-shadow: 0 9px 0 var(--ink), 0 0 0 10px rgba(240, 140, 0, .25); }
#write .box:not(.inkpad) svg { position: relative; z-index: 1; }

/* a right stroke: a few ink drops pop where it ended */
#write .w-pop { position: absolute; z-index: 3; width: 0; height: 0; pointer-events: none; }
#write .w-pop i {
  position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%; background: var(--c, var(--violet));
  border: 2px solid var(--ink); animation: w-drop .6s ease-out forwards;
}
#write .w-pop b {
  position: absolute; left: 0; top: 0; translate: -50% -130%; font-family: var(--f-display); font-weight: 400; font-size: 26px;
  color: #fff; -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; white-space: nowrap; animation: w-float .8s ease-out forwards;
}

/* a finished character: a red seal stamped in the corner */
#write .w-seal {
  position: absolute; z-index: 3; right: -16px; top: -16px; width: 58px; height: 58px; border-radius: 12px;
  background: var(--seal); color: #fff; display: grid; place-items: center;
  font-family: "Kaiti SC", "STKaiti", "KaiTi", "PingFang SC", serif; font-weight: 700; font-size: 36px; line-height: 1;
  border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .55), 0 4px 0 var(--ink);
  rotate: 12deg; animation: w-stamp .45s cubic-bezier(.2, 1.4, .4, 1) both; pointer-events: none;
}

/* ---- Today's words: each word's five dots are its level ---- */
#write .w-today { display: flex; flex-direction: column; min-height: 0; max-height: 100%; padding-top: 2px; }
#write .w-today-h { font-family: var(--f-display); font-weight: 400; font-size: 24px; text-align: center; margin-bottom: 12px; }
#write .w-rows { position: relative; display: flex; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; padding: 4px 6px 8px; margin: -4px -6px 0; scrollbar-width: none; }
#write .w-rows::-webkit-scrollbar { display: none; }
#write .w-met { flex: none; overflow: visible; }
#write .w-wrow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: none; height: 58px; padding: 0 12px 0 14px;
  border-radius: 16px; border: 3px solid var(--ink); background: #fff; box-shadow: 0 4px 0 var(--ink);
}
#write .w-wrow.cur { border-color: var(--violet); box-shadow: 0 4px 0 var(--violet-deep), 0 0 0 4px var(--violet-ring); }
#write .w-wrow.known { background: #f1efe8; border-color: #9aa0ad; box-shadow: 0 4px 0 #9aa0ad; }
#write .w-wrow.up { animation: w-pop .5s cubic-bezier(.3, 1.6, .5, 1); }
#write .w-wc { font-size: 27px; line-height: 1; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: clip; }
#write .w-wc.long { font-size: 23px; }
#write .w-hid { display: flex; gap: 4px; }
#write .w-hid i { display: block; width: 20px; height: 24px; border-radius: 6px; border: 2.5px dashed var(--violet); }
#write .w-pips { display: flex; gap: 4px; flex: none; }
#write .w-pips i { display: block; width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; }
#write .w-pips i.d { background: var(--green); }
#write .w-pips i.c { background: var(--violet); animation: w-pulse 1.2s ease-in-out infinite; }
#write .w-wrow.up .w-pips i.d:last-of-type { animation: w-pop .5s cubic-bezier(.3, 1.6, .5, 1) .2s both; }
#write .w-met-h { font-size: 13px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: #5c6275; text-align: center; margin: 16px 0 8px; }
#write .w-legend { font-size: 13px; color: #4b5163; text-align: center; margin-top: 14px; line-height: 1.4; flex: none; }

/* ---- the first time with a list: meet the new characters, or skip to practice ----
   The start card has the Writing Desk look (docs/DESIGN.md, the tokens in css/desk.css): desk paper, a soft round
   Home, the brush 写 title and the set's name in the header, one paper card with Pao Pao's line, the new characters
   on soft paper tiles (a word's characters stay together), the red main button. Practice keeps the Ink Pop look. */
#write .w-intro, #write .w-end {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; align-items: center;
  padding: 8px max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
#write.w-introing {
  background-color: var(--a-bg);
  background-image: linear-gradient(var(--a-grid) 1.5px, transparent 1.5px), linear-gradient(90deg, var(--a-grid) 1.5px, transparent 1.5px);
  background-size: 84px 84px; background-position: 0 0;
}
#write .w-head-title, #write .w-head-set { display: none; }
#write.w-introing .w-head-title {
  display: flex; align-items: center; gap: 10px; margin: 0; min-width: 0; white-space: nowrap;
  font-family: var(--f-display); font-weight: 400; font-size: 34px; line-height: 1; color: var(--a-fg);
}
#write.w-introing .w-head-set:not([hidden]) {
  display: block; min-width: 0; flex: 0 1 auto; padding: 13px 18px; border-radius: 999px;
  background: var(--a-card); box-shadow: var(--a-sh-sm); color: var(--a-fg); font: 900 16px/18px var(--f-body);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#write.w-introing #w-xp { display: none; }
#write.w-introing .w-head-title { margin-right: auto; }
#write.w-introing .game-head .icon-btn { width: 52px; height: 52px; font-size: 22px; border: 0; background: var(--a-card); box-shadow: var(--a-sh); transition: transform .12s ease-out; }
#write.w-introing .game-head .icon-btn .ic { width: 26px; height: 26px; }
#write.w-introing .game-head .icon-btn:active { transform: translateY(2px); box-shadow: var(--a-sh-sm); }
/* the paper card: centered, and still scrollable from its top when it's taller than the screen */
#write .w-intro-in {
  margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: clamp(18px, 3.4vh, 30px);
  width: min(1040px, 100%); padding: clamp(22px, 4.4vh, 44px) clamp(18px, 3.6vw, 44px);
  background: var(--a-card); border-radius: 26px; box-shadow: var(--a-sh);
}
#write .w-intro-hi { display: flex; align-items: center; justify-content: center; gap: 18px; }
#write .w-pao-big { width: 104px; height: 114px; flex: none; animation: w-bob 2.6s ease-in-out infinite; }
#write .w-intro .w-pao-big { width: 76px; height: 84px; }
#write .w-say-card { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
#write .w-say-card b { font-family: var(--f-display); font-weight: 400; font-size: 42px; line-height: 1.05; text-wrap: balance; }
#write .w-say-card span { font-size: 20px; font-weight: 800; color: var(--a-mute); }
#write .w-intro-words { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 22px 30px; max-width: 1100px; }
#write .w-intro-words.many { gap: 18px 22px; }
#write .w-end-tiles.many .w-tile { width: 92px; height: 92px; }
#write .w-end-tiles.many .w-tile > span { width: 72px; height: 72px; font-size: 62px; }
#write .w-iw { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; line-height: 1.25; }
#write .w-iw-tiles { display: flex; gap: 6px; }
#write .w-tile {
  position: relative; width: 112px; height: 112px; flex: none; display: grid; place-items: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 5px 0 var(--ink);
}
#write .w-tile > span { width: 88px; height: 88px; display: grid; place-items: center; font-size: 76px; line-height: 1; }
#write .w-tile > span svg { width: 100%; height: 100%; }
#write .w-tile.known { background: #f1efe8; border-color: #9aa0ad; box-shadow: 0 5px 0 #9aa0ad; color: #8b90a0; }
#write .w-intro .w-tile { width: 100px; height: 100px; border: 0; border-radius: 16px; background: #fff; box-shadow: var(--a-sh-sm), inset 0 0 0 1px rgba(80, 50, 20, .06); }
#write .w-intro .w-tile > span { width: 80px; height: 80px; font-size: 70px; }
#write .w-intro .w-tile.known { background: var(--a-word-bg); box-shadow: none; color: #8b90a0; }
#write .w-intro-words.many .w-tile { width: 86px; height: 86px; }
#write .w-intro-words.many .w-tile > span { width: 68px; height: 68px; font-size: 60px; }
#write .w-spark { position: absolute; right: -13px; top: -14px; width: 28px; height: 28px; animation: w-twinkle 2.2s ease-in-out infinite; }
#write .w-intro .w-spark { display: none; }
#write .w-iw-py { font-weight: 900; font-size: 20px; color: var(--c-write); }
#write .w-iw.known .w-iw-py { color: var(--a-mute); }
#write .w-iw-mean { font-size: 16px; font-weight: 800; color: var(--a-mute); max-width: 200px; }
#write .w-met-pill { display: inline-block; font-size: 15px; font-weight: 900; color: var(--green-deep); background: #dff6ea; border-radius: 999px; padding: 4px 12px; }
#write .w-intro-go { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 14px 16px; }
#write .w-intro .w-go { min-height: 72px; padding: 0 30px 0 24px; font-size: 28px; }
#write .w-intro .w-go svg { width: 22px; height: 22px; flex: none; }
#write .w-intro .w-go > span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; text-align: left; }
#write .w-intro .w-go small { font: 800 15px/1.2 var(--f-body); letter-spacing: 0; margin-top: 3px; opacity: .92; }
#write .w-intro .w-skip { min-height: 60px; }
#write .w-intro :is(.w-go, .w-skip):focus-visible { outline: 4px solid var(--c-write); outline-offset: 3px; }

/* ---- the end of a session ---- */
#write .w-end-in { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; max-width: 1100px; animation: w-card-in .5s cubic-bezier(.2, 1.4, .4, 1); }
#write .w-end h2 { font-family: var(--f-display); font-weight: 400; font-size: 62px; line-height: 1; margin: -6px 0 0; }
#write .w-end-sub { font-size: 26px; color: #2b3044; margin: -8px 0 0; }
#write .w-end-sub b.ok { color: var(--green-deep); font-weight: 900; }
#write .w-end-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px 26px; }
#write .w-end-tiles.many { gap: 16px 12px; }
#write .w-end-tiles.many .w-res { font-size: 13px; padding: 4px 9px; gap: 4px; }
#write .w-end-tiles.many .w-res svg { width: 13px; height: 13px; }
#write .w-end-t { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#write .w-res { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; font-weight: 900; border-radius: 999px; padding: 5px 12px; white-space: nowrap; }
#write .w-res svg { width: 16px; height: 16px; }
#write .w-res.ok { background: #dff6ea; color: var(--green-deep); }
#write .w-res.again { background: #fff1c2; color: #8a6200; }
#write .w-note {
  display: flex; align-items: center; gap: 16px; padding: 14px 24px 14px 16px; text-align: left; font-size: 21px; line-height: 1.35;
  background: #fff; border: 3px solid var(--ink); border-radius: 20px; box-shadow: 0 4px 0 var(--ink);
}
#write .w-note svg { width: 38px; height: 38px; flex: none; }
#write .w-note small { font-size: 18px; color: #4b5163; }
#write .w-note small b { font-size: 1.2em; }
#write .w-end-words { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 14px; width: min(920px, 100%); }
#write .w-end-words .w-wrow.up { background: #eafaf1; border-color: var(--green-deep); box-shadow: 0 4px 0 var(--green-deep); }
#write .w-end-go { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; }
#write .w-end-go .w-btn { min-height: 72px; font-size: 27px; padding: 0 30px; }
#write .w-end-go .w-btn svg { width: 28px; height: 28px; }
#write .w-end-can .can-svg { width: 150px; height: auto; }

/* ---- a new character's story covers the screen (css/charstory.css) ---- */
#write .w-story { position: absolute; inset: 0; z-index: 40; background: inherit; }
#write.w-storying .game-head, #write.w-storying .w-main { visibility: hidden; }

/* ---- upright: Today's words along the top, the word card in a row, the box under it ---- */
#write.w-tall .w-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 16px; align-items: stretch; }
#write.w-tall .w-side { display: contents; }
#write.w-tall .w-today { grid-row: 1; flex-direction: row; align-items: center; gap: 10px; max-height: none; padding: 0; }
#write.w-tall .w-legend, #write.w-tall .w-met-h, #write.w-tall .w-today-h span { display: none; }
#write.w-tall .w-today-h { order: 3; margin: 0; flex: none; }
#write.w-tall .w-allbtn { order: 2; margin: 0; flex: none; height: 54px; padding: 0 12px; }
#write.w-tall .w-rows { flex-direction: row; overflow-x: auto; overflow-y: visible; padding: 4px 6px 10px; margin: -4px 0 -6px; }
#write.w-tall .w-met { flex: none; }
#write.w-tall .w-wrow { gap: 8px; height: 54px; padding: 0 10px; }
#write.w-tall .w-card { grid-row: 2; flex-direction: row; text-align: left; padding: 12px 14px 12px 20px; gap: 14px; }
#write.w-tall .w-card-text { flex: 1; align-items: flex-start; margin: 0; gap: 2px; }
#write.w-tall .pinyin { font-size: 36px; }
#write.w-tall .meaning { font-size: 24px; }
#write.w-tall .w-card.w-quiz .meaning { font-size: 30px; }
#write.w-tall .w-remember { order: 2; width: auto; }
#write.w-tall .w-flag { margin: 0; order: 0; }
#write.w-tall .w-pill { order: 1; }
#write.w-tall .w-hear, #write.w-tall .w-hear.round { order: 3; width: 64px; height: 64px; min-height: 0; padding: 0; border-radius: 50%; }
#write.w-tall .w-hear svg { width: 32px; height: 32px; }
#write.w-tall .w-hear span { display: none; }
#write.w-tall .w-center { grid-row: 3; }
#write.w-tall .w-coach { grid-row: 4; align-items: center; }
#write.w-tall .w-bubble::before { top: 50%; margin-top: -8px; }

/* short screens (a phone sideways sees the iPad layout scaled, js/phonefit.js): a little tighter */
@media (max-height: 760px) {
  #write .w-main { gap: 20px; grid-template-columns: 240px minmax(0, 1fr) 226px; }
  #write .w-card { padding: 18px 16px 16px; gap: 10px; }
  #write .pinyin { font-size: 40px; }
  #write .meaning { font-size: 26px; }
  #write .w-wrow { height: 52px; }
  #write .w-tl { width: 64px; height: 64px; }
  #write .w-center { gap: 14px; }
  #write .w-help { font-size: 22px; }
  #write .w-intro-in, #write .w-end-in { gap: 20px; }
  #write .w-tile { width: 96px; height: 96px; }
  #write .w-tile > span { width: 74px; height: 74px; font-size: 64px; }
  #write .w-intro .w-tile { width: 88px; height: 88px; }
  #write .w-intro .w-tile > span { width: 70px; height: 70px; font-size: 60px; }
  #write .w-end h2 { font-size: 52px; }
}

/* a phone upright: the header and the start card get smaller so it all fits one screen */
@media (max-width: 600px) {
  #write.w-introing .game-head { gap: 8px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  #write.w-introing .game-head .icon-btn { width: 46px; height: 46px; }
  #write.w-introing .w-head-title { font-size: 24px; gap: 5px; }
  #write.w-introing .w-head-set:not([hidden]) { padding: 13px 11px; font-size: 13px; }
  #write .w-intro { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  #write .w-intro-in { padding: 22px 16px; gap: 20px; border-radius: 22px; }
  #write .w-intro-hi { gap: 12px; }
  #write .w-intro .w-pao-big { width: 54px; height: 60px; }
  #write .w-say-card b { font-size: 28px; }
  #write .w-say-card span { font-size: 17px; }
  #write .w-intro-words, #write .w-intro-words.many { gap: 14px 14px; }
  #write .w-intro .w-tile, #write .w-intro-words.many .w-tile { width: 58px; height: 58px; border-radius: 12px; }
  #write .w-intro .w-tile > span, #write .w-intro-words.many .w-tile > span { width: 46px; height: 46px; font-size: 40px; }
  #write .w-iw { gap: 6px; }
  #write .w-iw-tiles { gap: 4px; }
  #write .w-iw-py { font-size: 16px; }
  #write .w-iw-mean { font-size: 14px; max-width: 130px; }
  #write .w-met-pill { font-size: 13px; padding: 3px 9px; }
  #write .w-intro-go { width: 100%; flex-direction: column; align-items: stretch; gap: 12px; }
  #write .w-intro .w-go { min-height: 64px; font-size: 23px; padding: 0 18px; }
  #write .w-intro .w-go small { font-size: 13px; }
}
/* a short screen (a phone sideways at its own size): tighter still */
@media (max-height: 500px) {
  #write.w-introing .game-head { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 4px; }
  #write.w-introing .game-head .icon-btn { width: 44px; height: 44px; }
  #write.w-introing .w-head-title { font-size: 26px; }
  #write .w-intro-in { padding: 16px 22px; gap: 12px; }
  #write .w-intro .w-pao-big { width: 46px; height: 50px; }
  #write .w-say-card b { font-size: 26px; }
  #write .w-say-card span { font-size: 16px; }
  #write .w-intro .w-tile, #write .w-intro-words.many .w-tile { width: 60px; height: 60px; border-radius: 12px; }
  #write .w-intro .w-tile > span, #write .w-intro-words.many .w-tile > span { width: 48px; height: 48px; font-size: 42px; }
  #write .w-intro-words, #write .w-intro-words.many { gap: 10px 22px; }
  #write .w-iw { gap: 4px; }
  #write .w-iw-py { font-size: 16px; }
  #write .w-iw-mean { font-size: 14px; }
  #write .w-intro .w-go { min-height: 56px; font-size: 22px; }
  #write .w-intro .w-skip { min-height: 52px; }
  /* a word done on a sideways phone: ↻ Again and Next stack in the corner under Today's words (the box was
     sized before they came, and there's no room under it) */
  #write.w-after .w-actions { position: fixed; z-index: 3; right: max(16px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); flex-direction: column; align-items: stretch; }
  #write.w-after[data-phase="done"] .w-help { display: none; }
  #write.w-after .w-actions .report-btn { display: none; }
  #write.w-after .w-bubble { visibility: hidden; }   /* no room under the word card here (design review) */
  #write .w-actions { gap: 8px; }
  #write .w-actions .w-btn { min-height: 46px; padding: 0 14px; font-size: 19px; gap: 6px; box-shadow: 0 3px 0 var(--ink); }
  #write .w-actions .w-btn svg { width: 20px; height: 20px; }
  #write .w-know { min-height: 40px; padding: 8px 10px; font-size: 16px; }
}

@keyframes w-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes w-hop { 0% { transform: translateY(0) scale(1); } 40% { transform: translateY(-12px) scale(1.08, .94); } 100% { transform: translateY(0) scale(1); } }
@keyframes w-shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes w-pop { from { transform: scale(.85); } to { transform: scale(1); } }
@keyframes w-pulse { 50% { opacity: .35; } }
@keyframes w-twinkle { 50% { transform: scale(.75) rotate(20deg); } }
@keyframes w-drop { 0% { transform: translate(0, 0) scale(.4); opacity: 1; } 70% { opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; } }
@keyframes w-float { 0% { opacity: 0; transform: translateY(8px) scale(.6); } 25% { opacity: 1; transform: translateY(0) scale(1.1); } 100% { opacity: 0; transform: translateY(-26px) scale(1); } }
@keyframes w-stamp { 0% { opacity: 0; transform: scale(2.4); } 60% { opacity: 1; transform: scale(.92); } 100% { transform: scale(1); } }
@keyframes w-card-in { 0% { transform: scale(.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #write .w-pao, #write .w-pao-big, #write .w-spark, #write .w-pips i.c { animation: none; }
}

/* ---- a word tapped in Today's words: write it next (a few seconds to look away first) ---- */
#write .w-wrow.w-tap { cursor: pointer; transition: transform .12s; }
#write .w-wrow.w-tap:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-wrow.w-tap:focus-visible { outline: 4px solid var(--violet-ring); outline-offset: 2px; }
#write .w-cover {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--f-display); text-align: center; color: var(--ink); animation: w-pop .4s cubic-bezier(.3, 1.6, .5, 1);
}
#write .w-cover b { font-size: 30px; font-weight: 400; }
#write .w-cover .w-count {
  display: grid; place-items: center; width: 132px; height: 132px; border-radius: 50%; font-size: 72px; line-height: 1;
  background: #fff; border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); animation: w-pop .4s cubic-bezier(.3, 1.6, .5, 1);
}

/* ---- 🔒 "lock it in tomorrow": a half dot with a tiny lock, the dots legend, and every word in the list ---- */
#write .w-pips i { position: relative; }
#write .w-pips i.h { background: linear-gradient(90deg, var(--green) 50%, #fff 50%); }
#write .w-pips i.h b { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -52%); font-size: 7px; line-height: 1; filter: saturate(1.3); }
#write .w-pips i.h.ready { box-shadow: 0 0 0 2px var(--yellow); animation: w-ready 1.6s ease-in-out infinite; }
#write .w-pips i.h.c { animation: w-pulse 1.2s ease-in-out infinite; }
@keyframes w-ready { 50% { box-shadow: 0 0 0 4px rgba(255, 194, 46, .55); } }
#write .w-today-h { display: flex; align-items: center; justify-content: center; gap: 8px; }
#write .w-keybtn {
  width: 30px; height: 30px; border-radius: 50%; padding: 0; flex: none; display: grid; place-items: center;
  border: 3px solid var(--ink); background: var(--yellow); color: var(--ink); font-family: var(--f-display); font-size: 18px; line-height: 1;
  box-shadow: 0 3px 0 var(--ink); cursor: pointer;
}
#write .w-keybtn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#write .w-keybtn[aria-expanded="true"] { background: var(--violet); color: #fff; }
#write .w-keybtn { position: relative; }
#write .w-keybtn::after { content: ""; position: absolute; inset: -9px; }   /* a 30px dot, a 48px target */
html.phone-side #write .w-keybtn::after { inset: -18px; }
#write .w-allbtn {
  flex: none; margin-top: 12px; padding: 10px 12px; border-radius: 14px; border: 3px dashed var(--violet); background: var(--violet-soft);
  color: var(--violet-deep); font: inherit; font-size: 16px; cursor: pointer; white-space: nowrap;
}
#write .w-allbtn:active { transform: translateY(2px); }
#write .w-key {
  position: absolute; z-index: 20; right: 16px; top: 76px; width: min(330px, calc(100% - 32px)); box-sizing: border-box;
  background: #fff; border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 8px 0 var(--ink); padding: 16px 18px 14px;
  animation: w-card-in .25s cubic-bezier(.2, 1.4, .4, 1); transform-origin: top right;
}
#write .w-key h3 { margin: 0 34px 8px 0; font-family: var(--f-display); font-weight: 400; font-size: 21px; }
#write .w-key h3 + ol, #write .w-key h3 + ul { margin-bottom: 14px; }
#write .w-key-x { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--ink); background: #fff; font: inherit; font-size: 16px; cursor: pointer; }
#write .w-key ol, #write .w-key ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
#write .w-key li { display: flex; align-items: center; gap: 10px; font-size: 15px; line-height: 1.25; }
#write .w-key li .w-pips { min-width: 84px; }
#write .w-key-what li .w-pips { min-width: 20px; }
#write .w-key p { margin: 0; font-size: 13px; color: #4b5163; line-height: 1.4; }
#write .w-allsheet {
  position: absolute; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(29, 34, 51, .35); animation: w-card-in .2s ease-out;
}
#write .w-all-card {
  position: relative; width: min(860px, 100%); max-height: 100%; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink); padding: 18px 20px 16px;
}
#write .w-all-head { display: flex; align-items: center; gap: 14px; }
#write .w-all-head .w-key-x { position: static; flex: none; width: 44px; height: 44px; }
#write .w-all-card h3 { margin: 0; flex: 1; font-family: var(--f-display); font-weight: 400; font-size: 30px; white-space: nowrap; }
#write .w-all-find { flex: 0 1 300px; min-width: 0; }
#write .w-all-find input {
  width: 100%; box-sizing: border-box; min-height: 46px; padding: 0 16px; font: 700 17px var(--f-body); color: var(--ink);
  background: #fff; border: 2.5px solid var(--ink); border-radius: 999px; outline: none;
}
#write .w-all-find input:focus { border-color: var(--violet); box-shadow: 0 0 0 4px var(--violet-ring); }
#write .w-all-card .w-all-note { margin: 0; color: #4b5163; font-size: 16px; font-weight: 700; }
/* the words scroll inside the sheet when there are many; the head and the buttons stay put */
#write .w-all-grid { flex: 1 1 auto; min-height: 0; overflow-y: auto; scrollbar-width: thin; padding: 4px 4px 10px; margin: 0 -4px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; align-content: start; }
#write .w-all-w[hidden] { display: none; }
#write .w-all-grid .w-all-w { padding: 8px 6px; gap: 6px; }
#write .w-all-grid .w-all-w .w-zh { font-size: 28px; }
#write .w-all-grid .w-all-w .w-zh.long { font-size: 20px; }
#write .w-remember span { white-space: nowrap; }
#write .w-all-w.on { background: var(--violet); border-color: var(--violet-deep); color: #fff; box-shadow: 0 4px 0 var(--violet-deep); }
#write .w-all-foot { display: flex; justify-content: flex-end; gap: 12px; padding-top: 4px; border-top: 2px dashed #0002; }
#write .w-all-foot .w-btn { min-height: 52px; }
#write .w-all-w {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 8px 10px; border-radius: 16px;
  border: 3px solid var(--ink); background: #fff; box-shadow: 0 4px 0 var(--ink); font: inherit; color: var(--ink); cursor: pointer;
}
#write .w-all-w .w-zh { font-family: var(--f-kai); font-size: 32px; line-height: 1.1; }
#write .w-all-w .w-zh.long { font-size: 24px; }
#write .w-all-w:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-all-w.cur { opacity: .55; cursor: default; border-style: dashed; }

/* 🖐 the word's step, under its card, and the sheet that moves it (Justin 2026-10-11) */
#write .w-step {
  display: flex; align-items: center; gap: 7px; width: 100%; min-height: 50px; padding: 0 10px 0 12px; box-sizing: border-box;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink);
  font-family: var(--f-display); font-weight: 400; font-size: 20px; color: var(--ink); cursor: pointer;
}
#write .w-step[hidden] { display: none; }
#write .w-step > span:not(.w-pips) { flex: 1; min-width: 0; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#write .w-step .w-pips { gap: 3px; }
#write .w-step .w-pips i { width: 11px; height: 11px; }
#write .w-step svg { width: 18px; height: 18px; }
#write .w-step svg { width: 20px; height: 20px; flex: none; color: var(--violet); }
#write .w-step:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-steps {
  position: absolute; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(29, 34, 51, .35); animation: w-card-in .2s ease-out;
}
#write .w-steps[hidden] { display: none; }
#write .w-steps-card {
  width: min(520px, 100%); max-height: 100%; box-sizing: border-box; display: flex; flex-direction: column; gap: 10px;
  background: var(--paper); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink); padding: 20px 22px 18px;
}
#write .w-steps-card h2 { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: 30px; line-height: 1.1; }
#write .w-steps-card h2 .w-zh { font-family: var(--f-kai); }
#write .w-steps-card > p { margin: 0 0 4px; color: #4b5163; font-size: 17px; }
#write .w-steps-list { display: grid; gap: 8px; }
#write .w-steps-row {
  display: flex; align-items: center; gap: 14px; min-height: 60px; padding: 8px 14px; text-align: left;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); font: inherit; color: var(--ink); cursor: pointer;
}
#write .w-steps-row .w-pips { min-width: 84px; }
#write .w-steps-ic { flex: none; width: 48px; height: 48px; }
#write .w-steps-row:disabled .w-steps-ic { opacity: .55; }
#write .w-steps-t { flex: 1; display: flex; flex-direction: column; gap: 2px; }
#write .w-steps-t b { font-family: var(--f-display); font-weight: 400; font-size: 22px; }
#write .w-steps-t small { font-size: 14px; font-weight: 800; color: #4b5163; }
#write .w-steps-row.on { border-color: var(--violet); box-shadow: 0 4px 0 var(--violet-deep), 0 0 0 4px var(--violet-ring); }
#write .w-steps-row:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-steps-row:disabled { background: #f1efe8; border-color: #9aa0ad; box-shadow: 0 4px 0 #9aa0ad; cursor: default; }
#write .w-steps-now { font-style: normal; font-size: 13px; font-weight: 900; color: #fff; background: var(--violet); border-radius: 999px; padding: 4px 10px; }
#write .w-steps-x { align-self: center; min-height: 50px; margin-top: 4px; font-size: 20px; }
/* the bottom row: the kid's own Pinyin checks switch, then Cancel */
#write .w-steps-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
#write .w-steps-foot .w-steps-x { margin-top: 0; }
#write .w-steps-py {
  display: flex; align-items: center; gap: 14px; min-height: 56px; padding: 6px 12px 6px 14px; text-align: left;
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 0 4px 0 var(--ink); font: inherit; color: var(--ink); cursor: pointer;
}
#write .w-steps-py:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
#write .w-steps-py-t { display: flex; flex-direction: column; gap: 2px; }
#write .w-steps-py-t b { font-family: var(--f-display); font-weight: 400; font-size: 20px; }
#write .w-steps-py-t small { font-size: 14px; font-weight: 800; color: #4b5163; }
#write .w-sw { flex: none; position: relative; width: 52px; height: 30px; border-radius: 999px; background: #c9ccd6; border: 3px solid var(--ink); box-sizing: border-box; transition: background .15s; }
#write .w-sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); box-sizing: border-box; transition: transform .15s; }
#write .w-sw.on { background: var(--violet); }
#write .w-sw.on::after { transform: translateX(22px); }
#write .w-steps-py.lock { cursor: default; background: #f1efe8; border-color: #9aa0ad; box-shadow: 0 4px 0 #9aa0ad; }
#write .w-steps-py.lock:active { transform: none; }
#write .w-sw.lock { opacity: .6; }
@media (max-height: 560px) {
  #write .w-steps { padding: 10px; }
  #write .w-steps-card { width: min(720px, 100%); padding: 12px 16px; gap: 6px; }
  #write .w-steps-card h2 { font-size: 22px; }
  #write .w-steps-card > p { display: none; }
  #write .w-steps-list { grid-template-columns: 1fr 1fr; gap: 6px; }
  #write .w-steps-row { min-height: 52px; padding: 6px 10px; gap: 10px; }
  #write .w-steps-row .w-pips { display: none; }
  #write .w-steps-ic { width: 36px; height: 36px; }
  #write .w-steps-t b { font-size: 18px; }
  #write .w-steps-t small { font-size: 12px; }
  #write .w-steps-x { min-height: 42px; font-size: 17px; margin-top: 2px; }
  #write .w-steps-py { min-height: 46px; padding: 4px 10px; }
  #write .w-steps-py-t b { font-size: 17px; }
  #write .w-steps-py-t small { font-size: 14px; }
  #write .w-step { min-height: 42px; font-size: 17px; }
}

/* a phone held sideways sees the iPad layout at about half size (81px here = 44pt, 28px = 15pt):
   the step sheet gets two columns of big rows, clear of the notch and the home bar */
html.phone-side #write .w-steps { padding: 11px max(108px, env(safe-area-inset-right)) 39px max(108px, env(safe-area-inset-left)); }
html.phone-side #write .w-steps-card { width: min(1340px, 100%); padding: 18px 26px 20px; gap: 14px; border-radius: 34px; }
html.phone-side #write .w-steps-card h2 { font-size: 46px; }
html.phone-side #write .w-steps-card > p { display: none; }
html.phone-side #write .w-steps-list { grid-template-columns: 1fr 1fr; gap: 14px; }
/* shorter phones (Rebecca, idea #99): the pinyin switch and Cancel take the empty cell beside 听写 instead of a row
   of their own, and the card scrolls only if a screen is shorter still */
html.phone-side #write .w-steps-card { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; row-gap: 14px; overflow-y: auto; scrollbar-width: none; }
html.phone-side #write .w-steps-card > h2 { grid-column: 1 / -1; }
html.phone-side #write .w-steps-list { display: contents; }
html.phone-side #write .w-steps-foot { margin: 0; align-self: center; }
html.phone-side #write .w-steps-row { min-height: 112px; padding: 10px 18px; gap: 18px; border-radius: 22px; }
html.phone-side #write .w-steps-row .w-pips { display: none; }
html.phone-side #write .w-steps-ic { width: 66px; height: 66px; }
html.phone-side #write .w-steps-t { gap: 4px; }
html.phone-side #write .w-steps-t b { font-size: 38px; line-height: 1.05; }
html.phone-side #write .w-steps-t small { font-size: 27px; line-height: 1.2; }
html.phone-side #write .w-steps-now { font-size: 26px; padding: 6px 16px; }
html.phone-side #write .w-steps-x { min-height: 81px; padding: 0 44px; font-size: 32px; margin-top: 2px; }
html.phone-side #write .w-steps-py { min-height: 96px; padding: 8px 20px 8px 24px; gap: 24px; border-radius: 22px; }
html.phone-side #write .w-steps-py-t b { font-size: 36px; }
html.phone-side #write .w-steps-py-t small { font-size: 27px; }
html.phone-side #write .w-sw { width: 96px; height: 54px; border-width: 4px; }
html.phone-side #write .w-sw::after { top: 4px; left: 4px; width: 38px; height: 38px; border-width: 3px; }
html.phone-side #write .w-sw.on::after { transform: translateX(42px); }

/* short screens (a phone sideways sees a scaled iPad): the step chip's name still fits beside its dots */
@media (max-height: 760px) {
  #write .w-step { gap: 5px; padding: 0 8px; font-size: 16px; }
}

/* ---- a phone held sideways. js/phonefit.js draws the iPad layout at ~0.55 scale, which made every label 6 to 11pt
   and most buttons under 44pt (Justin 2026-10-12: "not mobile friendly at all"). So on a phone Write it! gets its own
   sizes, in the virtual iPad's pixels: 28px here is ~15pt on the phone, 81px is 44pt. Text is 15pt and up, buttons
   44pt and up, and everything stays clear of the Dynamic Island and the home bar (59pt = 108px, 21pt = 39px)
   whatever the phone reports. (Not CSS zoom: the stroke checker maps touches 1:1 and zoom breaks that.) */
html.phone-side #write .game-head { position: absolute; inset: 0 0 auto 0; z-index: 2; pointer-events: none; padding: 11px max(108px, env(safe-area-inset-right)) 0 max(108px, env(safe-area-inset-left)); gap: 14px; }
html.phone-side #write .game-head > * { pointer-events: auto; }
html.phone-side #write .icon-btn { width: 81px; height: 81px; font-size: 36px; }
html.phone-side #write .icon-btn .ic { width: 38px; height: 38px; }
html.phone-side #write .w-dict { min-height: 81px; padding: 0 26px; font-size: 30px; }
html.phone-side #write .xp-chip { display: none; }   /* XP still lands on the level-up and the round's end */
html.phone-side #write .w-main {
  height: 100%; grid-template-columns: 400px minmax(0, 1fr) 266px; gap: 25px; align-items: stretch;
  padding: 11px max(108px, env(safe-area-inset-right)) max(39px, env(safe-area-inset-bottom)) max(108px, env(safe-area-inset-left));
}
html.phone-side #write .w-side { padding-top: 96px; gap: 12px; min-height: 0; }
html.phone-side #write .w-coach { flex: 0 1 auto; min-height: 0; }   /* a long hint stays inside the column (Rebecca, idea #99) */
html.phone-side #write .w-coach .w-bubble { max-height: 100%; overflow-y: auto; scrollbar-width: none; }
html.phone-side #write .w-today { padding-top: 96px; }
html.phone-side #write .w-center { min-height: 0; gap: 14px; }
/* the word card: no flag (the step chip says the step) */
html.phone-side #write .w-card { padding: 14px 17px; gap: 9px; border-radius: 28px; }
html.phone-side #write .w-flag { display: none; }
html.phone-side #write .pinyin { font-size: 53px; }
html.phone-side #write .meaning { font-size: 36px; }
html.phone-side #write .w-card.w-quiz .meaning { font-size: 48px; }
html.phone-side #write .w-pill { font-size: 28px; padding: 6px 17px; }
html.phone-side #write .w-hear { min-height: 81px; font-size: 30px; border-radius: 22px; }
html.phone-side #write .w-hear svg { width: 36px; height: 36px; }
html.phone-side #write .w-hear.round { width: 104px; height: 104px; }
html.phone-side #write .w-hear.round svg { width: 56px; height: 56px; }
html.phone-side #write .w-remember { min-height: 81px; font-size: 28px; border-radius: 20px; }
html.phone-side #write .w-remember svg { width: 32px; height: 32px; }
/* the step chip: the step's name only (its dots are on the word's row in Today's words) */
html.phone-side #write .w-step { min-height: 81px; font-size: 28px; gap: 8px; padding: 0 16px; border-radius: 20px; }
html.phone-side #write .w-step svg { width: 28px; height: 28px; }
html.phone-side #write .w-step .w-pips { display: none; }
/* Pao Pao's words, without Pao Pao (no room) */
html.phone-side #write .w-coach > .w-pao { display: none; }
html.phone-side #write .w-bubble { font-size: 28px; line-height: 1.3; padding: 14px 17px; border-radius: 22px; }
html.phone-side #write .w-bubble::before { display: none; }
/* Today's words */
html.phone-side #write .w-today-h { font-size: 31px; margin-bottom: 11px; }
html.phone-side #write .w-keybtn { position: relative; width: 48px; height: 48px; font-size: 27px; }
html.phone-side #write .w-rows { gap: 11px; }
html.phone-side #write .w-wrow { height: 81px; padding: 0 14px 0 17px; gap: 8px; border-radius: 20px; }
html.phone-side #write .w-wc { font-size: 36px; }
html.phone-side #write .w-wrow .w-pips { gap: 3px; flex: none; }
html.phone-side #write .w-wrow .w-pips i { width: 15px; height: 15px; }
html.phone-side #write .w-allbtn { min-height: 81px; font-size: 28px; margin-top: 11px; border-radius: 20px; }
/* the middle: the characters, the box, the line under it and the buttons */
html.phone-side #write .w-tl { width: 96px; height: 96px; border-radius: 20px; }
html.phone-side #write .w-tl .w-tl-ink { font-size: 66px; }
html.phone-side #write .w-help { font-size: 32px; }
html.phone-side #write .dict-slot { width: 84px; height: 84px; font-size: 40px; }
html.phone-side #write .w-actions { flex-wrap: nowrap; gap: 14px; }
html.phone-side #write .w-actions .w-btn { min-height: 81px; padding: 0 25px; font-size: 31px; white-space: nowrap; border-radius: 22px; }
html.phone-side #write .w-actions .w-btn svg { width: 34px; height: 34px; }
html.phone-side #write .w-actions .report-btn { min-height: 81px; font-size: 26px; }
html.phone-side #write .w-actions:has(.report-btn) { flex-wrap: wrap; }
html.phone-side #write .w-actions .w-long { display: none; }   /* "Next", not "Next character": the strip shows which one */
html.phone-side #write .w-pill .w-long { display: none; }   /* "Sound only" fits on one line */
html.phone-side #write[data-phase="free"] .w-free { padding-bottom: 14px; }   /* room for the box's shadow above the buttons */
/* the box centered over Undo / Check / Clear: Undo and Clear left the card, so balance the strip (games/write.js --strip-w) */
#write .w-free.dict-one:not(.dict-wide) { column-gap: 0; }
#write .w-free.dict-one.dict-wide { padding-right: calc(var(--strip-w, 0px) + 16px); }
/* a phone: the box keeps the width the strip would have balanced, and the buttons shift under it instead */
html.phone-side #write .w-free.dict-one.dict-wide { padding-right: 0; }
html.phone-side #write:has(.w-free.dict-wide:not([hidden])) .w-below { padding-left: calc(var(--strip-w, 0px) + 16px); }
html.phone-side #write[data-phase="free"] .w-center { gap: 14px; }
/* one character, no strip: the box takes the whole middle and sits centered over Undo / Check / Clear (as on the canvas), not pinned to the top */
#write .w-free.dict-one > .dict-strip[hidden] + .dict-chars { grid-row: 1 / -1; }

/* ---- 说中文！ the stamp on a marked word, and Chinese-first buttons (docs/LANGUAGE.md) ---- */
#write .w-boxes, #write .w-free { position: relative; }
#write .w-stamp { position: absolute; top: -26px; right: -30px; z-index: 3; pointer-events: none;
  padding: 8px 16px 9px; border: 4px solid var(--seal, #c0392b); border-radius: 16px; background: #fffdf8; color: var(--seal, #c0392b);
  box-shadow: 0 5px 0 var(--seal, #c0392b); transform: rotate(-5deg); animation: w-stamp-in .32s cubic-bezier(.2, 1.6, .5, 1) both; }
#write .w-stamp .bark { font-size: 46px; }
#write .w-stamp .bark > b { font-family: var(--f-kai); white-space: nowrap; }
#write .w-stamp .bark > em { font-size: .38em; color: var(--ink); opacity: .8; }
#write .w-stamp .bark > small { font-size: .4em; }
#write .w-stamp.messy, #write .w-stamp.fail, #write .w-stamp.close { --seal: #8a6200; }
@keyframes w-stamp-in { from { opacity: 0; transform: scale(1.6) rotate(-12deg); } to { opacity: 1; transform: rotate(-5deg); } }
@media (prefers-reduced-motion: reduce) { #write .w-stamp { animation: none; } }
#write .w-btn-zh { display: inline-flex; flex-direction: column; align-items: center; line-height: 1.05; }
#write .w-btn-zh > b { font-weight: 900; }
#write .w-btn-zh > small { font-size: .62em; font-weight: 800; opacity: .75; }
#write .w-end h2 .w-end-bark > b { font-family: var(--f-kai); }
#write .w-end h2 .w-end-bark > small { font-size: .38em; }
#write .w-end h2 .w-end-bark > em { font-size: .4em; }
html.phone-side #write .w-stamp { top: -34px; right: -56px; padding: 5px 12px 6px; }
html.phone-side #write .w-stamp .bark { font-size: 44px; }
html.phone-side #write .w-stamp .bark > em { font-size: .42em; }
@media (max-width: 500px) { #write .w-stamp { top: -18px; right: -8px; padding: 5px 10px 6px; } #write .w-stamp .bark { font-size: 32px; } }
#write .pyc { position: relative; }
/* (no room beside them for a two-character word: it goes up in the empty strip above, over the last character's corner) */
#write .pyc > .w-stamp { top: -86px; right: -70px; white-space: nowrap; }
#write .pyc > .w-stamp .bark { font-size: 34px; }
html.phone-side #write .pyc > .w-stamp { top: -60px; right: -64px; padding: 3px 10px 4px; border-width: 3px; }
html.phone-side #write .pyc > .w-stamp .bark { font-size: 26px; }
#write .w-end-words .w-next { margin-left: auto; font: 900 15px/1 var(--f-body); color: var(--green-deep, #1f7a4a); white-space: nowrap; }
/* 🔤 the pinyin check after the characters (Try it: pick one of three · No help: add the tones) */
#write .pinyin.w-py-hid { visibility: hidden; }
#write .pyc { --pyc-miss: var(--violet-deep); --pyc-miss-soft: var(--violet-soft); }
#write .pyc-keys { --pyc-miss: var(--violet-deep); --pyc-miss-soft: var(--violet-soft); }
#write .pyc-forgot { min-height: 50px; font-size: 20px; }
/* (the check itself is css/pinyincheck.css; here, its phone-sideways sizes in Write it!: 81px = 44pt, 28px ≈ 15pt) */
html.phone-side #write .pyc { gap: 36px; }
html.phone-side #write .pyc-syl { min-width: 170px; min-height: 96px; font-size: 54px; border-radius: 24px; }
html.phone-side #write .pyc-o { font-size: 40px; }
html.phone-side #write .pyc-kb { --pyc-kw: 81px; --pyc-kh: 80px; }   /* the same 44pt keys as 听写's sideways keyboard */
html.phone-side #write .pyc-kb .dict-key.tone .tone-mark { width: 44px; }
html.phone-side #write .pyc-kb .dict-key.tone small { font-size: 28px; }   /* ×0.55 = 15pt */
html.phone-side #write .w-actions.pyc-keys { flex-wrap: wrap; row-gap: 12px; }
/* 💬 the meaning check after From memory (css/pinyincheck.css .mnc): two rows of two, 44pt tall, 15pt+ text */
#write .w-actions.mnc-keys { gap: 12px; }
#write .mnc-keys > .w-btn { min-height: 64px; justify-content: center; }
html.phone-side #write .mnc-q { min-height: 96px; font-size: 48px; border-radius: 24px; padding: 8px 30px; }
html.phone-side #write .mnc-keys { width: min(100%, 860px); }
html.phone-side #write .mnc-keys > .w-btn { min-height: 88px; }
html.phone-side #write .mnc-o { font-size: 32px; }


/* From memory's pinyin (js/dictation.js's pinyin step) sizes itself to the middle column, not the screen */
#write .w-free.dict-pystep { container-type: size; }
/* a phone held sideways: Today's words steps aside so the keyboard's keys can be finger-sized (81px = 44pt) */
html.phone-side #write:has(.w-free.dict-pystep:not([hidden])) .w-main { grid-template-columns: 322px minmax(0, 1fr) 0; }
html.phone-side #write:has(.w-free.dict-pystep:not([hidden])) .w-today { visibility: hidden; }
html.phone-side #write:has(.w-free.dict-pystep:not([hidden])) .w-help { display: none; }
html.phone-side #write .w-free.dict-one.dict-pystep { --kw: 81px; --kh: 72px; --g: 6px; --s: 64px; gap: 10px; padding-right: 0; }
html.phone-side #write .w-free.dict-pystep .dict-kb { width: calc(81px * 10 + 6px * 9 + 34px); }
html.phone-side #write .w-free.dict-pystep .dict-key { font-size: 34px; }
html.phone-side #write .w-free.dict-pystep .dict-key.tone .tone-mark { width: 44px; }
html.phone-side #write .w-free.dict-pystep .dict-key.tone small { font-size: 28px; }
html.phone-side #write .w-free.dict-pystep .dict-syl { height: 48px; font-size: 30px; }
html.phone-side #write .w-free.dict-pystep .dict-answer .dict-back { min-height: 66px; font-size: 26px; }
/* (the meaning check's marked keys stay colored, over the disabled look) */
#write .mnc-keys > .w-btn.right:disabled { background: #d7f7e6; border-color: #2ec27e; box-shadow: 0 4px 0 #1e9e62; color: #146c43; opacity: 1; }
#write .mnc-keys > .w-btn.wrong:disabled { background: var(--violet-soft); border-color: var(--violet-deep); box-shadow: 0 4px 0 var(--violet-deep); color: #3d2fa8; opacity: 1; }
