:root {
  color-scheme: light;
  --ink: #18202a;
  --muted: #637083;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #f5f7f4;
  --surface: #fbfcfa;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #dff3ef;
  --warm: #a8550f;
  --blue: #2563eb;
  --danger: #b91c1c;
  --shadow: 0 18px 45px rgba(28, 38, 54, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 44px;
  min-width: 120px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
  font-weight: 800;
  cursor: pointer;
}

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

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

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 86px;
  line-height: 1.45;
}

select:focus,
input:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

progress {
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

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

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(223, 243, 239, 0.55), rgba(245, 247, 244, 0.15)),
    var(--page);
}

.auth-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 28px;
  box-shadow: var(--shadow);
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 29px;
  font-weight: 900;
  flex: 0 0 auto;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.form-status {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 650;
}

.app {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 0;
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 10px 24px rgba(28, 38, 54, 0.12);
}

.sidebar-toggle:hover,
.sidebar-toggle.is-active {
  background: var(--accent);
  color: #ffffff;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(24, 32, 42, 0.42);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 76px 28px 28px;
  transition: transform 180ms ease, opacity 180ms ease;
}

.app.sidebar-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.app.sidebar-collapsed .sidebar {
  display: none;
}

.setting-list {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.setting-list > span {
  color: var(--muted);
  font-weight: 750;
}

.setting-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: auto;
  color: var(--ink);
  font-weight: 650;
}

.setting-option input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.stats {
  display: grid;
  gap: 10px;
  margin-top: auto;
  color: var(--muted);
  font-weight: 650;
}

.account-panel {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.account-panel span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.secondary-btn {
  min-width: 0;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.secondary-btn:hover {
  background: var(--surface);
}

.study {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  padding: 28px;
}

.mobile-header {
  display: none;
}

.card {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(780px, 100%);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 42px;
  box-shadow: var(--shadow);
}

.learned-circle {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  width: 38px;
  height: 38px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  color: var(--muted);
  padding: 0;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.learned-circle.is-learned {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.card-topline,
.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.card-topline {
  padding-right: 50px;
}

.card-topline span,
.meta span {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  overflow-wrap: anywhere;
}

.audio-btn,
.reveal-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  padding: 0;
  font-size: 17px;
  line-height: 1;
}

.audio-btn:hover,
.reveal-btn:hover,
.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.reveal-btn.is-revealed {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.word {
  margin-top: 12px;
  font-size: 104px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.simplified {
  color: var(--muted);
  font-size: 24px;
  min-height: 32px;
  overflow-wrap: anywhere;
}

.pinyin {
  min-width: 0;
  color: var(--accent-dark);
  font-size: 32px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.pinyin-row,
.meaning-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.meaning {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.meaning span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.meaning strong {
  color: var(--warm);
  font-size: 28px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.example-section {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.example-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.example-btn {
  min-width: 104px;
  min-height: 40px;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
}

.example-box {
  display: grid;
  gap: 5px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 10px 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.example-box strong {
  color: var(--ink);
  font-size: 20px;
  font-weight: 900;
}

.example-highlight {
  border-radius: 5px;
  background: rgba(168, 85, 15, 0.18);
  color: var(--warm);
  padding: 0 3px;
}

.example-box span {
  color: var(--muted);
  font-size: 14px;
}

.example-box .example-translation {
  color: var(--ink);
  font-weight: 700;
}

.sr-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  min-height: 18px;
}

.note {
  margin-top: auto;
}

.note textarea {
  min-height: 76px;
}

.controls {
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: min(780px, 100%);
}

.page-position {
  position: fixed;
  right: 28px;
  bottom: 28px;
  color: var(--muted);
  font-size: 16px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 100px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
  font-weight: 800;
  text-decoration: none;
}

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

.enrich-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.enrich-panel {
  width: min(900px, 100%);
  display: grid;
  gap: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 34px;
  box-shadow: var(--shadow);
}

.enrich-header,
.form-row,
.enrich-grid {
  display: grid;
  gap: 16px;
}

.enrich-header {
  grid-template-columns: 1fr auto;
  align-items: start;
}

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

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

.metric {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.metric strong {
  font-size: 28px;
}

.log-box {
  min-height: 140px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  color: var(--muted);
  padding: 14px;
  white-space: pre-wrap;
}

.batch-results {
  display: grid;
  gap: 14px;
}

.batch-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.batch-card h2 {
  margin: 0;
  font-size: 16px;
}

.result-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.result-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) minmax(90px, 1fr) minmax(130px, 1.5fr) minmax(150px, 2fr);
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
  align-items: start;
}

.result-row span,
.result-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.result-row span {
  color: var(--muted);
}

@media (max-width: 900px) {
  .word {
    font-size: 82px;
  }

  .card {
    padding: 34px;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--panel);
  }

  .auth-view {
    align-items: stretch;
    padding: 16px;
  }

  .auth-panel {
    align-self: center;
    padding: 22px;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
  }

  .sidebar-toggle {
    top: 14px;
    left: 14px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: min(330px, 88vw);
    border-right: 1px solid var(--line);
    padding: 72px 20px 24px;
    box-shadow: 0 18px 45px rgba(28, 38, 54, 0.2);
    overflow: auto;
  }

  .app.sidebar-collapsed .sidebar {
    display: flex;
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
  }

  .study {
    min-width: 0;
    gap: 14px;
    padding: 12px 12px 104px;
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    min-height: 64px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    padding: 6px 4px 6px 58px;
  }

  .mobile-header span {
    display: block;
    color: var(--ink);
    font-weight: 900;
  }

  .mobile-header strong {
    display: block;
    max-width: 210px;
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card {
    align-self: start;
    min-height: 0;
    width: 100%;
    gap: 14px;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: 24px 4px 20px;
    box-shadow: none;
  }

  .learned-circle {
    top: 20px;
    right: 2px;
  }

  .card-topline {
    padding-right: 48px;
    gap: 8px;
  }

  .card-topline span,
  .meta span {
    border-radius: 8px;
    padding: 6px 8px;
  }

  .word {
    margin-top: 4px;
    font-size: 72px;
  }

  .simplified {
    font-size: 18px;
    min-height: 24px;
  }

  .pinyin {
    font-size: 25px;
  }

  .meaning strong {
    font-size: 23px;
  }

  .example-box strong {
    font-size: 18px;
  }

  .note textarea {
    min-height: 92px;
  }

  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 8px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .controls button {
    min-width: 0;
    padding: 12px 8px;
  }

  .page-position {
    position: static;
    justify-self: center;
    margin-top: -4px;
    font-size: 14px;
  }

  .enrich-page {
    display: block;
    padding: 14px;
  }

  .enrich-panel {
    padding: 20px;
  }

  .enrich-header,
  .form-row,
  .enrich-grid {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 390px) {
  .auth-panel {
    padding: 18px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    font-size: 25px;
  }

  h1 {
    font-size: 24px;
  }

  .word {
    font-size: 58px;
  }

  .pinyin {
    font-size: 22px;
  }

  .controls {
    gap: 6px;
    padding-left: 8px;
    padding-right: 8px;
  }
}
