:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --border: #e3dfd7;
  --text: #1f1d1a;
  --muted: #7a756c;
  --accent: #0b6e4f;
  --accent-soft: #d9ede4;
  --danger: #b23a48;
  --good: #2e7d4f;
  --shadow: 0 2px 8px rgba(30, 25, 15, 0.06);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

/* The HTML [hidden] attribute normally maps to display:none via the UA
 * stylesheet, but any class-level `display` rule (e.g. `.loader-card {
 * display: flex }`) has higher specificity and will override it. Force
 * it globally so `el.hidden = true` actually hides the element. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1 {
  font-family: "Georgia", serif;
  font-weight: 600;
  margin: 0;
}

button {
  font: inherit;
  cursor: pointer;
  padding: 0.55rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  transition: opacity 0.15s;
}

button:hover {
  opacity: 0.9;
}

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

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.good {
  background: var(--good);
}

button.bad {
  background: var(--danger);
}

input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

label input {
  margin-top: 0.25rem;
  color: var(--text);
}

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

/* ---------- loader ---------- */

.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid rgba(0, 0, 0, 0.12);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -0.15em;
}

.spinner.lg {
  width: 2.25rem;
  height: 2.25rem;
  border-width: 3px;
}

.spinner.on-dark {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: white;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  gap: 0.75rem;
}

button[disabled],
button[aria-busy="true"] {
  opacity: 0.7;
  cursor: wait;
}

button .spinner {
  margin-right: 0.4rem;
}

/* ---------- mic / voice-input button ---------- */

/* Groups an input + mic button together so they're always vertically
 * aligned and treated as a single visual unit inside a form label. */
.input-with-mic {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.input-with-mic > input,
.input-with-mic > textarea {
  flex: 1 1 auto;
  margin-top: 0;
}

.mic-btn {
  padding: 0 0.9rem;
  font-size: 1.15rem;
  line-height: 1;
  min-width: 2.8rem;
  align-self: stretch;
  flex-shrink: 0;
}

.mic-btn.listening {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
  animation: mic-pulse 1.1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(178, 58, 72, 0.55);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(178, 58, 72, 0);
  }
}

.error {
  color: var(--danger);
  margin-top: 0.5rem;
}

/* ---------- login ---------- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 2rem;
  text-align: center;
  color: var(--accent);
}

.login-card .tagline {
  text-align: center;
  color: var(--muted);
  margin: 0.25rem 0 1.5rem;
  font-style: italic;
}

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 0.5rem;
}

/* ---------- app layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 1.25rem;
  color: var(--accent);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  justify-content: center;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 0.4rem 0.9rem;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

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

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

.row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row .grow {
  flex: 1 1 160px;
}

/* The Auto-translate button gets its own row to keep it away from the
 * Italian input above and the Hebrew/English inputs below. */
.row.translate-row {
  justify-content: flex-end;
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
  resize: vertical;
  min-height: 2.5rem;
}

textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

select {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}

/* ---------- translate tab ---------- */

.result-card {
  margin-top: 1rem;
}

.result-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

#translate-italian {
  margin: 0.25rem 0 1rem;
  font-size: 2rem;
}

#translate-alternatives {
  margin: 0.25rem 0 1rem 1.25rem;
  padding: 0;
  font-size: 1.05rem;
  color: var(--text);
}

#translate-alternatives li {
  margin: 0.15rem 0;
}

.translate-note {
  margin: 0.5rem 0;
  padding: 0.55rem 0.75rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

/* ---------- bulk add ---------- */

.bulk-add {
  margin-top: 1.25rem;
}

.bulk-add > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
  padding: 0.25rem 0;
}

.bulk-add > summary::-webkit-details-marker {
  display: none;
}

.bulk-add[open] > summary {
  margin-bottom: 0.75rem;
}

.bulk-help {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

#bulk-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.bulk-controls {
  margin-bottom: 0.5rem;
}

.bulk-progress {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.bulk-item {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, auto) 1fr;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.bulk-icon {
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.bulk-word {
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

.bulk-msg {
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

.bulk-pending {
  opacity: 0.7;
}

.bulk-processing {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.bulk-done .bulk-icon {
  color: var(--good);
}

.bulk-done .bulk-word strong {
  color: var(--accent);
}

.bulk-failed {
  background: #fdecee;
  border-color: #f0b4ba;
}

.bulk-failed .bulk-icon {
  color: var(--danger);
}

.bulk-skipped {
  opacity: 0.65;
}

.correction {
  margin: 0.25rem 0 0.75rem;
  padding: 0.6rem 0.8rem;
  background: #fff7e6;
  border: 1px solid #f0c674;
  border-radius: var(--radius);
  color: #8a5a00;
  font-size: 0.95rem;
}

.morphology {
  margin: 0.25rem 0 1rem;
  padding: 0.75rem 1rem;
  background: #f3efe7;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}

.morph-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.95rem;
}

.morph-head strong {
  color: var(--accent);
  font-family: "Georgia", serif;
  font-size: 1.15rem;
}

.morph-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0.75rem 0 0.25rem;
}

#morph-related {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1rem;
}

#morph-related li {
  font-size: 0.95rem;
  padding: 0.15rem 0;
}

#morph-related strong {
  color: var(--accent);
}

#morph-related .pos {
  font-size: 0.75rem;
  font-style: italic;
}

@media (max-width: 600px) {
  #morph-related {
    grid-template-columns: 1fr;
  }
}

.correction s {
  color: var(--danger);
  opacity: 0.8;
}

.correction strong {
  color: var(--accent);
}

/* ---------- words table ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.toolbar input {
  flex: 1;
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  padding: 0.6rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

thead th {
  background: #f3efe7;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: none;
}

td.it {
  font-weight: 600;
  color: var(--accent);
}

.row-actions {
  text-align: right;
  white-space: nowrap;
}

.row-actions button {
  padding: 0.25rem 0.5rem;
  margin-left: 0.25rem;
}

.stat-inline {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.learned-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ---------- quiz ---------- */

.quiz-card {
  text-align: center;
  padding: 2rem 1.5rem;
}

.quiz-word {
  font-family: "Georgia", serif;
  font-size: 2.5rem;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.quiz-row {
  margin: 0.4rem 0;
  font-size: 1.05rem;
}

.quiz-row .muted {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.4rem;
}

.quiz-buttons {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.quiz-buttons button {
  padding: 0.75rem 1.4rem;
  font-size: 1rem;
}

.quiz-history {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
}

/* ---------- quiz progress bar ---------- */

.quiz-progress {
  margin-bottom: 1rem;
}

.quiz-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.quiz-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

#quiz-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.3s ease;
}

.done-card {
  text-align: center;
  padding: 2.5rem 1.5rem;
}

.done-emoji {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.done-title {
  font-family: "Georgia", serif;
  font-size: 1.75rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.done-sub {
  font-size: 0.95rem;
}

/* ---------- small screens ---------- */

@media (max-width: 600px) {
  .topbar {
    flex-wrap: wrap;
  }
  .tabs {
    order: 3;
    width: 100%;
    justify-content: space-around;
  }
  .quiz-word {
    font-size: 2rem;
  }
  th,
  td {
    padding: 0.5rem 0.5rem;
  }
}
