:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --ink: #172026;
  --muted: #64717d;
  --line: #dce3ea;
  --green: #166c54;
  --green-soft: #e7f4ef;
  --coral: #b44d3f;
  --coral-soft: #fff0ed;
  --blue: #295f98;
  --blue-soft: #eaf2fb;
  --shadow: 0 10px 30px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(41, 95, 152, 0.08), transparent 280px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 18px;
}

.eyebrow,
.today-label {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 21px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 6px;
  font-size: 17px;
  line-height: 1.25;
}

.hero-panel {
  display: grid;
  gap: 18px;
  padding: 20px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.stats-grid div {
  min-width: 0;
  padding: 12px 8px;
  background: var(--blue-soft);
  border-radius: 8px;
  text-align: center;
}

.stats-grid div:nth-child(2) {
  background: var(--green-soft);
}

.stats-grid div:nth-child(3) {
  background: var(--coral-soft);
}

.stats-grid span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

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

.tabbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 16px 0;
  padding: 6px;
  background: rgba(247, 249, 251, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(14px);
}

.tab-button {
  min-height: 42px;
  color: var(--muted);
  background: transparent;
  border-radius: 7px;
  font-weight: 750;
}

.tab-button.active {
  color: #fff;
  background: var(--green);
}

.view {
  display: none;
  animation: fade 180ms ease;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px;
}

.card-form,
.ai-form,
.generated-card,
.review-card,
.lookup-result,
.word-card,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.card-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.ai-form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ai-note {
  margin: 0;
  padding: 11px 12px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.ai-note.success {
  color: var(--green);
  background: var(--green-soft);
}

.ai-note.error {
  color: var(--coral);
  background: var(--coral-soft);
}

.ai-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}

.generated-list {
  display: grid;
  gap: 12px;
  padding-bottom: 24px;
}

.generated-card {
  padding: 15px;
}

.generated-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.generated-card h3 {
  margin-bottom: 3px;
  font-size: 28px;
}

.generated-card dl {
  margin-top: 14px;
}

.auto-fill-status {
  margin-top: -6px;
  padding: 10px 12px;
  color: var(--muted);
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.auto-fill-status.found {
  color: var(--green);
  background: var(--green-soft);
  border-color: rgba(22, 108, 84, 0.22);
}

.auto-fill-status.missing {
  color: var(--coral);
  background: var(--coral-soft);
  border-color: rgba(180, 77, 63, 0.2);
}

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

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: 0;
}

input,
select {
  min-height: 46px;
  padding: 0 13px;
}

select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    #fff;
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 13px) 19px,
    0 0;
  background-size:
    5px 5px,
    5px 5px,
    100% 100%;
  background-repeat: no-repeat;
}

textarea {
  resize: vertical;
  padding: 12px 13px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(41, 95, 152, 0.14);
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  min-height: 44px;
  cursor: pointer;
  transition:
    transform 120ms ease,
    opacity 120ms ease,
    background 120ms ease;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.text-button:active,
.icon-button:active,
.tab-button:active {
  transform: scale(0.98);
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--green);
  border-radius: 8px;
  font-weight: 800;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.secondary-button,
.ghost-button {
  width: 100%;
  border-radius: 8px;
  font-weight: 800;
}

.secondary-button {
  color: var(--blue);
  background: var(--blue-soft);
}

.ghost-button {
  color: var(--coral);
  background: var(--coral-soft);
}

.text-button {
  min-height: 38px;
  padding: 0 10px;
  color: var(--blue);
  background: transparent;
  border-radius: 7px;
  font-weight: 800;
  white-space: nowrap;
}

.text-button.danger {
  color: var(--coral);
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  flex: 0 0 auto;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 22px;
  font-weight: 800;
}

.icon-button.small {
  width: 36px;
  height: 36px;
  min-height: 36px;
  font-size: 20px;
}

.speak-button {
  color: var(--blue);
  font-size: 13px;
}

.word-title-line,
.review-word-line,
.line-with-action,
.prompt-row,
.answer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-title-line h3 {
  margin-bottom: 0;
}

.line-with-action {
  justify-content: space-between;
}

.line-with-action > span,
.prompt-row p,
.answer-row p {
  min-width: 0;
  flex: 1 1 auto;
}

.prompt-row {
  margin: 18px 0;
  align-items: flex-start;
}

.review-card {
  padding: 16px;
}

.review-topline,
.word-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.review-word-line span {
  font-size: 28px;
  font-weight: 850;
}

.review-topline small {
  padding: 6px 9px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.prompt {
  margin: 0;
  font-size: 24px;
  line-height: 1.35;
  font-weight: 780;
}

.answer-box {
  margin-bottom: 12px;
}

.answer-panel {
  margin-top: 12px;
  padding: 14px;
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.answer-panel > span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.answer-row {
  align-items: flex-start;
  margin-bottom: 12px;
}

.answer-panel p {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.4;
  font-weight: 780;
}

dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

dl div {
  min-width: 0;
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

dd {
  margin: 3px 0 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.review-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.search-box {
  margin-bottom: 14px;
}

.lookup-box {
  margin-bottom: 10px;
}

.lookup-hint {
  margin-bottom: 14px;
  padding: 12px 14px;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.45;
}

.lookup-results {
  display: grid;
  gap: 12px;
  padding-bottom: 24px;
}

.lookup-result {
  padding: 15px;
}

.lookup-result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lookup-result h3 {
  margin-bottom: 3px;
  font-size: 28px;
}

.lookup-result .source {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 8px;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.lookup-result dl {
  margin-top: 14px;
}

.word-list {
  display: grid;
  gap: 12px;
  padding-bottom: 24px;
}

.word-list-item {
  display: flex;
  width: 100%;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  text-align: left;
}

.word-list-main {
  min-width: 0;
  flex: 1 1 auto;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.word-list-main strong {
  display: block;
  margin-bottom: 3px;
  font-size: 22px;
  line-height: 1.15;
}

.word-list-main small {
  display: block;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.word-list-arrow {
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.word-detail {
  display: grid;
  gap: 12px;
  padding-bottom: 24px;
}

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

.word-card {
  padding: 15px;
}

.word-card h3 {
  margin-bottom: 2px;
  font-size: 24px;
}

.meaning {
  margin-bottom: 0;
  color: var(--muted);
}

.word-card dl {
  margin-top: 14px;
}

.rich-card {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rich-card span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rich-card p {
  margin: 0;
  line-height: 1.45;
}

.note {
  margin: 12px 0 0;
  padding: 10px 12px;
  color: var(--coral);
  background: var(--coral-soft);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}

.empty-state {
  padding: 26px 18px;
  text-align: center;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 5;
  max-width: 420px;
  min-height: 44px;
  margin: 0 auto;
  padding: 12px 14px;
  color: #fff;
  background: rgba(23, 32, 38, 0.94);
  border-radius: 8px;
  text-align: center;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 640px) {
  .app-shell {
    padding-inline: 24px;
  }

  .hero-panel {
    grid-template-columns: 1.25fr 1fr;
    align-items: center;
  }

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

  .auto-fill-status,
  .card-form label:nth-child(n + 3),
  .card-form button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .tabbar {
    gap: 4px;
  }

  .tab-button {
    min-height: 40px;
    font-size: 13px;
  }

  .field-row,
  .ai-actions {
    grid-template-columns: 1fr;
  }
}
