:root {
  --ink: #172033;
  --muted: #697386;
  --paper: #ffffff;
  --canvas: #f3f6fb;
  --blue: #2357d8;
  --blue-dark: #163ea9;
  --blue-soft: #eaf0ff;
  --red: #d6453d;
  --red-dark: #b92f29;
  --red-soft: #fff0ed;
  --line: #dfe5ef;
  --line-strong: #cdd6e5;
  --shadow: 0 18px 50px rgba(25, 42, 74, 0.1);
  --shadow-soft: 0 8px 24px rgba(25, 42, 74, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  color-scheme: light;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(35, 87, 216, 0.08), transparent 28rem),
    radial-gradient(circle at 92% 12%, rgba(214, 69, 61, 0.07), transparent 24rem),
    var(--canvas);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(35, 87, 216, 0.28);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 50;
  left: 16px;
  top: 16px;
  padding: 10px 14px;
  color: #fff;
  background: var(--blue-dark);
  border-radius: 8px;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.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;
}

.page-shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 96px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-seal {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  color: #fff;
  background: var(--red);
  border-radius: 13px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 7px 16px rgba(214, 69, 61, 0.23);
  font-family: KaiTi, STKaiti, serif;
  font-size: 29px;
  line-height: 1;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1.25rem;
  letter-spacing: 0.14em;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
}

.header-note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #506078;
  font-size: 0.875rem;
  font-weight: 600;
}

.note-mark {
  width: 8px;
  height: 8px;
  background: var(--blue);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(35, 87, 216, 0.1);
}

.search-section {
  display: grid;
  grid-template-columns: minmax(230px, 0.72fr) minmax(480px, 1.28fr);
  column-gap: 48px;
  align-items: end;
  padding: 28px 40px 30px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(248, 251, 255, 0.94));
  border: 1px solid rgba(205, 214, 229, 0.86);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  position: relative;
  overflow: hidden;
}

.search-section::after {
  content: "";
  position: absolute;
  right: -72px;
  top: -92px;
  width: 240px;
  height: 240px;
  border: 1px solid rgba(35, 87, 216, 0.1);
  border-radius: 50%;
  box-shadow: inset 0 0 0 28px rgba(35, 87, 216, 0.025), inset 0 0 0 56px rgba(35, 87, 216, 0.02);
  pointer-events: none;
}

.search-heading,
.search-form,
.input-help,
.input-error,
.quick-picks {
  position: relative;
  z-index: 1;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.search-heading h1 {
  margin: 0;
  font-family: KaiTi, STKaiti, "Songti SC", serif;
  font-size: clamp(2rem, 4.2vw, 3.35rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.02em;
}

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

.input-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  width: 23px;
  height: 23px;
  color: #79859a;
  transform: translateY(-50%);
  stroke: currentColor;
  stroke-width: 1.8;
  pointer-events: none;
}

#character-input {
  width: 100%;
  height: 62px;
  padding: 0 54px 0 54px;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line-strong);
  border-radius: 16px;
  font-family: KaiTi, STKaiti, serif;
  font-size: 1.75rem;
  font-weight: 700;
  box-shadow: inset 0 2px 5px rgba(25, 42, 74, 0.035);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

#character-input:hover {
  border-color: #aab8ce;
}

#character-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(35, 87, 216, 0.11);
  outline: none;
}

.clear-button {
  position: absolute;
  right: 9px;
  top: 9px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: #738096;
  background: transparent;
  border: 0;
  border-radius: 12px;
}

.clear-button:hover {
  color: var(--ink);
  background: #f1f4f8;
}

.clear-button svg {
  width: 20px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-button,
.primary-control,
.icon-button {
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
  transition: background-color 180ms ease, color 180ms ease, box-shadow 180ms ease, transform 180ms var(--ease);
}

.search-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 148px;
  height: 62px;
  padding: 0 22px;
  color: #fff;
  background: var(--blue);
  box-shadow: 0 10px 22px rgba(35, 87, 216, 0.23);
}

.search-button:hover,
.primary-control:hover {
  background: var(--blue-dark);
  box-shadow: 0 12px 26px rgba(35, 87, 216, 0.26);
}

.search-button:active,
.primary-control:active,
.icon-button:active,
.quick-picks button:active {
  transform: translateY(1px);
}

.search-button svg,
.primary-control svg,
.icon-button svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.input-help,
.input-error {
  grid-column: 2;
  margin: 8px 0 0 2px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.input-error {
  color: var(--red-dark);
  font-weight: 600;
}

.quick-picks {
  grid-column: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.quick-picks span {
  margin-right: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.quick-picks button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #3f4c62;
  background: #f0f4fa;
  border: 1px solid transparent;
  border-radius: 11px;
  font-family: KaiTi, STKaiti, serif;
  font-size: 1.125rem;
  font-weight: 700;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.quick-picks button:hover {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #c9d7ff;
}

.learning-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 24px;
  margin-top: 24px;
}

.card {
  min-width: 0;
  background: var(--paper);
  border: 1px solid rgba(205, 214, 229, 0.88);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.writing-card {
  padding: 30px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.card h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.25;
}

.stroke-count {
  padding: 8px 13px;
  color: var(--red-dark);
  background: var(--red-soft);
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
}

.writer-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 390px);
  aspect-ratio: 1;
  margin: 26px auto 24px;
  background: #fffefd;
  border: 2px solid rgba(214, 69, 61, 0.42);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: inset 0 0 34px rgba(214, 69, 61, 0.035);
}

.rice-grid,
#character-target,
.writer-fallback,
.loading-state {
  position: absolute;
  inset: 0;
}

.rice-grid span {
  position: absolute;
  display: block;
  opacity: 0.45;
}

.grid-horizontal {
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px dashed var(--red);
}

.grid-vertical {
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px dashed var(--red);
}

.grid-diagonal {
  left: -21%;
  top: 50%;
  width: 142%;
  border-top: 1px dashed rgba(214, 69, 61, 0.62);
}

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

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

#character-target {
  display: grid;
  place-items: center;
  z-index: 2;
}

#character-target svg {
  width: 100%;
  height: 100%;
}

.writer-fallback {
  z-index: 2;
  display: grid;
  place-items: center;
  color: #202735;
  font-family: KaiTi, STKaiti, serif;
  font-size: clamp(9rem, 21vw, 16rem);
  line-height: 1;
}

.loading-state {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #667188;
  background: rgba(255, 254, 253, 0.88);
  font-size: 0.875rem;
  transition: opacity 200ms ease;
}

.loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(35, 87, 216, 0.18);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

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

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

.playback-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 110px;
  color: #526078;
  font-size: 0.875rem;
  font-weight: 600;
}

.status-dot {
  width: 9px;
  height: 9px;
  background: #8290a8;
  border-radius: 50%;
}

.playback-status.is-playing .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(214, 69, 61, 0.11);
}

.playback-status.is-complete .status-dot {
  background: var(--blue);
}

.playback-actions {
  display: flex;
  gap: 10px;
}

.icon-button,
.primary-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
}

.icon-button {
  color: #3f4d63;
  background: #eef2f7;
}

.icon-button:hover,
.icon-button[aria-pressed="true"] {
  color: var(--blue);
  background: var(--blue-soft);
}

.primary-control {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(35, 87, 216, 0.18);
}

.details-card {
  padding: 32px;
}

.character-heading {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.character-badge {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  flex: 0 0 78px;
  color: var(--red-dark);
  background: var(--red-soft);
  border: 1px solid rgba(214, 69, 61, 0.16);
  border-radius: 20px;
  font-family: KaiTi, STKaiti, serif;
  font-size: 3.25rem;
  font-weight: 700;
  line-height: 1;
}

.alternate-pinyin {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 24px 0 0;
  padding: 0;
  background: #f5f7fb;
  border: 1px solid #e6eaf1;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.fact-grid div {
  min-width: 0;
  padding: 16px 14px;
  text-align: center;
}

.fact-grid div + div {
  border-left: 1px solid #e2e7f0;
}

.fact-grid dt {
  color: var(--muted);
  font-size: 0.8125rem;
}

.fact-grid dd {
  margin: 5px 0 0;
  color: #29364c;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.word-section {
  margin-top: 27px;
}

.word-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}

.word-heading h3 {
  margin: 0;
  font-size: 1.0625rem;
}

.word-heading span {
  color: var(--muted);
  font-size: 0.75rem;
}

.chip-list,
.idiom-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip-list li {
  padding: 9px 14px;
  color: #2d405f;
  background: var(--blue-soft);
  border: 1px solid #d9e3ff;
  border-radius: 10px;
  font-size: 0.9375rem;
  font-weight: 600;
}

.idiom-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.idiom-list li {
  position: relative;
  padding: 13px 16px 13px 34px;
  color: #334059;
  background: #fff9f7;
  border: 1px solid #f1dedb;
  border-radius: 12px;
  font-family: KaiTi, STKaiti, serif;
  font-size: 1.0625rem;
  font-weight: 700;
}

.idiom-list li::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 50%;
  width: 7px;
  height: 7px;
  background: var(--red);
  border-radius: 2px;
  transform: translateY(-50%) rotate(45deg);
}

.empty-copy {
  width: 100%;
  color: var(--muted) !important;
  background: #f7f8fa !important;
  border-color: #e6e9ef !important;
  font-family: inherit !important;
  font-size: 0.875rem !important;
  font-weight: 500 !important;
}

.empty-copy::before {
  display: none;
}

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 4px 38px;
  color: #707b8e;
  font-size: 0.75rem;
}

footer p {
  margin: 0;
}

@media (max-width: 920px) {
  .search-section {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .search-form,
  .input-help,
  .input-error,
  .quick-picks {
    grid-column: 1;
  }

  .learning-grid {
    grid-template-columns: 1fr;
  }

  .writer-stage {
    max-width: 420px;
  }
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100% - 28px, 1180px);
  }

  .site-header {
    min-height: 78px;
  }

  .brand-seal {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border-radius: 11px;
    font-size: 25px;
  }

  .brand small,
  .header-note {
    display: none;
  }

  .search-section {
    padding: 24px 20px;
    border-radius: 20px;
  }

  .eyebrow {
    font-size: 0.75rem;
    letter-spacing: 0.07em;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  #character-input,
  .search-button {
    height: 56px;
  }

  .search-button {
    width: 100%;
  }

  .quick-picks {
    margin-top: 10px;
  }

  .card,
  .search-section {
    border-radius: 20px;
  }

  .writing-card,
  .details-card {
    padding: 22px 18px;
  }

  .writer-stage {
    margin-top: 20px;
    border-radius: 14px;
  }

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

  .playback-actions {
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
  }

  .icon-button,
  .primary-control {
    padding-inline: 10px;
  }

  .character-heading {
    gap: 14px;
  }

  .character-badge {
    width: 68px;
    height: 68px;
    flex-basis: 68px;
    border-radius: 17px;
    font-size: 2.8rem;
  }

  .fact-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .fact-grid div:nth-child(3) {
    border-left: 0;
  }

  .fact-grid div:nth-child(n + 3) {
    border-top: 1px solid #e2e7f0;
  }

  .idiom-list {
    grid-template-columns: 1fr;
  }

  footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
