:root {
  color-scheme: light;
  --bg: #edf0eb;
  --surface: #ffffff;
  --surface-subtle: #f6f7f3;
  --ink: #202326;
  --muted: #687076;
  --line: #d5dbd5;
  --line-strong: #bbc5bd;
  --jade: #176f67;
  --jade-dark: #105952;
  --jade-soft: #dcefe9;
  --cinnabar: #b43c32;
  --cinnabar-dark: #8f2d27;
  --gold: #9b6a18;
  --shadow: 0 18px 55px rgba(32, 35, 38, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(23, 111, 103, 0.24);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.site-main {
  min-height: 100dvh;
}

.stroke-view {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 34px clamp(18px, 4vw, 56px) 28px;
}

.stroke-header {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(390px, 0.9fr);
  gap: 18px 36px;
  align-items: end;
  margin-bottom: 22px;
}

.kicker {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stroke-header h1,
.learning-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.stroke-header h1 {
  max-width: 620px;
  font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: clamp(2rem, 4vw, 3.45rem);
  font-weight: 700;
  line-height: 1.1;
}

.hero-copy {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
}

.character-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.character-input-wrap {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
}

.character-input-wrap:focus-within {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px rgba(23, 111, 103, 0.12);
}

.character-input-wrap svg {
  width: 19px;
  color: var(--muted);
}

.character-input-wrap input {
  min-width: 0;
  height: 46px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--jade-dark);
  border-radius: 8px;
  background: var(--jade);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button:hover {
  background: var(--jade-dark);
}

.primary-button svg {
  width: 18px;
}

.input-message {
  grid-column: 2;
  min-height: 20px;
  margin: -10px 0 0;
  color: var(--jade-dark);
  font-size: 0.84rem;
}

.input-message:empty {
  display: none;
}

.input-message[data-type="error"] {
  color: var(--cinnabar-dark);
  font-weight: 700;
}

.stroke-workspace {
  display: grid;
  grid-template-columns: minmax(460px, 1.08fr) minmax(360px, 0.92fr);
  min-height: 680px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.writer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcf9;
  scroll-margin-top: 10px;
}

.writer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.character-identity {
  display: flex;
  align-items: center;
  gap: 14px;
}

.current-character {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--cinnabar);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 2rem;
  font-weight: 700;
}

.character-identity p,
.stroke-progress span {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.character-identity strong,
.stroke-progress strong {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.stroke-progress {
  text-align: right;
}

.stroke-progress strong {
  display: block;
  color: var(--jade-dark);
  font-size: 1.25rem;
}

.writer-stage-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 18px 0;
}

.writer-stage {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid #b85a50;
  background: #fffefd;
}

.rice-grid,
.writer-target,
.writer-canvas,
.writer-canvas > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.rice-grid {
  overflow: hidden;
}

.grid-line {
  position: absolute;
  display: block;
  background: rgba(180, 60, 50, 0.32);
}

.grid-horizontal {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  border-top: 1px dashed rgba(180, 60, 50, 0.4);
  background: transparent;
}

.grid-vertical {
  top: 0;
  left: 50%;
  width: 1px;
  height: 100%;
  border-left: 1px dashed rgba(180, 60, 50, 0.4);
  background: transparent;
}

.grid-diagonal-a,
.grid-diagonal-b {
  top: 50%;
  left: -21%;
  width: 142%;
  height: 1px;
  border-top: 1px dashed rgba(180, 60, 50, 0.28);
  background: transparent;
  transform: rotate(45deg);
}

.grid-diagonal-b {
  transform: rotate(-45deg);
}

.writer-target {
  z-index: 1;
}

.writer-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: rgba(255, 254, 253, 0.9);
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-mark {
  width: 28px;
  height: 28px;
  border: 2px solid var(--line);
  border-top-color: var(--cinnabar);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.playback-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.stroke-transport {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.play-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--jade);
  color: var(--jade-dark);
  background: var(--jade-soft);
}

.play-button {
  width: 50px;
  height: 50px;
  border-color: var(--jade-dark);
  background: var(--jade);
  color: #ffffff;
}

.play-button:hover {
  background: var(--jade-dark);
}

.icon-button svg {
  width: 19px;
}

.play-button svg {
  width: 22px;
}

.is-hidden {
  display: none !important;
}

.speed-control {
  display: grid;
  grid-template-columns: auto minmax(90px, 170px) 42px;
  gap: 10px;
  align-items: center;
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.speed-control > span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.speed-control svg {
  width: 17px;
}

.speed-control input {
  width: 100%;
  accent-color: var(--jade);
}

.speed-control output {
  color: var(--ink);
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.learning-panel {
  min-width: 0;
  padding: 24px;
  overflow: hidden;
}

.learning-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.learning-heading h2 {
  font-size: 1.4rem;
}

.learning-heading > span {
  color: var(--jade-dark);
  font-size: 0.9rem;
  font-weight: 800;
}

.sequence-hint {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.stroke-sequence {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-height: 590px;
  padding-right: 4px;
  overflow-y: auto;
}

.stroke-card {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(45deg, transparent 49.5%, rgba(180, 60, 50, 0.1) 50%, transparent 50.5%),
    linear-gradient(-45deg, transparent 49.5%, rgba(180, 60, 50, 0.1) 50%, transparent 50.5%),
    #ffffff;
  cursor: pointer;
}

.stroke-card:hover {
  border-color: #d09a94;
  background-color: #fffafa;
}

.stroke-card.is-active {
  border-color: var(--cinnabar);
  box-shadow: inset 0 0 0 1px var(--cinnabar);
}

.stroke-card.is-complete .stroke-number {
  background: var(--jade);
}

.stroke-number {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
}

.stroke-preview,
.stroke-preview svg {
  display: block;
  width: 100%;
  height: 100%;
}

.coverage-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.coverage-note svg {
  width: 17px;
  flex: 0 0 auto;
  color: var(--jade);
}

@media (max-width: 1100px) {
  .stroke-workspace {
    grid-template-columns: minmax(400px, 1fr) minmax(300px, 0.75fr);
  }

  .stroke-sequence {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .playback-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .speed-control {
    grid-template-columns: auto minmax(100px, 1fr) 42px;
  }
}

@media (max-width: 860px) {
  .stroke-view {
    padding: 16px 14px 22px;
  }

  .stroke-header {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 10px;
    margin-bottom: 12px;
  }

  .stroke-header > div:first-child {
    display: grid;
    gap: 4px;
  }

  .stroke-header h1 {
    font-family: inherit;
    font-size: 1.2rem;
    line-height: 1.25;
  }

  .hero-copy,
  .stroke-header .kicker {
    display: none;
  }

  .character-search {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .input-message {
    grid-column: 1;
    margin-top: -8px;
  }

  .stroke-workspace {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .writer-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }

  .writer-stage-wrap {
    padding: 12px 0;
  }

  .writer-stage {
    width: min(100%, 520px, clamp(260px, calc(100dvh - 260px), 520px));
    min-width: 0;
  }

  .playback-controls {
    align-items: center;
    flex-direction: row;
    gap: 16px;
    padding-top: 14px;
  }

  .speed-control {
    grid-template-columns: auto minmax(110px, 1fr) 42px;
    flex: 1 1 280px;
  }

  .stroke-transport {
    flex: 0 0 auto;
  }

  .stroke-sequence {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-height: none;
  }
}

@media (max-width: 600px) {
  .stroke-view {
    padding: 14px 10px 18px;
  }

  .kicker {
    margin-bottom: 5px;
  }

  .stroke-header h1 {
    font-size: 1.08rem;
  }

  .primary-button {
    width: auto;
    min-width: 116px;
    padding: 0 12px;
  }

  .character-input-wrap,
  .primary-button {
    min-height: 44px;
  }

  .character-input-wrap input {
    height: 42px;
  }

  .writer-panel,
  .learning-panel {
    padding: 12px;
  }

  .writer-meta {
    align-items: start;
  }

  .current-character {
    width: 42px;
    height: 42px;
    font-size: 1.6rem;
  }

  .character-identity {
    gap: 10px;
  }

  .character-identity p,
  .stroke-progress span {
    font-size: 0.74rem;
  }

  .character-identity strong,
  .stroke-progress strong {
    font-size: 0.92rem;
  }

  .stroke-progress strong {
    font-size: 1.08rem;
  }

  .writer-stage-wrap {
    padding: 10px 0;
  }

  .writer-stage {
    width: min(100%, clamp(170px, calc(100dvh - 348px), 420px));
    min-width: 0;
  }

  .playback-controls {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding-top: 12px;
  }

  .stroke-transport {
    justify-content: center;
  }

  .speed-control {
    grid-template-columns: 1fr 42px;
    flex-basis: auto;
  }

  .speed-control input {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .stroke-sequence {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .coverage-note {
    align-items: flex-start;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .loading-mark {
    animation-duration: 1.8s;
  }
}
