:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --primary: #4361ee;
  --primary-dark: #3145b0;
  --text: #1f2430;
  --muted: #6b7280;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(30, 41, 59, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: var(--card);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0 0 0.75rem;
  font-size: 1.4rem;
}

nav {
  display: flex;
  gap: 0.5rem;
}

.tab {
  border: none;
  background: #eef0f7;
  color: var(--muted);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.tab.active {
  background: var(--primary);
  color: white;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.5rem;
}

.view { display: none; }
.view.active { display: block; }

#search-form {
  display: flex;
  gap: 0.5rem;
}

#search-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid #dfe3ec;
  font-size: 1rem;
}

#search-form button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

#search-form button:hover { background: var(--primary-dark); }

#search-result { margin-top: 1.25rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.card .headword {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card .headword h2 {
  margin: 0;
  font-size: 1.6rem;
}

.card .phonetic {
  color: var(--muted);
  font-size: 1rem;
}

.card .translation {
  margin: 0.15rem 0 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--green);
}

.card .pos {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  background: #eaeeff;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-top: 0.4rem;
}

.card .definition {
  margin: 0.75rem 0 0.25rem;
  line-height: 1.5;
}

.card .example {
  color: var(--muted);
  font-style: italic;
  margin: 0;
}

.audio-btn {
  border: 1px solid #dfe3ec;
  background: white;
  border-radius: 50%;
  width: 2.1rem;
  height: 2.1rem;
  cursor: pointer;
  font-size: 1rem;
}

.save-btn, .list-save-hint {
  margin-top: 1rem;
  border: none;
  background: var(--green);
  color: white;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
}

.save-btn:disabled {
  background: #a9adba;
  cursor: default;
}

.save-btn.already-saved {
  display: inline-block;
  background: #a9adba;
  cursor: default;
}

.error {
  color: var(--red);
  font-weight: 600;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

.hidden { display: none !important; }

.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.list-filter {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.list-filter button {
  border: none;
  background: #eef0f7;
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.list-filter button.active {
  background: var(--primary);
  color: white;
}

#list-sort {
  border: 1px solid #dfe3ec;
  background: white;
  color: var(--text);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.word-list { display: flex; flex-direction: column; gap: 0.75rem; }

.word-row {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.word-row .w-summary {
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  cursor: pointer;
}

.word-row .w-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.word-row .chevron {
  color: var(--muted);
  font-size: 0.8rem;
  width: 0.8rem;
  display: inline-block;
}

.word-row strong {
  font-size: 1.1rem;
  text-transform: capitalize;
}

.status-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge.status-know { background: #dcfce7; color: #15803d; }
.status-badge.status-dont-know { background: #fee2e2; color: #b91c1c; }
.status-badge.status-new { background: #eef0f7; color: var(--muted); }

.word-row .w-details {
  padding: 0 1.25rem 1rem 2.55rem;
}

.word-row .w-details p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.word-row .w-details .w-example {
  margin-top: 0.35rem;
  font-style: italic;
}

.word-row .w-translation {
  font-weight: 600;
  color: var(--green);
  font-size: 0.95rem;
}

.delete-btn {
  border: none;
  background: none;
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.flash-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.flash-progress {
  color: var(--muted);
  font-weight: 600;
}

.direction-btn {
  border: 1px solid #dfe3ec;
  background: white;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

.flashcard {
  perspective: 1200px;
  height: 280px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}

.flashcard-front {
  background: var(--primary);
  color: white;
  font-size: 2rem;
  font-weight: 700;
  text-transform: capitalize;
}

.flashcard-back {
  background: var(--card);
  transform: rotateY(180deg);
  gap: 0.5rem;
}

.flashcard-back .fb-word { font-size: 1.4rem; font-weight: 700; text-transform: capitalize; color: var(--primary); }
.flashcard-back .fb-def { font-size: 1.05rem; line-height: 1.5; }
.flashcard-back .fb-example { color: var(--muted); font-style: italic; }

.flash-controls {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

.flash-controls button {
  flex: 1;
  padding: 0.8rem;
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.btn-know { background: var(--green); color: white; }
.btn-dont-know { background: var(--red); color: white; }

.flash-restart-wrap {
  text-align: center;
  margin-top: 1.5rem;
}

.flash-restart-wrap button {
  border: none;
  background: var(--primary);
  color: white;
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
}
