:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f1f4f7;
  --ink: #1c2229;
  --muted: #6d7782;
  --line: #d9e0e6;
  --blue: #2468d8;
  --blue-soft: #e8f0ff;
  --green: #1e7d57;
  --green-soft: #e7f5ee;
  --red: #c4473d;
  --red-soft: #fdebea;
  --amber: #9b681c;
  --amber-soft: #fff3dd;
  --shadow: 0 18px 48px rgba(31, 42, 55, 0.12);
  --small-shadow: 0 10px 28px rgba(31, 42, 55, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    Arial,
    sans-serif;
  letter-spacing: 0;
}

body {
  padding-left: 176px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

button:not(:disabled) {
  cursor: pointer;
}

button:focus-visible,
.click-word:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 104, 216, 0.22);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  width: 176px;
  min-height: 100vh;
  padding: 18px 12px;
  background: rgba(255, 255, 255, 0.9);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 20;
}

.brand-title {
  font-size: 20px;
  font-weight: 780;
  margin: 0;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-metrics {
  display: grid;
  gap: 8px;
  align-items: stretch;
}

.top-chip {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  justify-content: space-between;
  white-space: nowrap;
}

.top-chip-label {
  color: var(--muted);
  font-size: 12px;
}

.top-chip-value {
  font-size: 13px;
}

.current-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 10px;
  display: grid;
  gap: 5px;
}

.current-card-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.current-card-main {
  font-size: 14px;
  font-weight: 780;
  line-height: 1.25;
}

.current-card-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.view-switch {
  height: auto;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  display: grid;
  gap: 3px;
}

.view-button {
  height: 32px;
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.view-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 5px rgba(31, 42, 55, 0.12);
}

.study-shell {
  width: min(760px, calc(100vw - 220px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.study-panel,
.manage-panel,
.loading-panel,
.error-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.study-panel {
  min-height: 440px;
  display: grid;
  grid-template-rows: minmax(140px, auto) auto auto;
}

.unit-pill,
.tiny,
.queue-meta,
.recent-meta {
  color: var(--muted);
  font-size: 12px;
}

.unit-pill {
  text-align: right;
}

.question-body {
  padding: 20px 24px 8px;
  display: grid;
  gap: 12px;
  align-content: center;
}

.prompt-word {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 42px;
  font-weight: 840;
  line-height: 1.08;
}

.prompt-cn {
  min-height: 60px;
  font-size: 28px;
  font-weight: 780;
  line-height: 1.28;
}

.prompt-sentence {
  min-height: 84px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  font-size: 22px;
  line-height: 1.38;
}

.sentence-cn {
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 10px 24px 16px;
}

.option-button {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 11px 12px;
  text-align: left;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 11px;
  align-items: center;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
}

.option-button:not(:disabled):hover {
  border-color: #9eb8e7;
  box-shadow: var(--small-shadow);
}

.option-button:disabled {
  opacity: 0.72;
}

.option-button:focus-visible {
  border-color: #7da4e8;
}

.option-key {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 820;
}

.option-text {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.option-button.correct {
  border-color: #7fc6a2;
  background: var(--green-soft);
}

.option-button.pending {
  border-color: #8dadf0;
  background: var(--blue-soft);
}

.unsure-row {
  padding: 0 24px 16px;
  display: flex;
  justify-content: flex-end;
}

.unsure-button {
  min-width: 94px;
}

.unsure-button.pending {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: #f3d29b;
}

.option-button.wrong {
  border-color: #eca29b;
  background: var(--red-soft);
}

.spelling-area {
  padding: 10px 24px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.spelling-cells {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.letter-input,
.letter-fixed {
  width: 34px;
  height: 42px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 760;
  line-height: 1;
  text-align: center;
}

.letter-input {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.letter-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 104, 216, 0.14);
}

.letter-fixed {
  border: 1px solid transparent;
  background: var(--surface-soft);
  color: var(--muted);
}

.letter-space {
  width: 16px;
  background: transparent;
}

.spelling-input {
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  outline: none;
  font-size: 18px;
}

.spelling-input:focus,
.select:focus,
.profile-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 104, 216, 0.14);
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button {
  border-radius: 8px;
  font-weight: 760;
}

.primary-button,
.ghost-button,
.danger-button {
  height: 38px;
  padding: 0 14px;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.ghost-button {
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.danger-button {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid #f1beb8;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.primary-button:disabled {
  opacity: 0.48;
  cursor: default;
}

.feedback {
  border-top: 1px solid var(--line);
  padding: 12px 16px 14px;
  background: #fbfcfd;
}

.feedback.hidden,
.hidden {
  display: none;
}

.feedback-status,
.feedback-actions,
.answer-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.feedback-status {
  margin-bottom: 8px;
}

.answer-line {
  justify-content: flex-start;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 17px;
  font-weight: 760;
}

.result-badge {
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  font-weight: 800;
  font-size: 13px;
}

.result-badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.result-badge.bad {
  background: var(--red-soft);
  color: var(--red);
}

.keyboard-hint {
  color: var(--muted);
  font-size: 12px;
}

.memory-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.memory-block {
  border-left: 3px solid var(--line);
  padding: 2px 0 2px 10px;
  min-height: 42px;
}

.memory-title {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.memory-title-row,
.lookup-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.memory-title-row .memory-title {
  margin-bottom: 4px;
}

.memory-title-row .icon-button,
.lookup-label-row .icon-button {
  width: 26px;
  height: 26px;
  font-size: 12px;
}

.memory-text {
  margin: 0;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.feedback-actions {
  margin-top: 12px;
}

.tag-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.click-word {
  display: inline;
  color: inherit;
  border-bottom: 1px dotted #8aa0b7;
  background: transparent;
  padding: 0 1px;
  border-radius: 0;
  font-weight: inherit;
}

.click-word:hover {
  color: var(--blue);
}

.manage-shell {
  width: min(980px, calc(100vw - 220px));
  margin: 0 auto;
  padding: 22px 0 42px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.manage-panel {
  padding: 16px;
}

.profile-panel {
  grid-column: 1 / -1;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 780;
}

.profile-switcher {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.profile-card {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.profile-card.active {
  border-color: #8dadf0;
  background: var(--blue-soft);
}

.profile-button {
  min-height: 46px;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 6px 4px;
  display: grid;
  gap: 4px;
  text-align: left;
}

.profile-button:disabled {
  opacity: 1;
  cursor: default;
}

.profile-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.compact-button {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.profile-name {
  font-size: 15px;
  font-weight: 780;
}

.profile-meta {
  color: var(--muted);
  font-size: 12px;
}

.profile-create {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  max-width: 430px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.select,
.profile-input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 0 10px;
  outline: none;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 64px;
}

.metric-value {
  font-size: 22px;
  font-weight: 820;
  line-height: 1.1;
}

.metric-label {
  color: var(--muted);
  margin-top: 4px;
  font-size: 12px;
}

.section-gap {
  margin-top: 16px;
}

.progress-list,
.queue-list,
.recent-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.progress-row {
  display: grid;
  grid-template-columns: 70px 1fr 42px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.bar {
  height: 8px;
  border-radius: 8px;
  background: #e8edf2;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--amber), var(--green));
  width: 0;
}

.queue-item,
.recent-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
}

.queue-word {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 720;
}

.loading-panel,
.error-panel {
  width: min(520px, calc(100vw - 32px));
  margin: 18vh auto 0;
  padding: 24px;
}

.error-panel {
  border-color: #f1beb8;
}

.loading-title {
  font-size: 22px;
  font-weight: 820;
}

.loading-text {
  margin-top: 8px;
  color: var(--muted);
}

.lookup-popover {
  position: fixed;
  z-index: 1000;
  max-height: min(520px, calc(100vh - 24px));
  overflow: auto;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.lookup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.lookup-word {
  margin: 0;
  font-size: 20px;
  font-weight: 820;
  overflow-wrap: anywhere;
}

.close-button {
  font-size: 18px;
}

.lookup-line {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.lookup-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.lookup-value {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  body {
    padding-left: 0;
  }

  .topbar {
    width: auto;
    min-height: 64px;
    padding: 12px 22px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    position: sticky;
    left: auto;
    bottom: auto;
    align-items: center;
  }

  .top-metrics {
    display: none;
  }

  .current-card {
    display: none;
  }

  .view-switch {
    height: 36px;
    display: inline-flex;
  }

  .view-button {
    width: auto;
    min-width: 58px;
    height: 28px;
  }

  .study-shell,
  .manage-shell {
    width: min(760px, calc(100vw - 28px));
  }

  .manage-shell {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  body {
    background: var(--surface);
  }

  .topbar {
    min-height: 50px;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    gap: 8px;
    background: rgba(255, 255, 255, 0.96);
  }

  .brand-title {
    font-size: 17px;
    line-height: 1.1;
  }

  .brand-subtitle {
    display: none;
  }

  .study-shell,
  .manage-shell {
    width: 100%;
    padding: 8px 8px 18px;
  }

  .study-panel {
    border-radius: 8px;
    box-shadow: none;
    min-height: auto;
    grid-template-rows: auto auto auto;
  }

  .question-body,
  .options-grid,
  .spelling-area,
  .unsure-row {
    padding-left: 12px;
    padding-right: 12px;
  }

  .question-body {
    padding-top: 8px;
    padding-bottom: 2px;
    gap: 6px;
  }

  .prompt-word {
    min-height: 40px;
    font-size: 32px;
    line-height: 1.08;
  }

  .prompt-cn {
    min-height: 34px;
    font-size: 22px;
    line-height: 1.22;
  }

  .prompt-sentence {
    min-height: auto;
    padding: 10px;
    font-size: 17px;
    line-height: 1.42;
  }

  .options-grid,
  .memory-grid,
  .spelling-area,
  .profile-create,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .options-grid {
    gap: 8px;
    padding-top: 4px;
    padding-bottom: 8px;
  }

  .option-button {
    min-height: 54px;
    grid-template-columns: 28px 1fr;
    gap: 9px;
    padding: 9px 10px;
  }

  .option-key {
    width: 28px;
    height: 28px;
  }

  .spelling-area {
    gap: 8px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .spelling-cells {
    gap: 6px;
  }

  .letter-input,
  .letter-fixed {
    width: 31px;
    height: 38px;
    font-size: 18px;
  }

  .letter-space {
    width: 12px;
  }

  .unsure-row {
    padding-top: 0;
    padding-bottom: 10px;
    justify-content: stretch;
  }

  .unsure-button {
    width: 100%;
  }

  .feedback {
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  }

  .feedback-status {
    margin-bottom: 6px;
  }

  .keyboard-hint {
    display: none;
  }

  .answer-line {
    min-height: 38px;
    padding: 7px 9px;
    font-size: 16px;
  }

  .memory-grid {
    gap: 8px;
    margin-top: 8px;
  }

  .memory-block {
    min-height: 0;
    padding-left: 8px;
  }

  .memory-title {
    margin-bottom: 2px;
  }

  .memory-text {
    line-height: 1.42;
  }

  .feedback-actions {
    margin-top: 8px;
    margin-bottom: 8px;
  }

  .feedback-buttons,
  .feedback-buttons .primary-button {
    width: 100%;
  }

  .feedback-tags {
    display: none;
  }

  .profile-create {
    max-width: none;
  }

  .profile-card {
    grid-template-columns: 1fr;
  }

  .profile-actions {
    justify-content: stretch;
  }

  .profile-actions .compact-button {
    flex: 1;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    height: 36px;
  }

  .view-button {
    min-width: 48px;
    padding: 0 9px;
  }

  .manage-shell {
    gap: 10px;
  }

  .manage-panel {
    padding: 12px;
  }

  .metric-grid {
    gap: 8px;
  }

  .lookup-popover {
    width: calc(100vw - 20px) !important;
    max-height: calc(100svh - 20px);
  }
}

@media (max-width: 420px) and (orientation: portrait) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .study-shell,
  .manage-shell {
    padding-left: 0;
    padding-right: 0;
  }

  .study-panel,
  .manage-panel {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .prompt-word {
    font-size: 30px;
  }

  .prompt-cn {
    font-size: 21px;
  }
}
