:root {
  --paper: #EFE8DF;
  --paper-2: #F6F1EA;
  --line: rgba(23, 19, 15, 0.07);
  --border: #DCD3C6;
  --ink: #17130F;
  --muted: #6F675D;
  --amber: #FDAF04;
  --amber-ink: #17130F;
  --bad: #B4462E;
  --good: #3E7A4A;
  --shadow: 0 1px 0 rgba(23, 19, 15, 0.06), 0 6px 20px rgba(23, 19, 15, 0.06);
  --radius: 14px;
  --serif: 'DM Serif Display', Georgia, serif;
  --sans: 'Poppins', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1B1914;
    --paper-2: #24211B;
    --line: rgba(239, 232, 223, 0.05);
    --border: #3A352D;
    --ink: #EFE8DF;
    --muted: #A39A8E;
    --bad: #E07A5F;
    --good: #7FB98A;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  /* daftar katagi */
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100dvh;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }

button, input, textarea, select { font: inherit; color: inherit; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 8px;
}

.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; }
.brand-title { font-family: var(--serif); font-size: 32px; line-height: 1; }
.brand-title::after { content: '.'; color: var(--amber); }
.brand-sub { font-size: 13px; color: var(--muted); }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  outline: none;
}

h1, h2 { font-family: var(--serif); font-weight: 400; margin: 0; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 22px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

.panel {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.stack > * + * { margin-top: 16px; }

/* --- Bosh sahifa --- */
.hero { display: flex; flex-direction: column; gap: 14px; }
.hero-count { font-family: var(--serif); font-size: 56px; line-height: 1; }
.hero-count .u { font-size: 22px; color: var(--muted); margin-left: 6px; font-family: var(--sans); }
.underline { background: linear-gradient(transparent 62%, color-mix(in srgb, var(--amber) 55%, transparent) 62%); padding: 0 2px; }

.boxes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; padding: 16px 12px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-num { font-family: var(--serif); font-size: clamp(22px, 6.5vw, 28px); line-height: 1.1; white-space: nowrap; }
.stat-label { font-size: 12px; color: var(--muted); line-height: 1.25; }
.box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 4px 12px;
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  min-width: 0;
}
.box:hover { border-color: var(--ink); }
.box-num { font-size: 12px; color: var(--muted); line-height: 1.25; }
.box-count { font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.box.has-due { border-color: var(--amber); box-shadow: inset 0 -3px 0 var(--amber); }
.box-left { font-size: 11px; color: var(--muted); line-height: 1.25; }
.box-now { color: var(--ink); font-weight: 600; }

@media (max-width: 420px) {
  .boxes { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .box-count { font-size: 24px; }
  .box-num, .box-left { font-size: 10px; }
}

/* --- Tugmalar --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid var(--ink);
  background: transparent;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); font-weight: 600; }
.btn-dark { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-ghost { border-color: var(--border); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 17px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--paper-2);
  cursor: pointer;
  flex: none;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- Takrorlash --- */
.review-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.progress { flex: 1; height: 14px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress > span {
  display: block; height: 100%; min-width: 14px; border-radius: 999px;
  background: var(--amber); transition: width 0.35s cubic-bezier(.3,1.4,.6,1);
  /* Duolingo'dagidek ichki yaltiroq chiziq */
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.08), inset 0 3px 0 -1px rgba(255,255,255,0.45);
}

.flash {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 28px 20px;
}
.flash-word { font-family: var(--serif); font-size: clamp(34px, 9vw, 52px); line-height: 1.1; word-break: break-word; }
.flash-ipa { color: var(--muted); }
/* Javob savol bilan bir xil kattalikda, chiqishda biroz "sakraydi". */
.flash-answer { font-family: var(--serif); font-size: clamp(34px, 9vw, 52px); line-height: 1.1; word-break: break-word; }
.flash-back {
  align-self: stretch; display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 22px 14px; border-radius: 12px;
  background: var(--paper); border: 1px solid var(--border);
}
.pop { animation: pop 0.3s cubic-bezier(.3,1.6,.6,1); }
.flash.enter { animation: card-in 0.28s ease-out; }
@keyframes card-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }
.flash-def { color: var(--muted); max-width: 46ch; }
.flash-ex { font-style: italic; max-width: 46ch; }

.answer-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
/* Qalin "3D" tugmalar: bosilganda pastga cho'kadi. */
.btn-3d { border-width: 2px; border-radius: 16px; font-weight: 700; letter-spacing: 0.02em; transition: transform 0.06s, box-shadow 0.06s; }
.btn-3d:active { transform: translateY(4px); box-shadow: none !important; }
.btn-bad { background: var(--paper-2); border-color: var(--bad); color: var(--bad); box-shadow: 0 4px 0 var(--bad); }
.btn-good { background: #58A55C; border-color: #58A55C; color: #fff; box-shadow: 0 4px 0 #3E7A45; }
.btn-go { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); box-shadow: 0 4px 0 #C98A00; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; accent-color: var(--ink); }

/* --- Forma --- */
label.field { display: block; }
label.field > span { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
input[type=text], input[type=search], input[type=password], textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px; /* iOS kattalashtirmasin */
}
textarea { min-height: 76px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: transparent; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

.lookup-box { border: 1px dashed var(--border); border-radius: 12px; padding: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.def-option {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}
.def-option.on { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--amber); }
.def-option + .def-option { margin-top: 6px; }
.pos { font-size: 12px; color: var(--muted); font-style: italic; }

/* --- So'zlar ro'yxati --- */
.word-list { list-style: none; margin: 0; padding: 0; }
.word-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.word-item:last-child { border-bottom: 0; }
.word-main { flex: 1; min-width: 0; }
.word-en { font-weight: 600; }
.word-uz { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  flex: none;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.badge.due { border-color: var(--amber); color: var(--ink); background: color-mix(in srgb, var(--amber) 22%, transparent); }

.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filters .chip { flex: none; white-space: nowrap; }
.filters::-webkit-scrollbar { display: none; }

.empty { text-align: center; padding: 36px 16px; }
.empty .big { font-family: var(--serif); font-size: 26px; margin-bottom: 6px; }
/* Takrorlash tugagach: katta tabrik va natija */
.done { animation: pop 0.35s cubic-bezier(.3,1.6,.6,1); }
.done-emoji { font-size: 64px; line-height: 1; }
.done .big { font-size: 34px; }
.done-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.done-stat { border: 2px solid var(--border); border-radius: 16px; padding: 12px 8px; }
.done-stat b { display: block; font-family: var(--serif); font-size: 32px; font-weight: 400; line-height: 1.1; }
.done-stat.good b { color: #58A55C; }
.done-stat.bad b { color: var(--bad); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 32px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.skeleton { color: var(--muted); padding: 40px 0; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
