/* Telegram theme integration with fallbacks */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2481cc);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --accent: var(--tg-theme-accent-text-color, #2481cc);

  /* Gender colors (semantic, not themed) */
  --gender-der: #3478F6;
  --gender-die: #FF3B30;
  --gender-das: #34C759;
  --gender-plural: #FFCC00;

  /* Conjugation section colors */
  --prasens-bg: rgba(52, 120, 246, 0.05);
  --perfekt-bg: rgba(52, 199, 89, 0.05);
  --prateritum-bg: rgba(255, 149, 0, 0.05);
  --konjunktiv-bg: rgba(175, 82, 222, 0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  padding-top: env(safe-area-inset-top, 0px);
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  position: relative;
}

/* Search bar */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 12px;
  background: var(--secondary-bg);
  border-radius: 12px;
  flex-shrink: 0;
}

.search-icon {
  color: var(--hint);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  min-width: 0;
}

.search-bar input::placeholder {
  color: var(--hint);
}

.clear-btn {
  border: none;
  background: none;
  color: var(--hint);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Autocomplete suggestions */
.suggestions {
  position: absolute;
  top: calc(62px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 20;
  background: var(--secondary-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-height: 360px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.suggestion-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.suggestion-row:active {
  background: rgba(128,128,128,0.1);
}

.suggestion-row + .suggestion-row {
  border-top: 0.5px solid rgba(128,128,128,0.15);
}

.gender-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gender-dot-large {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.suggestion-word {
  font-weight: 500;
  flex-shrink: 0;
}

.suggestion-translation {
  color: var(--hint);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.level-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(36, 129, 204, 0.15);
  color: var(--link);
  flex-shrink: 0;
}

/* Results area */
.results {
  flex: 1;
  padding: 0 12px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Idle state */
.state-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 80px;
  color: var(--hint);
}

.idle-text {
  font-size: 16px;
}

/* Loading state */
.state-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 80px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Loading overlay (DB init) */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  color: var(--hint);
  transition: opacity 0.3s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Word card */
.word-card {
  background: var(--secondary-bg);
  border-radius: 16px;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

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

.card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.card-word {
  font-size: 28px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.pos-label {
  font-size: 14px;
  color: var(--hint);
}

.verb-badge {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 8px;
  font-weight: 500;
}

.badge-strong { background: rgba(175,82,222,0.15); color: #AF52DE; }
.badge-weak { background: rgba(175,82,222,0.15); color: #AF52DE; }
.badge-aux { background: rgba(90,200,250,0.15); color: #32ADE6; }

.plural-info {
  font-size: 12px;
  color: var(--hint);
}

.divider {
  height: 0.5px;
  background: rgba(128,128,128,0.2);
  margin: 12px 0;
}

/* Translations */
.translations {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.translation-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.translation-icon {
  color: var(--hint);
  flex-shrink: 0;
  font-size: 16px;
}

/* Conjugation table */
.conjugation-section, .declension-section {
  margin-top: 12px;
}

.section-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  margin-bottom: 4px;
}

.prasens-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 4px 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--prasens-bg);
}

.pronoun {
  font-size: 13px;
  color: var(--hint);
  text-align: right;
}

.conjugated {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 15px;
}

.tense-boxes {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.tense-box {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
}

.tense-box .section-label {
  margin-bottom: 4px;
}

.tense-box .conjugated {
  font-size: 14px;
}

.perfekt-box { background: var(--perfekt-bg); }
.prateritum-box { background: var(--prateritum-bg); }
.konjunktiv-box { background: var(--konjunktiv-bg); margin-top: 8px; }

/* Declension table */
.declension-grid {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 4px 16px;
  padding: 12px;
  border-radius: 8px;
}

.declension-grid.no-plural {
  grid-template-columns: 40px 1fr;
}

.decl-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
}

.decl-case {
  font-size: 13px;
  color: var(--hint);
}

.decl-form {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 15px;
}

/* Examples */
.examples-section {
  margin-top: 4px;
}

.example {
  margin-top: 8px;
}

.example-de {
  font-style: italic;
  font-size: 15px;
}

.example-en {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
}

/* Not found state */
.state-not-found {
  text-align: center;
  padding-top: 40px;
}

.not-found-icon {
  color: var(--hint);
  opacity: 0.5;
  margin-bottom: 8px;
}

.not-found-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.not-found-desc {
  font-size: 14px;
  color: var(--hint);
  margin-bottom: 20px;
}

.similar-words {
  text-align: left;
  margin-bottom: 20px;
}

.similar-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 8px;
  padding: 0 4px;
}

.wiktionary-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--link);
  text-decoration: none;
  font-size: 15px;
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(36, 129, 204, 0.1);
}

/* Utility */
.hidden {
  display: none !important;
}
