/* Writing practice */

.write__letters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 6px;
}
.write__letter {
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 0;
  font-family: var(--font-arabic);
  font-size: 28px;
  line-height: 1.3;
  text-align: center;
}
.write__letter:hover { border-color: var(--ink); color: var(--ink); text-decoration: none; }
.write__letter[aria-current="page"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
/* Letters already traced get a small green tick. */
.write__letter.is-traced { position: relative; }
.write__letter.is-traced::after {
  content: "✓";
  position: absolute;
  top: -6px;
  left: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--green);
  color: var(--paper);
  font-family: var(--font-sans);
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

.write__body { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.write__practice { flex: 1 1 520px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }

.write__pad {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  background: var(--card);
  background-image: linear-gradient(var(--line-soft) 1px, transparent 1px);
  background-size: 100% 25%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.write__guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(220px, 30vw);
  line-height: 1;
  color: var(--line);
  pointer-events: none;
  user-select: none;
}
/* Stroke order over the pad (LetterStrokes, 600 × 360 units): the letter's
   shape, a demonstration drawn stroke by stroke, and each stroke's dashed
   path, arrow and number. In guided practice a stroke is done (green), next
   (clay) or later (faint). */
.write__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.write__baseline { stroke: var(--line-strong); stroke-width: 1.5; stroke-dasharray: 6 6; }
.write__shape path { fill: none; stroke: var(--line); stroke-width: 30; stroke-linecap: round; stroke-linejoin: round; }
.write__shape circle { fill: var(--line); }
.write__demo path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 13;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 1;
  opacity: 0;
}
.write__demo circle { fill: var(--ink); opacity: 0; }
.write__demo.is-drawn path { stroke-dashoffset: 0; opacity: 1; transition: stroke-dashoffset 1s ease-in-out; }
.write__demo.is-drawn circle { opacity: 1; transition: opacity .3s ease; }
.write__demo.is-drawn circle:nth-of-type(2) { transition-delay: .25s; }
.write__demo.is-drawn circle:nth-of-type(3) { transition-delay: .5s; }
.write__order, .write__mark { --step: var(--clay); }
.write__order[data-state="done"], .write__mark[data-state="done"] { --step: var(--green); }
.write__order[data-state="later"], .write__mark[data-state="later"] { --step: var(--line-dashed); }
.write__order path { fill: none; stroke: var(--step); stroke-width: 2.5; stroke-dasharray: 7 6; stroke-linecap: round; }
.write__order polygon { fill: var(--step); }
.write__order circle { fill: none; stroke: var(--step); stroke-width: 2.5; stroke-dasharray: 4 4; }
.write__mark {
  position: absolute;
  --size: 28px;
  /* Kept inside the pad, even for dots near its edge (ي). */
  left: clamp(calc(var(--size) / 2 + 3px), var(--x), calc(100% - var(--size) / 2 - 3px));
  top: clamp(calc(var(--size) / 2 + 3px), var(--y), calc(100% - var(--size) / 2 - 3px));
  transform: translate(-50%, -50%);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: var(--step);
  border: 2.5px solid var(--card);
  color: var(--text-on-accent);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: content-box;
  pointer-events: none;
}
.write .is-hidden { display: none; }
.write__feedback {
  position: absolute;
  left: 14px;
  top: 14px;
  margin: 0;
  background: var(--green-soft);
  color: var(--green);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
}
.write__feedback.is-wrong { background: var(--clay-soft); color: var(--clay); }
@media (prefers-reduced-motion: reduce) {
  .write__demo.is-drawn path, .write__demo.is-drawn circle { transition: none; }
}

.write__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  color: var(--ink); /* stroke color, read by the writing controller */
}

.write__btn { font-weight: 600; padding: 10px 16px; }
.write__next { margin-left: auto; }
.write__watch { background: var(--clay); color: var(--text-on-accent); font-weight: 600; padding: 10px 16px; }
.write__watch:hover { background: var(--clay-hover); color: var(--text-on-accent); }

.write__info { flex: 1 1 300px; display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.write__name { font-size: 32px; line-height: 1; }
.write__count { font-size: 14px; }
.write__sound { background: var(--sand); color: var(--ink); }
.write__sound:hover { background: var(--line); color: var(--ink); }

.write__forms {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.write__form {
  background: var(--paper);
  border-radius: 12px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.write__glyph { font-size: 38px; line-height: 1.5; }
.write__form-label { font-size: 12px; color: var(--text-muted); }
.write__steps { display: flex; flex-direction: column; gap: 8px; }
.write__steps-title { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.write__step-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.write__step {
  --step: var(--clay);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1.45;
}
.write__step[data-state="next"] { background: var(--clay-soft); }
.write__step[data-state="done"] { --step: var(--green); background: var(--green-soft); }
.write__step[data-state="later"] { --step: var(--line-dashed); }
.write__step-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--step);
  color: var(--text-on-accent);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.write__hint { font-size: 13px; line-height: 1.45; color: var(--text-muted); }
.write__tip { font-size: 14px; line-height: 1.5; color: var(--text-body); }
.write__example { border-top: 1px solid var(--line); padding-top: 14px; font-size: 15px; }
.write__example-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.write__example-ar { font-size: 34px; }

@media (max-width: 600px) {
  .write__mark { --size: 22px; font-size: 12px; border-width: 2px; }
  .write__letters { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
  .write__letter { font-size: 24px; }
}
