/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg-primary:   #ffffff;
  --bg-secondary: #f9fafb;
  --bg-card:      #ffffff;
  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-hint:      #6b7280;
  --border-color:  rgba(0,0,0,.08);
  --border-input:  rgba(0,0,0,.12);
  --button-bg:     #f3f4f6;
  --link-color:    #2563eb;
  --accent-from:   #667eea;
  --accent-to:     #764ba2;
  --nav-height:    60px;
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg-primary:   #0b0f16;
  --bg-secondary: #111827;
  --bg-card:      #151e2d;
  --text-primary:   #e8eefc;
  --text-secondary: #d1d5db;
  --text-hint:      #9ca3af;
  --border-color:  rgba(255,255,255,.08);
  --border-input:  rgba(255,255,255,.12);
  --button-bg:     #1f2a44;
  --link-color:    #9cc2ff;
}

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

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
  transition: background-color .3s, color .3s;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app { max-width: 600px; margin: 0 auto; }

.view {
  display: none;
  padding: 16px;
  min-height: calc(100dvh - var(--nav-height) - var(--safe-bottom) - 32px);
}
.view.active { display: block; }

/* ── Search header ─────────────────────────────────────────────────────────── */
.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px;
}

.logo {
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -.5px;
}

.logo-sub {
  font-size: 12px;
  color: var(--text-hint);
  font-weight: 400;
  -webkit-text-fill-color: var(--text-hint);
  display: block;
}

/* ── Search box ────────────────────────────────────────────────────────────── */
.search-box {
  position: relative;
  margin-bottom: 8px;
}

#q {
  width: 100%;
  padding: 15px 48px 15px 18px;
  border-radius: 18px;
  border: 1.5px solid var(--border-input);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .3s;
}
#q:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(102,126,234,.18);
}
#q::-webkit-search-cancel-button { display: none; }
#q::placeholder { color: var(--text-hint); }

.search-hint {
  font-size: 12px;
  color: var(--text-hint);
  padding: 4px 4px 12px;
}

/* ── Result cards ──────────────────────────────────────────────────────────── */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 16px 44px 16px 16px;
  margin-bottom: 10px;
  position: relative;
  animation: slideUp .22s ease both;
  transition: border-color .2s;
}
.result-card:active { border-color: var(--accent-from); }

.card-word {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.card-dash { color: var(--text-hint); margin: 0 4px; }

.card-translation {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-hint);
}

.card-extra {
  font-size: 13px;
  color: var(--text-hint);
  margin-top: 8px;
  line-height: 1.55;
}
.card-extra b { color: var(--text-secondary); font-weight: 600; }

/* ── Favorite button ───────────────────────────────────────────────────────── */
.fav-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 4px;
  line-height: 1;
  color: var(--text-hint);
  transition: transform .15s, color .15s;
  border-radius: 50%;
}
.fav-btn:active { transform: scale(1.35); }
.fav-btn.is-fav { color: #f59e0b; }

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Theme toggle ──────────────────────────────────────────────────────────── */
#theme-toggle {
  background: var(--button-bg);
  border: 1px solid var(--border-input);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s;
}

/* ── Bottom nav ────────────────────────────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: linear-gradient(135deg, var(--accent-from) 0%, var(--accent-to) 100%);
  display: flex;
  z-index: 100;
  box-shadow: 0 -2px 24px rgba(102,126,234,.35);
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10px;
  padding: 8px 4px;
  transition: color .15s;
  position: relative;
}
.nav-btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.nav-btn.active { color: #fff; }
.nav-btn.active .nav-dot {
  display: block;
}
.nav-dot {
  display: none;
  position: absolute;
  top: 8px;
  width: 4px;
  height: 4px;
  background: white;
  border-radius: 50%;
}

/* ── Download overlay ──────────────────────────────────────────────────────── */
#download-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  animation: fadeIn .25s ease;
}

.dl-box {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.dl-icon {
  font-size: 64px;
  margin-bottom: 20px;
  display: block;
}

.dl-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
}

.dl-subtitle {
  font-size: 14px;
  color: var(--text-hint);
  margin-bottom: 28px;
  line-height: 1.6;
}

#dl-progress {
  width: 100%;
  height: 6px;
  border: none;
  border-radius: 3px;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-secondary);
  margin-bottom: 12px;
  display: block;
}
#dl-progress::-webkit-progress-bar   { background: var(--bg-secondary); border-radius: 3px; }
#dl-progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent-from), var(--accent-to));
  border-radius: 3px;
  transition: width .4s;
}
#dl-progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--accent-from), var(--accent-to));
}

#dl-status {
  font-size: 13px;
  color: var(--text-hint);
  min-height: 20px;
}

/* ── Offline banner ────────────────────────────────────────────────────────── */
#offline-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #f59e0b;
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 9px 16px;
  animation: slideUp .2s ease;
}

/* ── Install banner ────────────────────────────────────────────────────────── */
#install-banner {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 14px);
  left: 14px;
  right: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 90;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  animation: slideUp .3s ease;
}
#install-banner span { flex: 1; font-size: 14px; font-weight: 500; }

#install-btn {
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

#install-dismiss {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-hint);
  font-size: 20px;
  padding: 4px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── View headings ─────────────────────────────────────────────────────────── */
.view-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 18px;
  padding-top: 10px;
}

/* ── History / Favorites lists ─────────────────────────────────────────────── */
.list-item {
  padding: 13px 0;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: color .15s;
}
.list-item:active { color: var(--accent-from); }

.list-item-icon { font-size: 18px; color: var(--text-hint); flex-shrink: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub   { font-size: 13px; color: var(--text-hint); margin-top: 1px; }

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 24px; }

.settings-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-hint);
  margin-bottom: 8px;
  padding: 0 4px;
  font-weight: 600;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  margin-bottom: 8px;
  transition: background .2s;
}
.settings-row.tappable { cursor: pointer; }
.settings-row.tappable:active { background: var(--button-bg); }

.settings-row-title { font-size: 15px; }
.settings-row-value { font-size: 13px; color: var(--text-hint); }
.settings-row-arrow { color: var(--text-hint); }

.toggle {
  width: 46px; height: 26px;
  background: var(--border-input);
  border-radius: 13px;
  position: relative;
  cursor: pointer;
  transition: background .25s;
  border: none;
  flex-shrink: 0;
}
.toggle.on {
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform .25s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle.on::after { transform: translateX(20px); }

.action-btn {
  width: 100%;
  padding: 15px;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: #fff;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
  margin-top: 4px;
}
.action-btn:active   { transform: scale(.98); }
.action-btn:disabled { opacity: .5; cursor: not-allowed; }
.action-btn.secondary {
  background: var(--button-bg);
  color: var(--text-primary);
}

.support-link {
  display: block;
  text-align: center;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-from), var(--accent-to));
  color: #fff;
  border-radius: 14px;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  margin-top: 4px;
  transition: opacity .2s;
}
.support-link:active { opacity: .85; }

/* ── Phrase Translator ─────────────────────────────────────────────────────── */
#phrase-input {
  width: 100%;
  padding: 15px 18px;
  border-radius: 18px;
  border: 1.5px solid var(--border-input);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  resize: vertical;
  min-height: 90px;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .3s;
}
#phrase-input:focus {
  border-color: var(--accent-from);
  box-shadow: 0 0 0 3px rgba(102,126,234,.18);
}

.phrase-hint {
  font-size: 12px;
  color: var(--text-hint);
  padding: 8px 4px 14px;
}

.beta-badge-view {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  background: rgba(124,58,237,.12);
  color: #7c3aed;
  border-radius: 4px;
  font-weight: 700;
  vertical-align: middle;
  -webkit-text-fill-color: #7c3aed;
}
[data-theme="dark"] .beta-badge-view { background: rgba(167,139,250,.15); color: #a78bfa; -webkit-text-fill-color: #a78bfa; }

.phrase-token {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 13px 16px;
  margin-bottom: 8px;
  animation: slideUp .2s ease both;
}
.phrase-token.not-found {
  opacity: 0.55;
  display: flex;
  align-items: center;
  gap: 10px;
}
.phrase-token-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.phrase-token-word  { font-size: 18px; font-weight: 700; }
.phrase-token-arrow { color: var(--text-hint); font-size: 14px; }
.phrase-token-trans { font-size: 16px; color: var(--text-secondary); }
.phrase-token-meta  { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; align-items: center; }
.phrase-suffix {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  background: rgba(102,126,234,.1);
  color: var(--accent-from);
  border-radius: 999px;
  font-style: italic;
}

/* ── Empty states ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 16px 32px;
  color: var(--text-hint);
}
.empty-icon { font-size: 52px; margin-bottom: 14px; display: block; }
.empty-text { font-size: 15px; line-height: 1.6; max-width: 260px; margin: 0 auto; }

/* ── Loading ───────────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 28px;
  color: var(--text-hint);
  font-size: 14px;
}
