/* ===== Root Variables ===== */
:root {
  --bg: #edf1f6;
  --surface: rgba(255, 255, 255, .72);
  --surface-strong: rgba(255, 255, 255, .9);
  --border: rgba(255, 255, 255, .86);
  --text: #171923;
  --muted: #647084;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b7791f;
  --danger: #dc2626;
  --shadow: 0 24px 70px rgba(35, 48, 78, .14), inset 0 1px 0 rgba(255, 255, 255, .72);
  --arabic: "Noto Naskh Arabic", "Amiri", "Scheherazade New", serif;
  --latin: "Outfit", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ===== Reset ===== */
* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  padding: 22px 14px 160px;
  color: var(--text);
  font-family: var(--latin);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, .12), transparent 36%),
    linear-gradient(225deg, rgba(183, 121, 31, .12), transparent 38%),
    var(--bg);
}

button, input { font: inherit; }

/* ===== App Shell ===== */
.app-shell {
  width: min(960px, 100%);
  margin: 0 auto;
}

/* ===== Hero Section with Madina Image ===== */
.hero {
  position: relative;
  overflow: hidden;
  margin: 8px 0 18px;
  padding: 40px 30px;
  min-height: 200px;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.35);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
  isolation: isolate;
}

/* Madina Background Image - Chon jana jakshynakai */
.hero-background {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 0;
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0.15;
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* Hover effect */
.hero:hover .hero-image {
  opacity: 0.25;
  transform: scale(1.02);
}

/* Gradient overlay for better text readability */
.hero::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(237, 241, 246, 0.4) 0%,
    rgba(237, 241, 246, 0.1) 50%,
    rgba(237, 241, 246, 0.4) 100%
  );
  z-index: 1;
  pointer-events: none;
}

.hero-content {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.back-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.3s ease;
}

.back-link:hover {
  background: rgba(255, 255, 255, .8);
  transform: translateX(-4px);
}

h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1.02;
  letter-spacing: 0;
  text-shadow: 0 2px 20px rgba(255, 255, 255, .3);
}

/* ===== Search Panel ===== */
.search-panel {
  position: sticky;
  top: 12px;
  z-index: 20;
  padding: 14px;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.35);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
}

.search-line {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 10px;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 62px;
  padding: 0 18px;
  border: 1px solid rgba(15, 118, 110, .18);
  border-radius: 18px;
  outline: none;
  color: var(--text);
  background: var(--surface-strong);
  font-family: var(--arabic);
  font-size: 30px;
  line-height: 1;
  transition: box-shadow .18s ease, border-color .18s ease;
}

.search-input.is-kyrgyz {
  font-family: var(--latin);
  font-size: 22px;
}

.search-input::placeholder {
  color: #8d98a8;
  opacity: 1;
}

.search-input:focus {
  border-color: rgba(15, 118, 110, .58);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 16px;
  color: var(--accent-dark);
  background: var(--surface-strong);
  box-shadow: 0 8px 24px rgba(31, 42, 68, .08);
  cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}

.icon-button:active {
  transform: scale(.96);
}

.icon-button svg {
  width: 25px;
  height: 25px;
  fill: currentColor;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 22px;
  margin-top: 10px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.search-mode {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(15, 118, 110, .08);
}

.mode-option {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: color .16s ease, background .16s ease, box-shadow .16s ease, transform .16s ease;
}

.mode-option.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .2);
}

.mode-option:active {
  transform: scale(.98);
}

/* ===== Results ===== */
.results {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.result-card {
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.35);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 18px;
}

.entry-id {
  min-width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.arabic-word,
.arabic-example {
  font-family: var(--arabic);
  direction: rtl;
  text-align: right;
}

.arabic-word {
  display: block;
  color: var(--accent-dark);
  font-size: clamp(30px, 7vw, 42px);
  font-weight: 700;
  line-height: 1.7;
}

.translation-list {
  display: grid;
  gap: 8px;
  padding: 0 18px 18px;
}

.translation-item {
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, .12);
  border-radius: 16px;
  background: rgba(255, 255, 255, .58);
}

.translation-toggle {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  color: var(--text);
  list-style: none;
  text-align: left;
  cursor: pointer;
  border: none;
  background: transparent;
}

.translation-toggle::-webkit-details-marker {
  display: none;
}

.translation-number {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  border-radius: 11px;
  color: var(--accent-dark);
  background: rgba(15, 118, 110, .1);
  font-weight: 700;
  font-size: 13px;
}

.translation-text {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
}

.chevron {
  color: var(--muted);
  transition: transform .2s ease;
}

.translation-item[open] .chevron {
  transform: rotate(180deg);
}

.example-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .24s ease;
}

.translation-item[open] .example-panel {
  grid-template-rows: 1fr;
}

.example-inner {
  overflow: hidden;
  padding: 0 14px 16px;
  color: var(--muted);
}

.examples-list {
  display: grid;
  gap: 10px;
}

.example-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(15, 118, 110, .1);
  border-radius: 14px;
  background: rgba(255, 255, 255, .66);
}

.example-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--amber);
  background: rgba(183, 121, 31, .12);
  font-size: 13px;
  font-weight: 700;
}

.arabic-example {
  margin: 0 0 8px;
  color: #1f2937;
  font-size: clamp(25px, 6vw, 34px);
  line-height: 2;
}

.example-translation {
  margin: 0;
  font-size: 16px;
  line-height: 1.55;
}

.empty-state,
.error-state {
  padding: 38px 18px;
  border-radius: 22px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(1.35);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
}

.empty-state strong,
.error-state strong {
  display: block;
  margin-bottom: 7px;
  font-size: 18px;
}

.empty-state span,
.error-state span {
  color: var(--muted);
  line-height: 1.5;
}

/* ===== Keyboard ===== */
.keyboard-overlay {
  display: none;
  pointer-events: none;
}

.dictionary-keyboard {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 50;
  width: min(920px, calc(100% - 20px));
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(245, 248, 250, .98);
  box-shadow: 0 18px 48px rgba(25, 38, 62, .18);
  opacity: 0;
  pointer-events: none;
  transform: translate3d(-50%, 120%, 0);
  transition: transform .24s ease, opacity .2s ease;
  will-change: transform, opacity;
}

.dictionary-keyboard.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate3d(-50%, 0, 0);
}

.keyboard-handle {
  width: 46px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 99px;
  background: rgba(100, 112, 132, .32);
}

.keyboard-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(15, 118, 110, .08);
}

.keyboard-tab {
  height: 38px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  transition: color .16s ease, background .16s ease, transform .16s ease;
}

.keyboard-tab.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .2);
}

.keyboard-tab:active {
  transform: scale(.98);
}

.keyboard-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
}

.keyboard-actions {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr 1fr 1.2fr;
  gap: 6px;
  margin-top: 6px;
}

.key {
  min-width: 0;
  height: 46px;
  border: 1px solid rgba(15, 118, 110, .1);
  border-radius: 13px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, .9);
  box-shadow: inset 0 1px 0 #fff, 0 5px 16px rgba(31, 42, 68, .08);
  cursor: pointer;
  user-select: none;
  transition: transform .08s ease, background .12s ease;
}

.key:not(.action-key) {
  font-family: var(--arabic);
  font-size: 25px;
  line-height: 1;
}

.dictionary-keyboard[data-layout="kyrgyz"] .key:not(.action-key) {
  font-family: var(--latin);
  font-size: 19px;
  font-weight: 700;
}

.action-key {
  font-size: 14px;
  font-weight: 700;
}

.key:active {
  transform: scale(.94);
  background: rgba(229, 245, 242, .96);
}

/* ============================================ */
/* ===== RESPONSIVE - BARDIK TUZUMOKTORGO ===== */
/* ============================================ */

/* ===== Mobile (480px jana kichine) ===== */
@media (max-width: 480px) {
  body {
    padding: 10px 6px 160px;
  }

  .hero {
    padding: 20px 16px;
    min-height: 150px;
    border-radius: 18px;
  }

  .hero-image {
    opacity: 0.12;
  }
  
  .hero:hover .hero-image {
    opacity: 0.2;
  }

  .hero-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .back-link {
    font-size: 12px;
    padding: 6px 12px;
  }

  h1 {
    font-size: clamp(24px, 6vw, 32px);
  }

  .search-panel {
    padding: 8px;
    border-radius: 18px;
    top: 6px;
  }

  .search-line {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 5px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .icon-button svg {
    width: 20px;
    height: 20px;
  }

  .search-input {
    height: 48px;
    font-size: 22px;
    padding: 0 12px;
    border-radius: 14px;
  }

  .status-row {
    font-size: 12px;
    flex-wrap: wrap;
  }

  .mode-option {
    min-height: 34px;
    font-size: 12px;
  }

  .result-top {
    padding: 14px;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .entry-id {
    min-width: 30px;
    width: 30px;
    height: 30px;
    font-size: 12px;
  }

  .arabic-word {
    font-size: clamp(24px, 8vw, 32px);
  }

  .translation-list {
    padding: 0 12px 12px;
  }

  .translation-text {
    font-size: 15px;
  }

  .keyboard-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
  }

  .keyboard-actions {
    grid-template-columns: .8fr 1.2fr .8fr .7fr 1fr;
    gap: 4px;
  }

  .key {
    height: 38px;
    border-radius: 10px;
    font-size: 12px;
  }

  .key:not(.action-key) {
    font-size: 20px;
  }

  .dictionary-keyboard {
    width: calc(100% - 10px);
    padding: 8px;
    border-radius: 18px;
  }
}

/* ===== Tablet (721px - 1024px) ===== */
@media (min-width: 481px) and (max-width: 1024px) {
  body {
    padding: 18px 12px 160px;
  }

  .hero {
    padding: 32px 24px;
    min-height: 180px;
    border-radius: 24px;
  }

  .hero-image {
    opacity: 0.14;
  }
  
  .hero:hover .hero-image {
    opacity: 0.22;
  }

  h1 {
    font-size: clamp(30px, 5vw, 44px);
  }

  .search-panel {
    padding: 12px;
    border-radius: 24px;
  }

  .search-input {
    font-size: 28px;
    height: 56px;
  }

  .keyboard-grid {
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 5px;
  }

  .key:not(.action-key) {
    font-size: 23px;
  }
}

/* ===== Desktop (1025px jana chon) ===== */
@media (min-width: 1025px) {
  .hero {
    padding: 50px 40px;
    min-height: 220px;
    border-radius: 32px;
  }

  .hero-image {
    opacity: 0.18;
  }
  
  .hero:hover .hero-image {
    opacity: 0.28;
  }

  h1 {
    font-size: clamp(40px, 5vw, 56px);
  }

  .back-link {
    font-size: 15px;
    padding: 10px 20px;
    border-radius: 14px;
  }

  .search-panel {
    padding: 18px;
    border-radius: 32px;
  }

  .search-input {
    height: 68px;
    font-size: 34px;
    border-radius: 20px;
  }

  .icon-button {
    width: 56px;
    height: 56px;
    border-radius: 18px;
  }

  .key {
    height: 50px;
    border-radius: 14px;
  }

  .key:not(.action-key) {
    font-size: 27px;
  }
}

/* ===== Landscape mode (kichine ekranda) ===== */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding-bottom: 130px;
  }

  .hero {
    padding: 12px 16px;
    min-height: 80px;
    margin: 4px 0 12px;
    border-radius: 18px;
  }

  .hero-image {
    opacity: 0.1;
  }

  h1 {
    font-size: clamp(20px, 4vw, 28px);
  }

  .hero-content {
    flex-direction: row;
    align-items: center;
  }

  .back-link {
    font-size: 11px;
    padding: 4px 10px;
  }

  .search-panel {
    padding: 6px 10px;
    border-radius: 16px;
    top: 4px;
  }

  .search-line {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 4px;
  }

  .search-input {
    height: 36px;
    font-size: 18px;
    padding: 0 10px;
    border-radius: 10px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .icon-button svg {
    width: 16px;
    height: 16px;
  }

  .status-row {
    font-size: 10px;
    min-height: 16px;
    margin-top: 4px;
  }

  .search-mode {
    margin-top: 6px;
    gap: 4px;
    padding: 3px;
  }

  .mode-option {
    min-height: 28px;
    font-size: 10px;
  }

  .dictionary-keyboard {
    padding: 6px;
    border-radius: 16px;
  }

  .keyboard-grid {
    gap: 4px;
  }

  .key {
    height: 30px;
    border-radius: 8px;
    font-size: 10px;
  }

  .key:not(.action-key) {
    font-size: 16px;
  }

  .keyboard-actions {
    margin-top: 4px;
    gap: 4px;
  }

  .keyboard-handle {
    display: none;
  }

  .result-top {
    padding: 10px 14px;
  }

  .arabic-word {
    font-size: clamp(20px, 5vw, 28px);
  }

  .translation-list {
    padding: 0 12px 10px;
    gap: 4px;
  }

  .translation-toggle {
    min-height: 38px;
    padding: 6px 10px;
  }

  .translation-text {
    font-size: 13px;
  }

  .entry-id {
    min-width: 26px;
    height: 26px;
    font-size: 10px;
  }
}