/* Hanzi Stroke Order Canvas (米字格) */
.stroke-dialog {
  width: 780px;
  max-width: min(780px, calc(100vw - 28px));
}
.stroke-dialog-shell {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.stroke-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 0;
}
.stroke-header-copy .dialog-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--jade);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.stroke-header-copy .dialog-title {
  font-size: 20px;
  margin: 0;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.stroke-hanzi-title {
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  font-family: 'Noto Sans SC', serif;
  line-height: 1.1;
}
.stroke-pinyin-title,
.stroke-pinyin-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 16px;
  color: var(--jade);
  font-weight: 800;
  background: var(--soft);
  border: 1.5px solid var(--jade);
  padding: 4px 12px;
  border-radius: 999px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}
.stroke-pinyin-badge:hover {
  background: var(--jade);
  color: #ffffff;
  transform: translateY(-1px);
}
.stroke-meaning-title {
  font-size: 14.5px;
  color: var(--text);
  font-weight: 600;
}
.stroke-pin-toggle-btn.is-active {
  background: var(--soft);
  border-color: var(--jade);
  color: var(--jade);
  font-weight: 700;
}
/* Override global .hide-pinyin inside #stroke-dialog so learners always see Pinyin unless toggled locally */
.hide-pinyin #stroke-dialog:not(.is-pinyin-hidden) .stroke-pinyin-title {
  display: inline-flex !important;
}
.hide-pinyin #stroke-dialog:not(.is-pinyin-hidden) .stroke-tab-pinyin {
  display: inline !important;
}
.hide-pinyin #stroke-dialog:not(.is-pinyin-hidden) .stroke-visual-py {
  display: block !important;
}
#stroke-dialog.is-pinyin-hidden .pinyin {
  display: none !important;
}
.stroke-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.stroke-char-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.stroke-char-tab {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 14px;
  font-size: 18px;
  font-family: 'Noto Sans SC', serif;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s ease, background-color .2s ease, color .2s ease;
}
.stroke-tab-pinyin {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--jade);
}
.stroke-char-tab.is-active .stroke-tab-pinyin {
  color: #ffffff;
}
.stroke-char-tab:hover {
  border-color: var(--jade);
  background: var(--soft);
}
.stroke-char-tab.is-active {
  background: var(--jade);
  color: #fff;
  border-color: var(--jade);
  box-shadow: 0 2px 8px rgba(8,127,109,0.25);
}
.stroke-practice-body {
  display: grid;
  grid-template-columns: 312px 1fr;
  gap: 24px;
  align-items: start;
  margin-top: 4px;
}
.stroke-stage-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: 100%;
}
.mizige-container {
  position: relative;
  width: 280px;
  height: 280px;
  flex-shrink: 0;
  background: #fffcf5;
  border: 2px solid #e27d60;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 6px 20px rgba(24,61,54,0.08);
  margin: 0 auto;
  user-select: none;
  touch-action: none;
}
.mizige-container > .stroke-mnemonic-box {
  display: none !important;
}
.mizige-grid-bg {
  position: absolute;
  inset: 0;
  width: 280px;
  height: 280px;
  color: #f0a894;
  pointer-events: none;
  opacity: 0.88;
}
.mizige-ghost {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 210px;
  line-height: 1;
  font-family: 'Noto Sans SC', 'Kaiti', 'STKaiti', serif;
  color: #d1d5db;
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
  transition: opacity .2s ease;
}
.mizige-ghost.is-hidden,
.mizige-ghost.has-vector-ghost {
  opacity: 0;
}
.stroke-ghost-group {
  color: #d3ddd8;
  opacity: 0.78;
  transition: opacity .2s ease;
}
.stroke-ghost-group.is-hidden {
  opacity: 0;
  display: none;
}
.stroke-ghost-group.is-faint {
  opacity: 0.28;
}
.stroke-ghost-path {
  fill: currentColor;
}
.mizige-canvas {
  position: absolute;
  inset: 0;
  width: 280px;
  height: 280px;
  cursor: crosshair;
  touch-action: none;
  z-index: 2;
}
.mizige-stroke-player {
  position: absolute;
  inset: 0;
  width: 280px;
  height: 280px;
  pointer-events: none;
  z-index: 1;
}
.mizige-stroke-player.is-hidden {
  display: none;
}
.mizige-ghost.is-faint {
  opacity: 0.12;
}
.stroke-hint-outline {
  opacity: 0.92;
  transition: opacity .18s ease;
}
.stroke-hint-outline.is-hidden {
  opacity: 0;
  display: none;
}
.stroke-hint-outline.is-flashing {
  opacity: 1;
  fill: rgba(220, 38, 38, 0.34);
  stroke: #dc2626;
  stroke-width: 14px;
}
.stroke-hint-median {
  opacity: 0.95;
  transition: opacity .18s ease;
}
.stroke-hint-median.is-hidden {
  opacity: 0;
  display: none;
}
.stroke-hint-median.is-flashing {
  stroke: #dc2626;
  stroke-width: 20px;
}
.stroke-start-dot {
  fill: #e27d60;
  stroke: #fffcf5;
  stroke-width: 12px;
  opacity: 0.95;
  pointer-events: none;
}
.stroke-start-dot.is-hidden {
  display: none;
}
.stroke-pulse-ring {
  pointer-events: none;
  opacity: 0.72;
  animation: strokePulseRing 1.5s ease-out infinite;
}
.stroke-pulse-ring.is-hidden,
.stroke-order-badge.is-hidden,
.stroke-brush-cursor.is-hidden {
  display: none;
  opacity: 0;
}
.stroke-order-badge {
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(8, 127, 109, 0.35));
}
.stroke-order-text {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: 36px;
  font-weight: 800;
  user-select: none;
}
.stroke-brush-cursor {
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(24, 61, 54, 0.32));
}
@keyframes strokePulseRing {
  0% {
    stroke-width: 10px;
    opacity: 0.85;
  }
  100% {
    stroke-width: 2px;
    opacity: 0.15;
  }
}
@media (prefers-reduced-motion: reduce) {
  .stroke-pulse-ring {
    animation: none;
  }
}
.stroke-mnemonic-box {
  position: static;
  width: 280px;
  max-width: 100%;
  flex-shrink: 0;
  background: var(--cream);
  border: 1px solid rgba(183,119,33,0.32);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.stroke-mnemonic-box[hidden] {
  display: none !important;
}
.stroke-mnemonic-radicals {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}
.stroke-mnemonic-rad-text {
  color: var(--ink);
  font-weight: 600;
}
.stroke-mnemonic-story {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink);
}
.stroke-mnemonic-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.stroke-mnemonic-badge {
  font-size: 11px;
  font-weight: 700;
  color: #7c5112;
}
.stroke-mnemonic-radical {
  font-size: 11px;
  font-weight: 700;
  color: var(--jade);
  background: var(--soft);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.stroke-mnemonic-text {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
}
.stroke-controls-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stroke-mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.stroke-mode-btn {
  min-height: 36px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}
.stroke-mode-btn.is-active {
  background: var(--jade);
  color: #fff;
  border-color: var(--jade);
}
.stroke-anim-section {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stroke-anim-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.stroke-play-btn {
  flex: 1;
  font-weight: 650;
  min-width: 120px;
}
.stroke-step-btn {
  min-height: 36px;
  min-width: 38px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.stroke-speed-btn {
  font-size: 11px;
  padding: 6px 10px;
  min-height: 36px;
  white-space: nowrap;
}
.stroke-anim-progress {
  font-size: 11.5px;
  color: var(--jade);
  font-weight: 600;
  line-height: 1.4;
}
.stroke-stat-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
}
.stroke-stat-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.stroke-stat-badge strong {
  font-size: 20px;
  color: var(--jade);
  font-weight: 700;
}
.stroke-accuracy-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--jade);
}
.stroke-toggle-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stroke-toggle-group .btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 12px;
}
.stroke-color-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}
.color-dots {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.color-dot:hover {
  transform: scale(1.15);
}
.color-dot.is-active {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--jade);
  transform: scale(1.1);
}
.stroke-rules-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stroke-rules-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.stroke-rules-box strong {
  color: var(--ink);
  font-size: 12.5px;
}
.stroke-rule-return-btn {
  border: 1px solid var(--jade);
  background: var(--soft);
  color: var(--jade);
  border-radius: 8px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.stroke-active-type-bar {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11.5px;
  color: var(--text);
}
.stroke-active-type-bar strong {
  color: var(--jade);
  font-size: 11.5px;
}
.stroke-rules-box ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.stroke-rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease, color .18s ease;
}
.stroke-rule-item:hover {
  border-color: var(--jade);
  color: var(--ink);
}
.stroke-rule-item.is-active-rule {
  border-color: var(--jade);
  background: var(--soft);
  color: var(--ink);
  font-weight: 600;
}
.stroke-rule-text {
  font-size: 11px;
  line-height: 1.3;
}
.stroke-rule-demo-chip {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--jade);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.stroke-rule-item.is-active-rule .stroke-rule-demo-chip {
  background: var(--jade);
  border-color: var(--jade);
  color: #fff;
}
.hanzi-load-more-wrap {
  text-align: center;
  margin-top: 22px;
}
.stroke-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.stroke-tip {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.hanzi-card.is-mastered-stroke {
  border-color: var(--jade);
  box-shadow: 0 4px 14px rgba(8,127,109,0.12);
}
.hanzi-card.is-mastered-stroke .hanzi-write-btn {
  background: var(--soft);
  color: var(--jade);
  border-color: var(--jade);
}

/* Dark mode for stroke dialog */
html[data-theme=dark] .mizige-container {
  background: #1e2825;
  border-color: #634336;
}
html[data-theme=dark] .mizige-grid-bg {
  color: #7a4f41;
  opacity: 0.65;
}
html[data-theme=dark] .mizige-ghost {
  color: #436254;
  opacity: 0.6;
}
html[data-theme=dark] .mizige-ghost.is-hidden,
html[data-theme=dark] .mizige-ghost.has-vector-ghost {
  opacity: 0;
}
html[data-theme=dark] .stroke-ghost-group {
  color: #2f493e;
  opacity: 0.82;
}
html[data-theme=dark] .stroke-mnemonic-box {
  background: #192b24;
  border-color: #2f4d40;
}
html[data-theme=dark] .stroke-mnemonic-badge {
  color: #eebd5b;
}
html[data-theme=dark] .stroke-mnemonic-radicals {
  color: #a8c7b8;
}
html[data-theme=dark] .stroke-mnemonic-rad-text,
html[data-theme=dark] .stroke-mnemonic-story,
html[data-theme=dark] .stroke-mnemonic-text {
  color: #e6f4ee;
}
html[data-theme=dark] .color-dot.is-active {
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px #82cfa8;
}
html[data-theme=dark] .stroke-char-tab {
  background: #192e26;
  border-color: #2b4135;
  color: #bbcec1;
}
html[data-theme=dark] .stroke-char-tab.is-active {
  background: #177d5f;
  border-color: #177d5f;
  color: #fff;
}
html[data-theme=dark] .stroke-rules-box {
  background: #152720;
  border-color: #2b4135;
}
html[data-theme=dark] .stroke-anim-section {
  background: #152720;
  border-color: #2b4135;
}
html[data-theme=dark] .stroke-anim-progress {
  color: #8bd6bc;
}

@media (max-width: 680px) {
  .stroke-dialog-shell {
    padding: 16px 14px;
    gap: 10px;
  }
  .stroke-practice-body {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 12px;
  }
  .stroke-controls-sidebar {
    width: 100%;
    gap: 8px;
  }
  .stroke-rules-box {
    padding: 8px 10px;
    font-size: 11px;
  }
  .stroke-rules-box ul {
    grid-template-columns: 1fr 1fr;
    gap: 2px 8px;
  }
  .stroke-footer {
    position: sticky;
    bottom: 0;
    background: var(--paper);
    z-index: 5;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    text-align: left;
    gap: 10px;
    padding: 10px 0 2px;
  }
  .stroke-tip {
    font-size: 11px;
  }
}
