:root {
  --primary: #1D4ED8;
  --primary-dark: #1E40AF;
  --primary-light: #DBEAFE;
  --primary-glow: rgba(29, 78, 216, 0.15);
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --radius-sm: 8px;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --font: 'Source Sans Pro', system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #1D4ED8;
    --primary-dark: #60A5FA;
    --primary-light: #1a2744;
    --primary-glow: rgba(29, 78, 216, 0.15);
    --bg: #131313;
    --surface: #1e1e1e;
    --text: #e8e8e8;
    --text-secondary: #a8a8a8;
    --text-muted: #6b6b6b;
    --border: #333333;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.no-scroll {
  overflow: hidden;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px;
}

main.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 0 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.header-actions {
  display: flex;
  gap: 2px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.header-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  font-size: inherit;
  font-weight: inherit;
  margin: 0;
  line-height: inherit;
}

.logo-icon {
  border-radius: 6px;
  flex-shrink: 0;
}

.logo-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

/* ── Search ── */
.search-wrapper {
  position: relative;
  padding-bottom: 18px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 17px;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color 0.2s;
}

#searchInput {
  width: 100%;
  padding: 13px 16px 13px 46px;
  font-size: 16px;
  font-family: var(--font);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

#searchInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: var(--surface);
}

#searchInput:focus ~ .search-icon {
  color: var(--primary);
}

#searchInput::placeholder {
  color: var(--text-muted);
}

/* ── Suggestions dropdown ── */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
  max-height: 320px;
  overflow-y: auto;
  display: none;
  margin-top: -2px;
}

.suggestions.visible {
  display: block;
}

.suggest-header {
  padding: 8px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.suggest-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}

.suggest-item:hover {
  background: var(--primary-light);
}

.suggest-item-word {
  flex: 1;
  min-width: 0;
}

.suggest-hint {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}

.history-item:hover {
  background: var(--primary-light);
}

.suggest-bookmark {
  flex-shrink: 0;
  color: var(--text-muted);
  opacity: 0.4;
}

.suggest-bookmark.on {
  opacity: 1;
  color: #f59e0b;
}

/* ── Offline banner ── */
.offline-banner {
  display: none;
  text-align: center;
  padding: 6px 14px;
  font-size: 12px;
  background: #fef3cd;
  color: #92400e;
}

.is-offline .offline-banner {
  display: block;
}

@media (prefers-color-scheme: dark) {
  .offline-banner {
    background: #332b0e;
    color: #fbbf24;
  }
}

/* ── Results ── */
.results {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* State messages */
.state-message {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
}

.state-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.state-sub {
  font-size: 14px;
}

/* ── Skeleton loading ── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton-list {
  padding: 8px 0;
}

.skeleton-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--border) 25%, var(--surface) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-line.word {
  width: 120px;
}

.skeleton-line.hint {
  width: 80px;
  height: 11px;
  opacity: 0.6;
}

/* Search shortcut hint */
.search-hint {
  position: absolute;
  right: 18px;
  top: 17px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.4;
  pointer-events: none;
  font-family: inherit;
  letter-spacing: 0.3px;
}

#searchInput:focus ~ .search-hint {
  display: none;
}

@media (max-width: 480px) {
  .search-hint { display: none; }
  .suggestions { max-height: 240px; }
}

/* Result bar (history) */
.result-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.result-count {
  font-size: 13px;
  color: var(--text-muted);
}

.result-count strong {
  color: var(--primary);
  font-weight: 700;
}

/* ── Action button (shared) ── */
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  padding: 0;
  line-height: 0;
}

.action-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.action-btn:active {
  transform: scale(0.92);
}

.action-btn.speaking {
  color: var(--primary);
  animation: speak-pulse 0.6s ease-in-out infinite;
}

.copy-btn.copied {
  color: #16a34a;
}

.copy-btn.copied svg {
  animation: copy-pop 0.3s ease;
}

@keyframes copy-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes speak-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.action-btn svg {
  width: 18px;
  height: 18px;
}

/* Bookmark button */
.bookmark-btn {
  margin-left: auto;
}

.bookmark-btn.bookmarked {
  color: #f59e0b;
}

/* History view */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.history-item-word {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.history-item-time {
  font-size: 11px;
  color: var(--text-muted);
}

.history-clear {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  text-align: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.history-clear:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* ── Word detail (inline) ── */
.word-detail {
  padding: 20px 0;
}

.word-detail .card-section:first-child {
  margin-top: 0;
}

.word-heading {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.word-pos {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: lowercase;
  letter-spacing: 0.3px;
  display: inline-block;
}

.word-hindi {
  font-size: 17px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
}

.word-hindi .sep {
  color: var(--text-muted);
  margin: 0 3px;
}

.word-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

/* Section inside card */
.card-section {
  margin-top: 14px;
}

.card-section:first-child {
  margin-top: 12px;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--primary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Definitions */
.def-group {
  margin-bottom: 10px;
}

.def-group:last-child {
  margin-bottom: 0;
}

.def-pos-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: lowercase;
}

.def-sense {
  font-size: 14px;
  line-height: 1.6;
  padding-left: 20px;
  position: relative;
  margin-bottom: 2px;
  color: var(--text-secondary);
}

.defs-section {
  counter-reset: sense-counter;
}

.def-sense::before {
  content: counter(sense-counter) '.';
  counter-increment: sense-counter;
  position: absolute;
  left: 0;
  color: var(--text-muted);
  font-size: 12px;
}

/* Examples */
.example {
  font-size: 14px;
  line-height: 1.6;
  padding-left: 16px;
  position: relative;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 2px;
}

.example::before {
  content: '\201C';
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

.example::after {
  content: '\201D';
  color: var(--text-muted);
}

/* Synonyms / Antonyms */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-align: left;
  white-space: nowrap;
}

.tag:hover {
  background: #BFDBFE;
  opacity: 0.85;
}

.tag:active {
  transform: scale(0.96);
}

.tag.antonym {
  background: #fde8e8;
  color: #b91c1c;
}

.tag.antonym:hover {
  background: #fbd5d5;
}

@media (prefers-color-scheme: dark) {
  .tag:hover {
    background: #2e2e2e;
    opacity: 1;
  }
  .tag.antonym {
    background: #2d1a1a;
    color: #f87171;
  }
  .tag.antonym:hover {
    background: #3d2222;
  }
}

/* Highlight */
mark.highlight {
  background: none;
  color: var(--primary);
  font-weight: 700;
}

/* ── Overlay (history / bookmarks) ── */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: var(--bg);
  display: none;
  flex-direction: column;
  animation: overlayIn 0.15s ease-out;
  overscroll-behavior: contain;
}

.overlay.open {
  display: flex;
}

@keyframes overlayIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.overlay-content {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.overlay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.overlay-header h2 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
}

.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.export-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.export-btn:hover {
  opacity: 0.9;
}

@media (prefers-color-scheme: dark) {
  .export-btn {
    background: var(--primary);
    color: #fff;
  }
}

/* Bookmark list */
.bookmarks-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.empty-msg {
  text-align: center;
  padding: 48px 20px;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.bookmark-item:hover {
  background: var(--primary-light);
}

.bookmark-item-star {
  flex-shrink: 0;
  color: #f59e0b;
}

.bookmark-item-word {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

.bookmark-item-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.bookmark-item-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  transition: background 0.12s, color 0.12s;
}

.bookmark-item-remove:hover {
  background: #fee2e2;
  color: #b91c1c;
}

/* History list */
.history-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.clear-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  text-align: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.clear-btn:hover {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

/* ── Footer ── */
.footer {
  border-top: 1px solid var(--border);
  padding: 14px 0;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
}

.footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.footer a:hover {
  text-decoration: underline;
}

/* ── Install banner ── */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s;
}

.install-banner.visible {
  transform: translateY(0);
  opacity: 1;
}

.install-banner-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-banner-text {
  flex: 1;
  min-width: 0;
}

.install-banner-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.install-banner-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.install-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.install-btn:hover {
  opacity: 0.9;
}

.install-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.install-dismiss:hover {
  background: var(--primary-light);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  .install-banner {
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.3);
  }
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .header {
    padding: 14px 0 0;
  }

  .container {
    padding: 0 14px;
  }

  .search-wrapper {
    padding-bottom: 14px;
  }

  #searchInput {
    padding: 12px 14px 12px 42px;
    font-size: 16px;
  }

  .search-icon {
    left: 12px;
    width: 18px;
    height: 18px;
    top: 15px;
  }

  .def-sense {
    font-size: 13px;
    padding-left: 18px;
  }

  .example {
    font-size: 13px;
  }

  .state-message {
    padding: 24px 16px;
  }

  .overlay-content {
    padding: 14px;
  }
}
