:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6a63;
  --border: #e4e2da;
  --accent: #0f6e5c;
  --accent-contrast: #ffffff;
  --arabic: #7a3b12;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14150f;
    --surface: #1e1f18;
    --text: #f1efe6;
    --muted: #a6a495;
    --border: #34362a;
    --accent: #4fd6ae;
    --accent-contrast: #0a2620;
    --arabic: #f0b27a;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }

[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, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px 4px;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.search-wrap {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px 14px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

.search-icon { color: var(--muted); flex: none; }

#search-input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

#search-input::placeholder { color: var(--muted); }

.clear-btn {
  border: none;
  background: var(--border);
  color: var(--text);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.suggestions {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(100% - 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 20;
}

.suggestions li {
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.suggestions li:hover,
.suggestions li.active {
  background: var(--bg);
}

.suggestions .s-word { font-weight: 600; }
.suggestions .s-word mark { background: none; color: var(--accent); font-weight: 700; }
.suggestions .s-arabic { color: var(--arabic); font-size: 1rem; direction: rtl; }

.status {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 10px;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1em;
}

.results {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 6px 16px 40px;
}

.empty-state {
  color: var(--muted);
  padding: 24px 4px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.az-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 18px;
}

.az-nav button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

.az-nav button:hover { border-color: var(--accent); color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  animation: fadein .15s ease-out;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: none; }
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.card-word {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.card-note {
  font-style: italic;
  color: var(--muted);
  font-size: 0.85rem;
}

.sense {
  padding: 8px 0;
  border-top: 1px dashed var(--border);
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.sense:first-child { border-top: none; padding-top: 0; }

.sense-context {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.sense-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.sense-phonetic {
  font-style: italic;
  color: var(--text);
  font-size: 1rem;
}

.sense-arabic {
  direction: rtl;
  font-size: 1.35rem;
  color: var(--arabic);
  font-family: "Noto Naskh Arabic", "Traditional Arabic", "Geeza Pro", "Arabic Typesetting", serif;
  flex: none;
}

.examples {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.example {
  margin-bottom: 8px;
  font-size: 0.92rem;
}

.example:last-child { margin-bottom: 0; }

.example-fr {
  color: var(--muted);
  font-style: italic;
}

.example-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.example-phonetic { font-style: italic; }

.example-arabic {
  direction: rtl;
  color: var(--arabic);
  font-family: "Noto Naskh Arabic", "Traditional Arabic", "Geeza Pro", "Arabic Typesetting", serif;
  font-size: 1.1rem;
  flex: none;
}

.card-page {
  margin-top: 10px;
  text-align: right;
  font-size: 0.72rem;
  color: var(--muted);
}

.no-results {
  color: var(--muted);
  padding: 20px 4px;
}

@media (min-width: 480px) {
  .sense-row, .example-row { flex-wrap: nowrap; }
}
