:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef5f8;
  --text: #172033;
  --muted: #677286;
  --line: #dfe7ef;
  --blue: #1f68b2;
  --teal: #1a9d9a;
  --purple: #5b34d6;
  --red: #d44b4b;
  --green: #158765;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "STHeiti", "Microsoft YaHei", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-logo {
  width: 86px;
  height: 86px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  font-weight: 750;
  letter-spacing: 0;
}

.brand p,
.section-heading p,
.study-strip p,
.progress-copy p,
.print-toolbar p,
.records-band p {
  color: var(--muted);
  line-height: 1.65;
}

.account-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: min(360px, 100%);
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.account-box strong,
.account-box small {
  display: block;
  text-align: right;
}

.account-box strong {
  font-size: 15px;
}

.account-box small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.account-actions {
  display: flex;
  gap: 8px;
}

.progress-band {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(420px, 1.15fr);
  gap: 24px;
  align-items: stretch;
  padding: 30px;
  background: linear-gradient(135deg, #ffffff 0%, #eef7f7 58%, #f6f1ff 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-copy h2 {
  margin-top: 12px;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.1;
  letter-spacing: 0;
}

.progress-copy p {
  margin-top: 12px;
  max-width: 520px;
}

.progress-panel {
  align-self: center;
  padding: 24px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(223, 231, 239, 0.9);
  border-radius: 8px;
}

.progress-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  color: var(--muted);
}

.progress-line strong {
  color: var(--text);
  font-size: 28px;
}

.progress-track {
  height: 14px;
  margin: 14px 0 22px;
  overflow: hidden;
  background: #e7edf3;
  border-radius: 999px;
}

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

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

.metrics div {
  min-height: 74px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: 24px;
  line-height: 1.1;
}

.home-start {
  display: grid;
  place-items: center;
  margin-top: 24px;
  padding: 18px 0 8px;
}

.start-button {
  width: min(560px, 100%);
  min-height: 88px;
  padding: 22px 28px;
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(31, 104, 178, 0.22);
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 800;
  letter-spacing: 0;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease;
}

.start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 48px rgba(31, 104, 178, 0.28);
}

.detector-shell {
  width: min(920px, 100%);
  margin: 24px auto 0;
}

.workspace-panel,
.results-band,
.records-band {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.section-heading h2 {
  font-size: 23px;
  letter-spacing: 0;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  color: #fff;
  background: var(--text);
  border-radius: 8px;
  font-weight: 800;
}

.word-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  margin-top: 24px;
  padding: 36px 26px;
  background: #f9fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
}

.audio-button {
  min-width: 76px;
  min-height: 38px;
  padding: 8px 14px;
  color: var(--blue);
  background: #fff;
  border: 1px solid #bdd4ea;
  border-radius: 8px;
}

.audio-button.loading {
  color: var(--muted);
  background: #eef4f8;
}

.word-stage .audio-button {
  position: absolute;
  top: 18px;
  right: 18px;
}

.word-index {
  position: absolute;
  top: 22px;
  left: 22px;
  color: var(--muted);
  font-size: 14px;
}

#currentWord,
#studyWord {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(44px, 8vw, 78px);
  font-weight: 780;
  letter-spacing: 0;
}

.meaning-text {
  margin-top: 18px;
  color: var(--text);
  font-size: 28px;
  font-weight: 680;
  line-height: 1.35;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.action-row.compact {
  margin-top: 14px;
}

.primary-action,
.solid-button,
.ghost-button,
.export-button,
.filter-button {
  border: 0;
  border-radius: 8px;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.primary-action {
  min-height: 72px;
  padding: 18px;
  color: #fff;
  font-size: 22px;
  font-weight: 750;
}

.primary-action.know {
  background: var(--green);
}

.primary-action.unknown {
  background: var(--red);
}

.primary-action:hover,
.solid-button:hover,
.export-button:hover,
.ghost-button:hover,
.filter-button:hover {
  transform: translateY(-1px);
}

.confirm-box {
  margin-top: 18px;
  padding: 18px;
  background: #f7fbfb;
  border: 1px solid #c9e3e0;
  border-radius: 8px;
}

.confirm-box p {
  color: var(--text);
  font-weight: 700;
}

.toolbar-row,
.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.ghost-button {
  min-height: 42px;
  padding: 10px 16px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
}

.solid-button {
  min-height: 46px;
  padding: 12px 18px;
  color: #fff;
  background: var(--blue);
  font-weight: 720;
}

.solid-button.accent {
  background: var(--green);
}

.solid-button.wide {
  width: 100%;
  margin-top: 14px;
}

.large-actions {
  display: grid;
  gap: 14px;
  margin-top: 26px;
}

.export-button {
  display: grid;
  gap: 8px;
  min-height: 96px;
  padding: 20px;
  text-align: left;
  background: #f7fbfd;
  border: 1px solid var(--line);
}

.export-button strong {
  color: var(--text);
  font-size: 22px;
}

.export-button span {
  color: var(--muted);
}

.study-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 22px;
  padding: 18px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.study-strip h3 {
  font-size: 22px;
}

.results-band {
  margin-top: 24px;
}

.records-band {
  margin-top: 24px;
}

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

.record-summary div {
  min-height: 78px;
  padding: 13px;
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.record-summary strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: 23px;
  line-height: 1.15;
}

.activity-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.activity-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.75fr) minmax(120px, 1fr) minmax(130px, 1.1fr) 110px;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.activity-row strong,
.activity-row span {
  overflow-wrap: anywhere;
}

.activity-row span,
.activity-empty {
  color: var(--muted);
}

.activity-empty {
  margin-top: 14px;
  padding: 14px;
  background: #f8fbfd;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-button {
  min-height: 40px;
  padding: 9px 14px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
}

.filter-button.active {
  color: #fff;
  background: var(--text);
  border-color: var(--text);
}

.search-input {
  flex: 1 1 220px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.search-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 104, 178, 0.12);
}

.word-table {
  display: grid;
  gap: 8px;
  max-height: 460px;
  margin-top: 18px;
  overflow: auto;
  padding-right: 4px;
}

.word-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) 92px;
  gap: 14px;
  align-items: center;
  min-height: 52px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.word-row strong {
  overflow-wrap: anywhere;
}

.status-pill {
  justify-self: end;
  min-width: 72px;
  padding: 5px 10px;
  text-align: center;
  color: var(--muted);
  background: #f0f4f8;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.known {
  color: var(--green);
  background: #e8f5f0;
}

.status-pill.unknown,
.status-pill.mistake {
  color: var(--red);
  background: #fbefef;
}

.print-preview {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.print-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.print-toolbar > div:last-child {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.print-version-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.print-version {
  min-height: 38px;
  padding: 8px 14px;
  color: var(--muted);
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 720;
}

.print-version.active {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.print-message {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.print-area {
  display: grid;
  gap: 18px;
}

.print-page {
  width: min(100%, 210mm);
  min-height: 297mm;
  margin: 0 auto;
  padding: 11mm 10mm;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.print-page header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 19mm;
  padding-bottom: 4mm;
  border-bottom: 2px solid #172033;
}

.print-page h2 {
  font-size: 21px;
}

.print-page small {
  color: var(--muted);
}

.print-logo-mark {
  display: grid;
  place-items: center;
  width: 15mm;
  height: 15mm;
  color: var(--blue);
  background: #eef7f7;
  border: 1px solid #b9d8ec;
  border-radius: 8px;
  font-weight: 800;
  font-size: 18px;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 7mm;
  margin-top: 4mm;
}

.print-column {
  display: grid;
}

.print-item {
  display: grid;
  grid-template-columns: 8mm minmax(29mm, 1fr) minmax(30mm, 1fr);
  min-height: 8.4mm;
  align-items: center;
  border-bottom: 1px solid #e7edf3;
  font-size: 14px;
}

.print-item .num {
  color: var(--muted);
}

.print-item .word {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.print-item.blank .meaning {
  height: 22px;
  border-bottom: 1px solid #98a6b7;
}

.site-footer {
  margin-top: 34px;
  padding: 22px 24px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.75;
}

.site-footer p + p {
  margin-top: 8px;
}

.site-footer-motto {
  color: var(--text);
  font-weight: 760;
  letter-spacing: 0.03em;
  white-space: pre-wrap;
}

.study-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 51, 0.44);
  z-index: 20;
}

.auth-modal,
.auth-prompt-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 51, 0.44);
}

.study-panel,
.auth-panel,
.auth-prompt-panel {
  position: relative;
  width: min(640px, 100%);
  padding: 34px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 30px 70px rgba(23, 32, 51, 0.22);
}

.study-panel {
  text-align: center;
}

.auth-panel h2 {
  margin-top: 10px;
  font-size: 28px;
}

.auth-prompt-panel h2 {
  margin-top: 10px;
  font-size: 30px;
  line-height: 1.2;
}

.auth-prompt-panel p {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.auth-prompt-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 24px;
}

.auth-prompt-actions .quiet-action {
  grid-column: 1 / -1;
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 20px;
  padding: 5px;
  background: #eef4f8;
  border-radius: 8px;
}

.auth-tab {
  min-height: 40px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-weight: 720;
}

.auth-tab.active {
  color: var(--text);
  background: #fff;
  box-shadow: 0 6px 14px rgba(23, 32, 51, 0.08);
}

.auth-pane {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.auth-pane label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-pane input {
  min-height: 46px;
  padding: 0 13px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.auth-pane input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 104, 178, 0.12);
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 10px;
  align-items: end;
}

.code-row .ghost-button {
  min-height: 46px;
}

.auth-status {
  min-height: 22px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.auth-status.error {
  color: var(--red);
}

.auth-status.success {
  color: var(--green);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  min-height: 36px;
  padding: 7px 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.audio-button.centered {
  margin-top: 16px;
}

.floating-actions {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 15;
  display: grid;
  width: 156px;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(23, 32, 51, 0.14);
  backdrop-filter: blur(12px);
}

.floating-button {
  min-height: 40px;
  padding: 9px 12px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 720;
  transition:
    transform 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.floating-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.1);
}

.floating-button.print {
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.floating-button.secondary {
  color: var(--blue);
  background: #f6fbff;
}

.floating-button.quiet {
  color: var(--muted);
  background: #fff;
}

.app-shell:not(.is-detecting) .detect-only {
  display: none;
}

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

@media (max-width: 900px) {
  .app-shell,
  .print-preview {
    width: min(100% - 22px, 720px);
  }

  .topbar,
  .progress-band,
  .study-strip,
  .print-toolbar {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .progress-band {
    padding: 20px;
  }

  .account-box,
  .account-box strong,
  .account-box small {
    text-align: left;
  }

  .account-box {
    justify-content: space-between;
    min-width: 0;
  }

  .floating-actions {
    right: 12px;
    bottom: 12px;
    width: min(190px, calc(100vw - 24px));
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .floating-button.print,
  .floating-button.quiet {
    grid-column: 1 / -1;
  }

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

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

  .activity-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .word-stage {
    min-height: 260px;
  }

  .word-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .status-pill {
    justify-self: start;
  }

  .print-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 4mm;
  }

  .print-item {
    grid-template-columns: 7mm minmax(24mm, 1fr) minmax(24mm, 1fr);
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

  .brand-logo {
    width: 64px;
    height: 64px;
  }

  h1 {
    font-size: 24px;
  }

  .workspace-panel,
  .results-band,
  .records-band,
  .site-footer {
    padding: 20px;
  }

  .auth-panel,
  .auth-prompt-panel,
  .study-panel {
    padding: 28px 20px 22px;
  }

  .auth-tabs,
  .code-row,
  .auth-prompt-actions {
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding-bottom: 230px;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .primary-action {
    min-height: 62px;
    font-size: 20px;
  }

  #currentWord,
  #studyWord {
    font-size: clamp(38px, 14vw, 58px);
  }
}

@media print {
  body {
    background: #fff;
    font-family: "STHeiti", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
      "WenQuanYi Micro Hei", sans-serif;
  }

  .app-shell,
  .print-toolbar,
  .study-modal,
  .auth-modal,
  .auth-prompt-modal {
    display: none !important;
  }

  .print-preview,
  .print-area {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .print-page {
    width: 210mm;
    height: 297mm;
    min-height: 0;
    margin: 0;
    padding: 11mm 10mm;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
    page-break-after: always;
  }

  .print-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 7mm;
  }

  .print-item {
    grid-template-columns: 8mm minmax(29mm, 1fr) minmax(30mm, 1fr);
    min-height: 8.4mm;
    font-size: 14px;
  }

  .print-page:last-child {
    page-break-after: auto;
  }
}
