/* Character tracing. Block and inline-block boxes with margins only, so the layout
   works in older reader browsers without Grid, Flex spacing, box ratios or custom properties. */
/* The Choose button and, beside it, the character being practised and its Zhuyin. The button and the character
   float left; the readings take the rest of the row and wrap inside it, so a character with many readings never
   pushes the button or the character onto another line. On a very narrow page they go under the row instead. */
.trace-choices { margin: 4px 0 0; white-space: nowrap; }
.trace-choices:after { content: ""; display: block; clear: both; }
.trace-choices button, .trace-choices .trace-character { float: left; }
/* Every reading of the character, in the dictionary's order; one syllable never breaks across lines. */
.trace-reading { display: block; overflow: hidden; padding: 8px 0 0 6px; white-space: normal; font-size: 26px; font-weight: 700; line-height: 1.3; }
.trace-reading:empty { display: none; }
.trace-reading span { display: inline-block; margin: 0 18px 6px 0; white-space: nowrap; }
.trace-choices button, .trace-actions button, .chooser-head button, .chooser-pages button { min-height: 52px; margin: 0 6px 6px 0; padding: 8px 14px; font-size: 20px; font-weight: 700; line-height: 1.3; vertical-align: top; }
.trace-choices button:disabled, .chooser-pages button:disabled { background: #f1f1e9; }
/* Room for the stroke label and two lines of feedback, so a longer message does not move the sheet. */
.trace-info { min-height: 82px; margin: 0 0 6px; font-size: 20px; line-height: 1.3; }
.trace-info p { margin: 0; }
.trace-info #message { display: block; font-size: 20px; }
.trace-character { display: inline-block; min-width: 58px; min-height: 52px; margin: 0 6px 6px 0; padding: 4px 10px; border: 2px solid #254532; border-radius: 10px; color: #fffdf7; background: #315a47; font-size: 32px; font-weight: 700; line-height: 1.25; text-align: center; vertical-align: top; }
.trace-character:empty { visibility: hidden; }
/* A square sheet as wide as the page, but short enough to keep the controls on the same screen.
   The script replaces this estimate with the measured room. */
.trace-sheet { position: relative; width: 100%; max-width: 896px; max-width: calc(100vh - 300px); min-width: 252px; margin: 0 auto; border: 3px solid #000; background: #fff; }
.trace-sheet:before { content: ""; display: block; padding-top: 100%; }
.trace-guide, .trace-ink, .trace-mark { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: block; width: 100%; height: 100%; }
/* The feedback mark lies under the ink canvas, the sheet's top layer, and never takes input. */
.trace-mark { pointer-events: none; }
/* Pen strokes must not pan, select or open menus; the page outside the sheet scrolls as usual.
   The canvas holds only pure black marks and is scaled without smoothing. */
.trace-ink { touch-action: none; -ms-touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; cursor: crosshair; image-rendering: -webkit-optimize-contrast; image-rendering: crisp-edges; image-rendering: pixelated; }
/* The guide is drawn in thousandths of the sheet. Every stroke shows its outline ("frame"); the stroke
   to write has a heavy outline, a start dot and a dashed line ending in an arrowhead.
   The writing area is pure black and white, at the owner's request, so that an e-ink screen may use its faster
   black-and-white update: no grey or colour and no anti-aliased edges. Only the X/O mark (styled below) has colour.
   Every line is at least 4.5 thousandths wide, over one pixel even on the narrowest (252px) sheet: a browser draws a
   line thinner than a pixel as a translucent grey one even without anti-aliasing. */
.trace-guide { shape-rendering: crispEdges; }
.guide-grid { fill: none; stroke: #000; stroke-width: 4.5; stroke-dasharray: 4.5 18; }
.guide-frame { fill: none; stroke: #000; stroke-width: 4.5; stroke-linejoin: round; }
.guide-current { fill: none; stroke: #000; stroke-width: 9; stroke-linejoin: round; }
.guide-line { fill: none; stroke: #000; stroke-width: 6; stroke-dasharray: 18 14; stroke-linejoin: round; }
.guide-arrow { fill: #000; }
.guide-dot { fill: #000; stroke: #fff; stroke-width: 6; }
/* A large red X after a stroke that is not accepted; a large green O when the character is finished. Solid
   colours, no transparency or fading. */
.mark-wrong { fill: none; stroke: #d00000; stroke-width: 64; stroke-linecap: round; }
.mark-right { fill: none; stroke: #008a2e; stroke-width: 64; }
.trace-actions { margin: 8px 0 0; }
.trace-actions button:disabled { background: #f1f1e9; }
/* The chooser takes the place of the sheet: stroke counts first, then one page of characters.
   Its buttons are fixed nodes; only their text and pressed state change. */
.trace-chooser { margin: 4px 0 0; }
.chooser-head h2 { display: inline-block; margin: 10px 0 0; font-size: 24px; line-height: 1.3; color: #254f39; vertical-align: top; }
.chooser-label { margin: 4px 0 6px; font-size: 20px; line-height: 1.3; }
.chooser-groups button { min-width: 52px; min-height: 52px; margin: 0 6px 6px 0; padding: 4px 6px; font-size: 22px; font-weight: 700; line-height: 1.2; vertical-align: top; }
.chooser-characters button { min-width: 58px; min-height: 58px; margin: 0 6px 6px 0; padding: 4px 8px; font-size: 32px; line-height: 1.2; vertical-align: top; }
.chooser-groups button[aria-pressed="true"], .chooser-characters button[aria-pressed="true"] { color: #fffdf7; background: #315a47; border-color: #254532; }
.chooser-pages { margin: 2px 0 0; }
.trace-notes details { display: block; }
.trace-notes ul { margin: 0; }
.trace-note { margin: 8px 0; font-size: 18px; line-height: 1.5; }
.trace-license { color: #315a47; font-weight: 700; }
@media (max-width: 559px) {
  .trace-info { min-height: 96px; font-size: 18px; }
  .trace-info #message { font-size: 18px; }
}
@media (max-width: 559px) {
  .chooser-head h2 { font-size: 22px; }
  .chooser-label { font-size: 18px; }
}
@media (max-width: 419px) {
  .trace-reading { clear: both; padding: 0; font-size: 24px; }
  .trace-reading span { margin-right: 14px; }
  .trace-choices button, .trace-actions button, .chooser-head button, .chooser-pages button { margin-right: 4px; }
  .trace-actions button { padding: 8px 10px; }
  .chooser-groups button, .chooser-characters button { margin-right: 4px; }
  .chooser-characters button { min-width: 52px; min-height: 52px; font-size: 28px; }
  .chooser-head h2 { display: block; margin: 0 0 4px; }
}
