:root {
  --brand-primary: #B71F28;
  --brand-secondary: #F2E205;
  --brand-accent: #FE0000;
  --brand-bg: #B71F28;
  --content-bg: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #3a3a3a;
  --text-muted: #666;
  --text-light: #888;
  --border-color: #e2e8f0;
  --highlight: #fef3c7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 6px 16px -2px rgba(0,0,0,0.12), 0 3px 6px -2px rgba(0,0,0,0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --transition: all 0.22s ease;
  --success: #10b981;
  --error: #ef4444;
  --cefr-gray: #6b7280;
}

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

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

body {
  font-family: 'Inter', sans-serif;
  background: linear-gradient(to bottom, var(--brand-bg) 220px, #f8f9fa 220px), #f8f9fa;
  background-size: 100% 220px, 100% 100%;
  background-repeat: no-repeat, no-repeat;
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page-wrapper {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.dictionary-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin: 24px auto;
  max-width: 860px;
  width: calc(100% - 48px);
  background: var(--content-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.dictionary-header {
  background: var(--brand-bg);
  color: white;
  padding: 32px 40px;
  position: relative;
}

.dictionary-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 6px;
  background: var(--brand-secondary);
}

.dictionary-header h1 {
  font-family: 'Source Serif Pro', serif;
  font-weight: 700;
  font-size: 2.6rem;
  letter-spacing: -1px;
  cursor: pointer;
  transition: var(--transition);
}

.dictionary-header h1:hover {
  color: var(--brand-secondary);
}

.tagline {
  color: rgba(255, 255, 255, .9);
  font-size: 1.1rem;
  margin-top: 8px;
  font-weight: 500;
}

.auth-container {
  position: absolute;
  top: 16px;
  right: 40px;
}

.auth-indicator {
  font-size: 0.95rem;
  color: white;
}

.auth-indicator a {
  color: white;
  text-decoration: none;
  cursor: pointer;
  font-weight: 600;
}

.control-bar {
  padding: 28px 40px;
  background: var(--content-bg);
  border-bottom: 1px solid var(--border-color);
}

.search-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-input {
  padding: 15px 20px;
  font-size: 1.2rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  background: #fdfdfd;
}

.search-input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 4px rgba(183, 31, 40, .18);
  background: white;
}

.button-group {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

.random-btn,
.exercise-btn,
.review-btn,
.keyboard-toggle-btn {
  flex: 1;
  min-width: 0;
  padding: 13px 18px;
  font-size: .98rem;
  font-weight: 600;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.review-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.random-btn:hover,
.exercise-btn:hover,
.review-btn:hover:not(:disabled),
.keyboard-toggle-btn:hover {
  background: var(--brand-secondary);
  border-color: var(--brand-secondary);
  color: #1a1a1a;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(242, 226, 5, .3);
}

.random-btn:active,
.exercise-btn:active,
.review-btn:active,
.keyboard-toggle-btn:active {
  transform: translateY(0);
}

.virtual-keyboard {
  margin-top: 18px;
  background: white;
  border: 2px solid var(--brand-secondary);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.keyboard-content {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.keyboard-row {
  display: flex;
  gap: 7px;
  justify-content: center;
}

.key {
  width: 48px;
  height: 52px;
  font-size: 1.15rem;
  font-weight: 600;
  background: white;
  border: 1.8px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  color: var(--text-primary);
  user-select: none;
}

.key.wide {
  width: 150px;
  font-size: .95rem;
  font-weight: 500;
}

.key:hover {
  background: var(--brand-secondary);
  color: #1a1a1a;
  border-color: var(--brand-secondary);
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(242, 226, 5, .3);
}

.key:active {
  background: #e6d604;
  transform: translateY(0);
}

.key:focus {
  outline: 3px solid var(--brand-secondary);
  outline-offset: 2px;
}

.results-container {
  flex: 1;
  min-height: auto;
  padding: 36px 40px;
  background: var(--content-bg);
}

.no-result {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 50px 0;
  font-size: 1.15rem;
}

.entry {
  padding: 32px 0;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.entry:last-child {
  border-bottom: none;
}

.headword {
  font-family: 'Source Serif Pro', serif;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.7px;
  margin-bottom: 6px;
}

.headword.kyrgyz {
  font-family: 'Inter', sans-serif;
  font-size: 2.35rem;
  line-height: 1.2;
}

.pronunciation {
  color: var(--text-muted);
  font-size: 1.15rem;
  font-style: italic;
  margin-bottom: 14px;
}

.translation {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--brand-primary);
  display: inline-block;
  padding: 3px 0;
  transition: var(--transition);
}

.translation:hover {
  background: rgba(183, 31, 40, 0.12);
  border-radius: 6px;
  padding: 3px 6px;
  margin: -3px -6px;
}

.translation.kyrgyz {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
}

.pos,
.topic-tag,
.level-tag {
  padding: 7px 14px;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.pos {
  background: var(--brand-primary);
  color: white;
}

.topic-tag {
  background: var(--brand-secondary);
  color: #1a1a1a;
}

.level-tag {
  background: var(--cefr-gray);
  color: white;
}

.pos:hover,
.topic-tag:hover,
.level-tag:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, .15);
}

.tags-container {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.sense-item {
  position: relative;
  padding-right: 140px;
  margin-top: 26px;
}

.sense-item:first-child {
  margin-top: 0;
}

.sense-item .tags-container {
  position: absolute;
  right: 0;
  top: 0;
}

.section-title {
  font-size: .92rem;
  font-weight: 600;
  color: var(--text-light);
  margin: 22px 0 11px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
}

.sense-number {
  font-weight: 700;
  color: var(--brand-primary);
  margin-right: 9px;
}

.examples-list {
  list-style: none;
  margin-top: 9px;
}

.example-item {
  margin-bottom: 15px;
  padding-left: 4px;
}

.example-original {
  font-style: italic;
  color: var(--text-secondary);
  display: block;
}

.example-translation {
  font-size: .96rem;
  color: var(--text-muted);
  display: block;
  margin-top: 3px;
}

.grammar-list {
  list-style: none;
  background: transparent;
  padding: 0;
  border: none;
  margin-top: 10px;
}

.grammar-item {
  padding: 7px 0;
  border-bottom: 1px solid var(--border-color);
}

.grammar-item:last-child {
  border-bottom: none;
}

.grammar-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-right: 9px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 18px;
  margin-top: 10px;
}

.related-item {
  display: flex;
  flex-direction: column;
  min-width: 135px;
}

.related-word {
  font-weight: 600;
  color: var(--text-primary);
}

.related-translation {
  font-size: .92rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.grammar-table {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 8px;
  border-radius: var(--radius-sm);
  background: #fdfdfd;
  padding: 4px 0;
}

.grammar-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: .94rem;
  min-width: 580px;
}

.grammar-table th,
.grammar-table td {
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.grammar-table th {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: .88rem;
  background: transparent;
  position: sticky;
  top: 0;
  z-index: 1;
}

.grammar-table .case-label {
  color: var(--text-light);
  font-weight: 500;
  width: 40px;
  min-width: 40px;
}

.grammar-table tbody tr {
  background: transparent;
  transition: background 0.2s ease;
}

.grammar-table tbody tr:hover {
  background: rgba(242, 226, 5, 0.08);
}

.grammar-table tbody tr + tr td {
  padding-top: 12px;
}

.filter-modal,
.exercise-modal,
.saved-modal,
.flashcard-modal,
.auth-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(5px);
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: white;
  margin: 6% auto;
  padding: 30px;
  border-radius: var(--radius-md);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  color: var(--brand-primary);
  font-size: 1.4rem;
  font-weight: 600;
}

.close-modal {
  background: none;
  border: none;
  font-size: 1.7rem;
  cursor: pointer;
  color: var(--text-light);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--transition);
}

.close-modal:hover {
  background: #fee2e2;
  color: var(--brand-primary);
}

.filter-list,
.saved-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.filter-item,
.saved-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-item:hover,
.saved-item:hover {
  background: #fffbeb;
  border-color: var(--brand-primary);
}

.filter-item:last-child,
.saved-item:last-child {
  border-bottom: none;
}

.saved-item .remove-word {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-light);
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.saved-item .remove-word:hover {
  color: var(--error);
  background: #fef2f2;
}

.exercise-question {
  font-size: 1.55rem;
  font-weight: 600;
  margin-bottom: 26px;
  text-align: center;
  color: var(--brand-primary);
}

.answer-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 26px;
}

.answer-option {
  padding: 20px;
  border: 2.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #fdfdfd;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  font-weight: 500;
  font-size: 1.08rem;
}

.answer-option:hover:not(.selected):not(.correct):not(.incorrect) {
  border-color: var(--brand-primary);
  background: #fffbeb;
}

.answer-option.selected {
  border-color: var(--brand-primary);
  background: #fffbeb;
}

.answer-option.correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.answer-option.incorrect {
  border-color: var(--error);
  background: #fef2f2;
}

.exercise-feedback {
  margin-top: 22px;
  padding: 18px;
  border-radius: var(--radius-sm);
  background: #fffbeb;
  border-left: 4px solid var(--brand-secondary);
}

.exercise-feedback h4 {
  margin-bottom: 7px;
  color: var(--brand-primary);
  font-size: 1.12rem;
}

.exercise-buttons {
  display: flex;
  gap: 14px;
  margin-top: 26px;
}

.exercise-btn-modal {
  flex: 1;
  padding: 15px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1.02rem;
}

.next-btn {
  background: var(--brand-primary);
  color: white;
}

.next-btn:hover {
  background: var(--brand-accent);
}

.close-btn {
  background: #e2e8f0;
  color: var(--text-primary);
}

.close-btn:hover {
  background: #cbd5e1;
}

.flashcard-content {
  text-align: center;
  padding: 20px 0;
}

.flashcard-word {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 30px;
  font-family: 'Inter', sans-serif;
}

.flashcard-translation {
  font-size: 1.4rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  display: none;
}

.flashcard-emojis {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}

.flashcard-emojis button {
  font-size: 2.4rem;
  background: none;
  border: none;
  cursor: pointer;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.flashcard-emojis button:hover {
  background: #f0f0f0;
  transform: scale(1.1);
}

.flashcard-progress {
  font-size: 0.95rem;
  color: var(--text-light);
  margin-bottom: 18px;
}

.flashcard-next {
  margin-top: 20px;
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--brand-primary);
  transition: var(--transition);
}

.flashcard-next:hover {
  color: var(--brand-accent);
  transform: translateX(4px);
}

.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 8px 0;
  z-index: 100;
  display: none;
  min-width: 160px;
  margin-top: 4px;
}

.user-dropdown a {
  display: block;
  padding: 8px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.92rem;
  transition: var(--transition);
}

.user-dropdown a:hover {
  background: #f0f0f0;
}

.entry .save-heart {
  position: absolute;
  top: 0;
  right: 48px;
  font-size: 1.4rem;
  color: #ccc;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid #ddd;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  z-index: 2;
  text-decoration: none;
}

.entry .save-heart:hover {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  background: #fff9f9;
}

.entry .save-heart.saved {
  color: var(--brand-primary);
}

.save-tooltip {
  position: absolute;
  background: #333;
  color: white;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  z-index: 1000;
  pointer-events: none;
}

.save-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}

.dictionary-footer {
  margin-bottom: 10px;
  padding: 24px 40px;
  background: var(--content-bg);
  color: var(--text-light);
  font-size: .92rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
}

.university-link {
  color: var(--brand-primary);
  text-decoration: none;
  font-weight: 600;
}

.university-link:hover {
  text-decoration: underline;
  color: var(--brand-accent);
}

@media (max-width: 640px) {
  .dictionary-header h1 {
    font-size: 2.2rem;
  }

  .headword {
    font-size: 2rem;
  }

  .translation {
    font-size: 1.4rem;
  }

  .button-group {
    flex-direction: column;
  }

  .sense-item {
    padding-right: 0;
  }

  .sense-item .tags-container {
    position: static;
    margin-top: 10px;
  }

  .control-bar,
  .results-container,
  .dictionary-header,
  .dictionary-footer {
    padding-left: 20px;
    padding-right: 20px;
  }

  .auth-container {
    right: 20px;
  }

  .answer-options {
    grid-template-columns: 1fr;
  }
}

.auth-modal .modal-content {
  background: white;
  margin: 6% auto;
  padding: 30px;
  border-radius: var(--radius-md);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.auth-modal .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.auth-modal .modal-header h3 {
  color: var(--brand-primary);
  font-size: 1.4rem;
  font-weight: 600;
}

.auth-modal .close-modal {
  background: none;
  border: none;
  font-size: 1.7rem;
  cursor: pointer;
  color: var(--text-light);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--transition);
}

.auth-modal .close-modal:hover {
  background: #fee2e2;
  color: var(--brand-primary);
}

.auth-modal .form-group {
  margin-bottom: 16px;
}

.auth-modal input {
  width: 100%;
  padding: 14px;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
}

.auth-modal input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(183, 31, 40, 0.1);
}

.auth-buttons {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}

.auth-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
}

.auth-signin {
  background: var(--brand-primary);
  color: white;
}

.auth-signin:hover {
  background: var(--brand-accent);
}

.auth-signup {
  background: var(--brand-secondary);
  color: #1a1a1a;
}

.auth-signup:hover {
  background: #e6d604;
}

.auth-toggle {
  text-align: center;
  margin-top: 16px;
  font-size: 0.92rem;
  color: var(--text-light);
}

.auth-toggle a {
  color: var(--brand-primary);
  text-decoration: none;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 2px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
  display: none;
  box-shadow: var(--shadow-sm);
}

.search-suggestion {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

.search-suggestion:last-child {
  border-bottom: none;
}

.search-suggestion:hover,
.search-suggestion.selected {
  background: var(--brand-secondary);
  color: #1a1a1a;
}

.search-container {
  position: relative;
}

/* new */

.example-match-item {
  margin-bottom: 20px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 3px solid var(--brand-secondary);
}
.example-highlight {
  background-color: var(--highlight);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
}
.goto-lemma-btn {
  background: var(--brand-secondary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s;
}
.goto-lemma-btn:hover {
  background: var(--brand-primary);
  transform: translateY(-1px);
}

.lemma-highlight {
  background-color: var(--highlight);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 600;
  color: var(--text-primary);
}

.example-match-item {
  margin-bottom: 20px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 3px solid var(--brand-secondary);
}

.goto-lemma-btn {
  background: var(--brand-secondary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.2s;
}

.goto-lemma-btn:hover {
  background: var(--brand-primary);
  transform: translateY(-1px);
}

.examples-in-context {
  margin-top: 16px;
}
