:root {
  color-scheme: light;
  --paper: #f7f4ee;
  --surface: #ffffff;
  --ink: #1d2328;
  --muted: #68727d;
  --line: #d9d7ce;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warm: #c77d2d;
  --shadow: 0 18px 60px rgba(24, 35, 40, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.14), transparent 36%),
    linear-gradient(315deg, rgba(199, 125, 45, 0.16), transparent 38%),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button {
  border: 0;
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 32px 18px;
}

.study-panel {
  width: min(680px, 100%);
  min-width: 0;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 215, 206, 0.85);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(22px, 4vw, 36px);
}

.study-panel > * {
  min-width: 0;
}

#homePanel,
#wordListPanel {
  width: min(920px, 100%);
}

.topbar {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 8px;
  width: 100%;
}

.word-label,
.sense-hint {
  margin: 0;
  color: var(--muted);
}

.stats {
  min-width: 82px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  background: #fbfaf7;
}

.stats span {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent-strong);
}

.stats small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.day-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.study-progress-row {
  align-items: center;
  justify-content: space-between;
}

.study-progress-row .word-label {
  margin: 0;
}

.home-summary {
  display: grid;
  gap: 16px;
}

.home-card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.home-card-title {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 720;
}

.today-plan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(82px, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 14px;
}

.today-plan-item {
  min-height: 68px;
  display: grid;
  align-content: center;
  background: var(--surface);
}

.home-plan-meta {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.home-plan-meta:empty {
  display: none;
}

.plan-compare {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.progress-card {
  display: grid;
  gap: 14px;
}

.progress-overview .stats {
  background: var(--surface);
}

.heatmap-tooltip {
  min-height: 1.5em;
  margin: 0;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 680;
}

.heatmap-scroll {
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.heatmap-months,
.heatmap-grid {
  width: 744px;
  display: grid;
  grid-template-columns: repeat(53, 10px);
  column-gap: 4px;
  margin-inline: auto;
}

.heatmap-months {
  min-height: 20px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.7rem;
}

.heatmap-month-label {
  align-self: end;
  white-space: nowrap;
}

.heatmap-grid {
  grid-template-rows: repeat(7, 10px);
  grid-auto-flow: column;
  gap: 4px;
}

.heatmap-day {
  width: 10px;
  height: 10px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--heat-color, #ecefeb);
  cursor: default;
  transition:
    background-color 180ms ease,
    transform 120ms ease,
    box-shadow 120ms ease;
}

.heatmap-day.is-active {
  cursor: pointer;
}

.heatmap-day.is-active:hover,
.heatmap-day.is-active:focus-visible {
  position: relative;
  z-index: 1;
  transform: scale(1.35);
  box-shadow: 0 0 0 2px var(--surface);
  outline: 1px solid rgba(29, 35, 40, 0.34);
}

.home-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}

.home-account-actions,
.home-primary-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-home-status {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.word-list-panel {
  min-height: min(760px, calc(100vh - 64px));
}

.word-list-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.word-list-header h1 {
  margin: 6px 0 0;
  font-size: 1.65rem;
  letter-spacing: 0;
}

.sort-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.sort-field select {
  min-height: 42px;
  max-width: 230px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 34px 0 12px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
}

.sort-field select:focus {
  border-color: rgba(15, 118, 110, 0.58);
  outline: none;
}

.word-list {
  min-height: 0;
  max-height: min(560px, calc(100vh - 270px));
  overflow-y: auto;
  border-block: 1px solid var(--line);
}

.word-list-item {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(217, 215, 206, 0.72);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: 0;
}

.word-list-name {
  min-width: 0;
  margin-right: auto;
  overflow-wrap: anywhere;
}

.word-list-meta {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.word-list-badge {
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 680;
  line-height: 1.2;
  white-space: nowrap;
}

.word-list-badge.is-duration,
.word-list-badge.is-new {
  background: #f3f4f2;
}

.word-list-badge.is-reinforce {
  border-color: rgba(199, 125, 45, 0.42);
  background: #fff8e8;
  color: #946019;
}

.word-list-badge.is-review {
  border-color: rgba(15, 118, 110, 0.35);
  background: #edf9f7;
  color: var(--accent-strong);
}

.word-list-badge.is-mastered {
  border-color: rgba(22, 163, 74, 0.36);
  background: #ecfdf3;
  color: #166534;
}

.word-list-item:last-child {
  border-bottom: 0;
}

.word-list-item:hover,
.word-list-item:focus-visible {
  background: #f2fbf9;
  color: var(--accent-strong);
  outline: none;
}

.word-stage {
  display: grid;
  gap: 14px;
  padding-block: 12px 10px;
}

.word-label {
  font-size: 0.86rem;
}

.word-card-wrap {
  position: relative;
  min-width: 0;
  width: 100%;
}

.word-button {
  width: 100%;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding-inline: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--ink);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.word-button:hover,
.word-button:focus-visible {
  border-color: rgba(15, 118, 110, 0.55);
  box-shadow: 0 12px 30px rgba(15, 118, 110, 0.12);
  outline: none;
}

.word-button:active {
  transform: translateY(1px);
}

.word-button:disabled {
  cursor: default;
  opacity: 0.72;
}

.word-button.is-finished {
  cursor: pointer;
  border-color: rgba(15, 118, 110, 0.35);
  background: #f2fbf9;
}

.word-button.is-mastered {
  border-color: rgba(21, 128, 61, 0.96);
  background: #ecfdf3;
  box-shadow: 0 14px 30px rgba(22, 163, 74, 0.16);
}

.audio-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-strong);
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

.audio-button:hover,
.audio-button:focus-visible {
  border-color: rgba(15, 118, 110, 0.58);
  background: #f2fbf9;
  outline: none;
}

.audio-button:active {
  transform: scale(0.96);
}

.audio-button[hidden] {
  display: none;
}

.audio-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

#wordText {
  max-width: 100%;
  font-size: 5.8rem;
  font-weight: 820;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.word-button.is-finished #wordText {
  font-size: 4.9rem;
}

.sense-area {
  display: grid;
  gap: 12px;
}

.morphology-panel {
  display: grid;
  gap: 12px;
  padding-block: 14px;
  border-block: 1px solid var(--line);
}

.morphology-panel[hidden] {
  display: none;
}

.morphology-title,
.morphology-group-title,
.morphology-special-meaning {
  margin: 0;
  letter-spacing: 0;
}

.morphology-title {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.morphology-group {
  display: grid;
  grid-template-columns: minmax(72px, 0.16fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.morphology-group + .morphology-group {
  padding-top: 12px;
  border-top: 1px solid rgba(216, 212, 202, 0.72);
}

.morphology-group-title {
  padding-top: 2px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 780;
}

.morphology-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px 18px;
  min-width: 0;
}

.morphology-item {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.morphology-item-label {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.morphology-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
  line-height: 1.45;
}

.morphology-form.is-muted,
.morphology-separator {
  color: #9aa1a8;
  font-weight: 560;
}

.morphology-form.is-normal {
  color: var(--ink);
  font-weight: 760;
}

.morphology-form.is-special {
  color: #b42318;
  font-weight: 800;
}

.morphology-separator {
  padding-inline: 6px;
}

.morphology-special-list {
  display: grid;
  gap: 12px;
}

.morphology-special {
  display: grid;
  gap: 8px;
  padding-left: 12px;
  border-left: 3px solid #b42318;
}

.morphology-special-meaning {
  color: #b42318;
  font-size: 0.84rem;
  font-weight: 800;
}

.sense-list {
  display: grid;
  gap: 10px;
}

.sense-list.is-reordering {
  pointer-events: none;
}

.sense-item {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease,
    opacity 180ms ease,
    transform 140ms ease;
}

.sense-item:hover,
.sense-item:focus-visible {
  border-color: rgba(15, 118, 110, 0.58);
  background: #f2fbf9;
  outline: none;
}

.sense-item:active {
  transform: scale(0.995);
}

.sense-item:disabled,
.sense-item.is-example {
  cursor: default;
}

.sense-item.is-example {
  align-items: flex-start;
  background: #fbfaf7;
}

.sense-item.is-confirmed,
.sense-item.is-mastered,
.sense-item.is-confirming {
  border-color: rgba(22, 163, 74, 0.88);
  background: #ecfdf3;
  box-shadow: 0 14px 28px rgba(22, 163, 74, 0.16);
}

.sense-item.is-mastered {
  border-color: rgba(21, 128, 61, 0.96);
}

.sense-item.is-example.is-collapsible {
  cursor: pointer;
}

.sense-item.is-example.is-collapsible:not(.is-expanded) {
  align-items: center;
}

.sense-item.is-collapsible::after {
  content: "+";
  flex: 0 0 auto;
  color: #166534;
  font-size: 1.15rem;
  font-weight: 760;
}

.sense-item.is-collapsible.is-expanded::after {
  content: "\2212";
}

.sense-item.is-collapsible:hover,
.sense-item.is-collapsible:focus-visible {
  border-color: rgba(21, 128, 61, 1);
  background: #e4f9eb;
}

.sense-item.is-confirming {
  pointer-events: none;
  animation: senseConfirm 340ms cubic-bezier(0.2, 0.82, 0.2, 1) forwards;
}

@keyframes senseConfirm {
  0% {
    transform: scale(1);
  }

  62% {
    transform: scale(0.965);
  }

  100% {
    transform: scale(0.965);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sense-item.is-confirming {
    animation-duration: 1ms;
  }
}

.sense-rank {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.11);
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 760;
}

.sense-copy {
  flex: 1;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.sense-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.sense-pos {
  flex: 0 0 auto;
  color: var(--warm);
  font-size: 0.92rem;
  font-weight: 800;
}

.sense-text {
  min-width: 0;
  font-size: 1.02rem;
  overflow-wrap: anywhere;
}

.sense-ipa {
  flex: 0 1 auto;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

.sense-detail-group {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.sense-detail-group > .sense-definition,
.sense-detail-group > .sense-definition-zh,
.sense-detail-group > .sense-example,
.sense-detail-group > .sense-example-zh {
  color: inherit;
  font-size: 0.92rem;
  line-height: 1.45;
}

.sense-example-group {
  margin-top: 0.9rem;
}

.sense-definition-zh,
.sense-example-zh {
  font-size: 0.9rem;
}

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

.primary-button,
.secondary-button,
.danger-button,
.plain-button {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 720;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--accent-strong);
  outline: none;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fbfaf7;
  color: var(--ink);
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: rgba(199, 125, 45, 0.7);
  outline: none;
}

.danger-button {
  background: #b42318;
  color: white;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #912018;
  outline: none;
}

.plain-button {
  background: transparent;
  color: var(--muted);
}

.plain-button:hover,
.plain-button:focus-visible {
  color: var(--ink);
  outline: none;
}

.primary-button:disabled {
  cursor: default;
  background: #94a3ad;
}

.secondary-button:disabled {
  cursor: default;
  color: #8d969f;
  background: #f1f2f2;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(29, 35, 40, 0.28);
}

.modal-backdrop[hidden] {
  display: none;
}

.reset-dialog {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.account-dialog {
  width: min(500px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow-y: auto;
}

.account-dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.account-dialog-heading h2 {
  margin-top: 4px;
}

.account-state-badge {
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f3f4f2;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
}

.account-state-badge.is-online {
  border-color: rgba(15, 118, 110, 0.34);
  background: #edf9f7;
  color: var(--accent-strong);
}

.account-auth-view,
.account-user-view,
.account-conflict-view,
.account-delete-confirm,
.account-form,
.account-action-list {
  display: grid;
  gap: 12px;
}

.account-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f4f2;
}

.account-tab {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 720;
}

.account-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 35, 40, 0.08);
}

.account-input {
  font-weight: 600;
}

.account-user-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.account-user-copy strong {
  overflow-wrap: anywhere;
}

.account-sync-copy {
  color: var(--muted);
  font-size: 0.84rem;
}

.account-sync-copy.is-error,
.account-message.is-error {
  color: #b42318;
}

.account-sync-copy.is-pending {
  color: #946019;
}

.account-message {
  min-height: 1.45em;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.account-message:empty {
  display: none;
}

.account-data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.account-data-actions .plain-button {
  min-height: 36px;
  padding-inline: 10px;
  font-size: 0.82rem;
}

.reset-dialog h2,
.reset-word {
  margin: 0;
}

.reset-dialog h2 {
  font-size: 1.35rem;
}

.reset-word {
  color: var(--muted);
}

.reset-options,
.reset-confirm,
.confirm-actions,
.plan-form {
  display: grid;
  gap: 10px;
}

.plan-form {
  gap: 18px;
}

.plan-reset-button {
  margin-top: 4px;
}

.plan-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.number-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-weight: 720;
}

.number-input:focus {
  border-color: rgba(15, 118, 110, 0.58);
  outline: none;
}

.confirm-title,
.confirm-copy {
  margin: 0;
}

.confirm-title {
  font-weight: 800;
  color: var(--ink);
}

.confirm-copy {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 560px) {
  .app-shell {
    padding: 16px;
  }

  .study-panel {
    min-height: calc(100vh - 32px);
  }

  .word-button {
    padding-inline: 56px;
  }

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

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

  .stats {
    width: 100%;
  }

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

  .home-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .home-account-actions,
  .home-primary-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .account-home-status {
    max-width: none;
    text-align: center;
  }

  .today-plan-grid {
    grid-template-columns: 1fr;
  }

  .home-card {
    padding: 16px;
  }

  .word-list-header {
    align-items: stretch;
    flex-direction: column;
  }

  .sort-field select {
    width: 100%;
    max-width: none;
  }

  .word-list-item {
    align-items: flex-start;
  }

  .morphology-group {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .morphology-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
  }
}
