:root {
  color-scheme: light;
  --bg: #f2fbf7;
  --panel: #ffffff;
  --panel-soft: #f8fffb;
  --panel-strong: #e8f7ef;
  --ink: #16312d;
  --muted: #647a76;
  --line: #d7ebe4;
  --accent: #21a67a;
  --accent-dark: #147a65;
  --accent-blue: #3187d8;
  --accent-blue-soft: #eaf5ff;
  --sun: #f6b84b;
  --warn: #d94f3d;
  --ok: #1d9a5f;
  --key: #31546a;
  --key-text: #fbfffd;
  --shadow: 0 18px 45px rgba(40, 104, 88, 0.14);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 10%, rgba(142, 225, 188, 0.32), transparent 30%),
    radial-gradient(circle at 96% 4%, rgba(173, 216, 255, 0.46), transparent 28%),
    linear-gradient(180deg, #fefffd 0%, var(--bg) 100%);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 92px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 46px);
}

h2 {
  font-size: 22px;
}

.topbar__meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar__meta span,
.content-note,
.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
}

.topbar__meta span {
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar,
.practice-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.sidebar {
  border-radius: 8px;
  padding: 18px;
  position: static;
}

.sidebar__intro p,
.content-note span,
.brand-strip span,
.hint-text,
.typing-status {
  color: var(--muted);
}

.sidebar__intro p {
  margin: 8px 0 18px;
  line-height: 1.65;
  font-size: 14px;
}

.course-list {
  display: grid;
  gap: 10px;
  max-height: 170px;
  overflow-y: auto;
  padding-right: 3px;
}

.course-button {
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.course-button:hover {
  border-color: rgba(33, 166, 122, 0.45);
}

.course-button.is-active {
  background: linear-gradient(135deg, var(--panel-strong), var(--accent-blue-soft));
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.course-button.is-complete {
  border-color: rgba(29, 154, 95, 0.45);
}

.course-button__title,
.course-button__meta {
  display: block;
}

.course-button__title {
  font-weight: 800;
  margin-bottom: 5px;
}

.course-button__meta {
  color: var(--muted);
  font-size: 12px;
}

.content-note {
  display: grid;
  gap: 6px;
  margin-top: 18px;
  padding: 13px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  background: linear-gradient(135deg, #fff, #f2fbf7);
}

.lesson-block {
  margin-top: 18px;
}

.lesson-block h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.lesson-list {
  display: grid;
  gap: 8px;
  max-height: 100px;
  overflow-y: auto;
  padding-right: 3px;
}

.lesson-button {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  text-align: left;
  font-size: 13px;
}

.lesson-button.is-active {
  border-color: var(--accent-blue);
  background: var(--accent-blue-soft);
  color: #17466e;
}

.lesson-button.is-complete::after {
  content: "完成";
  float: right;
  color: var(--ok);
  font-weight: 800;
}

.leaderboard-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.leaderboard-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.leaderboard-block h3 {
  margin: 0;
  font-size: 14px;
}

.leaderboard-block__header button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.leaderboard-block label,
.leaderboard-block p {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.leaderboard-block label {
  margin: 10px 0 5px;
}

.leaderboard-block input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
  background: var(--panel-soft);
  color: var(--ink);
}

.leaderboard-block input:focus {
  border-color: var(--accent);
}

.leaderboard-block p {
  margin: 7px 0 10px;
  line-height: 1.5;
}

.leaderboard-list {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 24px;
}

.leaderboard-list li {
  padding: 8px 9px;
  border-radius: 7px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}

.leaderboard-list strong,
.leaderboard-list span {
  display: block;
}

.leaderboard-list strong {
  color: var(--ink);
  margin-bottom: 2px;
}

.leaderboard-list__empty {
  list-style: none;
  margin-left: -24px;
  text-align: center;
}

.practice-panel {
  border-radius: 8px;
  padding: 22px;
}

.practice-header,
.brand-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.lesson-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-button,
.brand-strip button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
}

.ghost-button {
  color: var(--ink);
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.ghost-button:hover {
  border-color: var(--accent);
  background: var(--panel-strong);
  color: var(--accent-dark);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 22px 0;
}

.stats-grid div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, var(--panel-soft));
}

.stats-grid span,
.stats-grid small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats-grid strong {
  display: block;
  margin: 5px 0 2px;
  font-size: 26px;
  line-height: 1;
}

.typing-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
}

.typing-card.is-complete {
  border-color: rgba(29, 154, 95, 0.45);
  box-shadow: 0 0 0 4px rgba(29, 154, 95, 0.1);
}

.typing-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
}

.progress-track {
  height: 8px;
  margin-bottom: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5f1ee;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-blue));
  transition: width 160ms ease;
}

.target-text {
  min-height: 92px;
  max-height: 390px;
  padding: 18px;
  border-radius: 8px;
  background: #1d3f4a;
  color: #f3fffb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.65;
  overflow-wrap: anywhere;
  overflow: auto;
  white-space: pre-wrap;
  tab-size: 2;
}

.typing-card.is-multiline .target-text {
  min-height: 180px;
  font-size: clamp(15px, 2vw, 20px);
  line-height: 1.6;
}

.char {
  border-radius: 4px;
  padding: 1px 1px;
}

.char.is-done {
  color: #aef2c8;
}

.char.is-current {
  background: var(--sun);
  color: #20312d;
}

.char.is-error {
  background: var(--warn);
  color: #fff;
}

.char.is-linebreak {
  color: #82a8af;
  font-size: 0.72em;
  user-select: none;
}

.char.is-linebreak.is-current {
  color: #20312d;
}

.typing-input {
  width: 100%;
  margin-top: 14px;
  min-height: 54px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 13px 15px;
  outline: none;
  color: var(--ink);
  background: var(--panel-soft);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.6;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.typing-card.is-multiline .typing-input {
  min-height: 160px;
}

.typing-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(33, 166, 122, 0.12);
}

.hint-text {
  min-height: 24px;
  margin-top: 12px;
  font-size: 14px;
}

.keyboard {
  margin: 20px auto;
  display: grid;
  gap: 7px;
  width: min(820px, 100%);
  padding: 10px;
  border: 1px solid rgba(49, 84, 106, 0.22);
  border-radius: 10px;
  background: #dce8e8;
  box-shadow: inset 0 2px 5px rgba(22, 49, 45, 0.12);
}

.key-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.key {
  display: grid;
  place-items: center;
  flex: 1 1 0;
  min-width: 0;
  height: 46px;
  border-radius: 6px;
  padding: 4px 2px 6px;
  background: var(--key);
  color: var(--key-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 800;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

.key__secondary,
.key__primary {
  display: block;
  line-height: 1;
}

.key__secondary {
  align-self: start;
  font-size: 10px;
}

.key__primary {
  align-self: end;
  font-size: 14px;
}

.key--single .key__secondary {
  display: none;
}

.key--single .key__primary {
  align-self: center;
}

.key--control {
  font-size: clamp(8px, 1.2vw, 11px);
  white-space: nowrap;
}

.key--u125 {
  flex-grow: 1.25;
}

.key--u150 {
  flex-grow: 1.5;
}

.key--u175 {
  flex-grow: 1.75;
}

.key--u200 {
  flex-grow: 2;
}

.key--u225 {
  flex-grow: 2.25;
}

.key--u275 {
  flex-grow: 2.75;
}

.key--u625 {
  flex-grow: 6.25;
}

.key.is-active {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.brand-strip {
  margin-top: 20px;
  padding: 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--panel-strong), #fff7e6);
  border: 1px solid rgba(33, 166, 122, 0.22);
}

.brand-strip > div:first-child {
  display: grid;
  gap: 4px;
}

.brand-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.brand-strip button {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-blue));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 20px rgba(49, 135, 216, 0.2);
}

.brand-strip button:hover {
  background: var(--accent-dark);
}

.brand-strip .brand-actions .ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  box-shadow: none;
}

.brand-strip .brand-actions .ghost-button:hover {
  border-color: var(--accent);
  background: #fff;
  color: var(--accent-dark);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.info-grid div {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.info-grid strong {
  color: var(--accent-dark);
}

.info-grid span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.result-dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(22, 49, 45, 0.22);
}

.result-dialog::backdrop {
  background: rgba(22, 49, 45, 0.32);
  backdrop-filter: blur(4px);
}

.result-dialog__body {
  padding: 24px;
  background: linear-gradient(180deg, #fff, var(--panel-soft));
}

.result-dialog__body > p:last-of-type {
  color: var(--muted);
  line-height: 1.7;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 12px;
}

.result-summary div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.result-summary strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.dialog-actions button {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 16px;
}

.dialog-actions button:last-child {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-blue));
  color: #fff;
  font-weight: 800;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 14px 0;
  }

  .topbar,
  .practice-header,
  .brand-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar__meta,
  .lesson-actions {
    justify-content: flex-start;
  }

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

  .sidebar {
    position: static;
    max-height: none;
  }

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

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

  .keyboard {
    gap: 5px;
    padding: 7px;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    height: 42px;
  }
}

@media (max-width: 520px) {
  .practice-panel,
  .sidebar,
  .typing-card {
    padding: 14px;
  }

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

  .result-summary {
    grid-template-columns: 1fr;
  }

  .stats-grid strong {
    font-size: 22px;
  }

  .target-text {
    font-size: 20px;
  }

  .typing-card.is-multiline .target-text {
    font-size: 14px;
  }

  .key-row {
    gap: 5px;
  }

  .keyboard {
    display: none;
  }
}
