/* Search */
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search:focus-within {
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .18);
}
.search input {
  flex: 1;
  border: 0;
  background: transparent;
  outline: none;
  font-size: 17px;
  padding: 6px 4px;
}
.search button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--green-600);
  color: #fff;
}
.search button svg { width: 18px; height: 18px; fill: #fff; }
.search button:active { background: var(--green-700); }

/* Generic buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  background: var(--surface-2);
  color: var(--text);
  transition: transform .1s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn--primary {
  background: var(--green-600);
  color: #fff;
}
.btn--primary:active { background: var(--green-700); }
.btn--ghost {
  background: transparent;
  color: var(--green-700);
}
.btn--danger { color: var(--danger); background: transparent; }
.btn--block { width: 100%; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }

.btn svg { width: 18px; height: 18px; fill: currentColor; }

/* Icon button */
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.is-active { color: var(--green-600); }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 12px; }

/* Word result */
.word-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.word-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.15;
}
.word-phonetic {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pos {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--green-700);
  background: var(--green-100);
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 14px 0 8px;
}
.defs { margin: 0; padding: 0; }
.defs li {
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}
.defs li:last-child { border-bottom: 0; }
.def-example {
  margin-top: 4px;
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
}
.syns {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.syns b { color: var(--text); font-weight: 600; }

/* Chips / tags */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--green-100);
  color: var(--green-700);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.chip--muted { background: var(--surface-2); color: var(--muted); }
.chip button { color: inherit; line-height: 1; padding: 0 0 0 2px; font-size: 14px; }

/* List items */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.list-item__main { flex: 1; min-width: 0; }
.list-item__word {
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-transform: lowercase;
}
.list-item__meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.list-item__actions { display: flex; gap: 4px; }

/* Sync status dot — grey = local-only, green = mirrored to server. */
.sync-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.55;
}
.sync-dot.is-synced {
  background: var(--green-500);
  opacity: 1;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}
.empty__emoji {
  font-size: 42px;
  margin-bottom: 8px;
}
.empty__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}

/* Section title */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin: 20px 4px 8px;
}

/* Notes editor */
.field { display: block; margin-top: 10px; }
.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 4px;
}
.field textarea,
.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  outline: none;
  resize: vertical;
}
.field textarea:focus,
.field input:focus {
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, .16);
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 4px 10px;
  margin: -4px -4px 10px;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-bar .chip {
  cursor: pointer;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  border: 1px solid transparent;
}
.filter-bar .chip.is-on {
  background: var(--green-600);
  color: #fff;
}

/* Flashcard */
.flashcard {
  perspective: 1200px;
  margin: 8px 0 20px;
}
.flashcard__inner {
  position: relative;
  width: 100%;
  min-height: 240px;
  transform-style: preserve-3d;
  transition: transform .5s ease;
  cursor: pointer;
}
.flashcard.is-flipped .flashcard__inner { transform: rotateY(180deg); }
.flashcard__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: var(--shadow);
}
.flashcard__face--back {
  transform: rotateY(180deg);
  background: linear-gradient(135deg, var(--green-50), var(--surface));
}
.flashcard__word {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.flashcard__hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}
.flashcard__defs { font-size: 15px; color: var(--text); }
.flashcard__defs .pos { margin-top: 8px; }

/* Quiz MCQ */
.quiz-q {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.45;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--green-50);
  color: var(--green-800);
  margin-bottom: 16px;
}
@media (prefers-color-scheme: dark) {
  .quiz-q { background: rgba(16,185,129,.08); color: var(--green-300); }
}

.mcq { display: grid; gap: 10px; }
.mcq button {
  text-align: left;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.4;
  transition: transform .1s ease, border-color .15s ease, background .15s ease;
}
.mcq button:active { transform: scale(.99); }
.mcq button.correct {
  border-color: var(--green-500);
  background: var(--green-50);
  color: var(--green-800);
}
.mcq button.wrong {
  border-color: var(--danger);
  background: #fef2f2;
  color: var(--danger);
}
@media (prefers-color-scheme: dark) {
  .mcq button.correct { background: rgba(16,185,129,.12); color: var(--green-300); }
  .mcq button.wrong { background: rgba(220,38,38,.12); }
}
.mcq button[disabled] { cursor: default; }

/* Stats row */
.stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.stat {
  flex: 1;
  text-align: center;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat__num { font-size: 22px; font-weight: 700; color: var(--green-700); }
.stat__label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* Sync banner (shown to anonymous users on Saved/History) */
.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--green-50);
  color: var(--green-800);
  border: 1px solid var(--green-200);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
.banner:active { background: var(--green-100); }
.banner__chev { color: var(--green-700); font-weight: 700; }
@media (prefers-color-scheme: dark) {
  .banner { background: rgba(16,185,129,.10); color: var(--green-300); border-color: rgba(16,185,129,.25); }
}

/* Header user chip */
.user-chip {
  display: inline-flex;
  align-items: center;
  max-width: 160px;
  padding: 6px 12px;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 32px;
}
.user-chip:active { background: var(--green-100); }

/* Auth view */
.auth-card { max-width: 420px; margin: 16px auto 0; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 12px;
}
.auth-tabs .btn {
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  border-radius: 8px;
}
.auth-tabs .btn.is-on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.form-error {
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* Helpers */
.hstack { display: flex; align-items: center; gap: 8px; }
.vstack { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.hidden { display: none !important; }
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--green-200);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
