:root {
  --bg: #0f2a2e;
  --card: #f7f3ea;
  --ink: #142428;
  --muted: #5a6e72;
  --accent: #1f8a7a;
  --accent-deep: #14685c;
  --line: rgba(20, 36, 40, 0.12);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Cairo", sans-serif;
  color: #e8f2f1;
  background:
    radial-gradient(900px 480px at 10% -10%, #1d5c55 0%, transparent 55%),
    radial-gradient(700px 420px at 100% 0%, #2a4a6b 0%, transparent 50%),
    var(--bg);
  padding-bottom: calc(1rem + var(--safe-b));
}

.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
}

.header, .tabs, .filters, main, .foot {
  position: relative;
  z-index: 1;
  width: min(640px, calc(100% - 1.25rem));
  margin-inline: auto;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  padding: 1.1rem 0 0.7rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: #9ec5bf;
  font-size: 0.82rem;
}

.header h1 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(1.7rem, 6vw, 2.3rem);
}

.stats {
  margin: 0;
  color: #a9c5c1;
  font-size: 0.85rem;
  text-align: left;
  direction: ltr;
  line-height: 1.45;
}

.header-side {
  display: grid;
  justify-items: end;
  gap: 0.45rem;
}

.header-side .btn {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.section-title {
  margin: 1.15rem 0 0.55rem;
  font-size: 1rem;
  color: var(--accent-deep);
}

.sense-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.4rem;
  margin-top: 0.65rem;
}

.btn.tiny {
  padding: 0.5rem 0.35rem;
  font-size: 0.88rem;
}

.tabs {
  display: none;
}

.tab, .btn, select, input {
  font: inherit;
}

.tab {
  font-weight: 700;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.06);
  color: #d7ebe8;
  border-radius: 14px;
  padding: 0.78rem 0.8rem;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.filters {
  display: grid;
  grid-template-columns: 0.85fr 1.4fr;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

select, input[type="search"] {
  width: 100%;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.08);
  color: #e8f2f1;
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
}

select option { color: #111; }

.panel { display: none; }
.panel.active {
  display: block;
  animation: rise .28s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--card);
  color: var(--ink);
  border-radius: 22px;
  padding: 1.15rem 1.05rem 1rem;
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
}

.badge {
  background: #d9efe9;
  color: var(--accent-deep);
  padding: 0.18rem 0.62rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
}

.visual {
  text-align: center;
  font-size: 3rem;
  margin-bottom: 0.35rem;
}

.en {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  line-height: 1.35;
  direction: ltr;
  text-align: left;
}

.en.word {
  text-align: center;
  font-size: clamp(2rem, 8vw, 2.7rem);
}

.pos {
  margin: 0.25rem 0 0;
  text-align: center;
  color: var(--muted);
  font-family: "Nunito", sans-serif;
  font-size: 0.92rem;
  direction: ltr;
}

.ar {
  margin: 0.75rem 0 0;
  font-size: 1.15rem;
  color: #33494d;
  line-height: 1.7;
}

.word-link {
  margin: 0 0 0.55rem;
  color: var(--accent-deep);
  font-weight: 700;
  direction: ltr;
  text-align: left;
  font-family: "Nunito", sans-serif;
}

.senses {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.55rem;
}

.sense {
  background: #eef6f3;
  border-radius: 14px;
  padding: 0.7rem 0.8rem;
}

.sense-en {
  margin: 0;
  direction: ltr;
  text-align: left;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  color: #1d3538;
}

.sense-ar {
  margin: 0.3rem 0 0;
  color: var(--muted);
}

.sense-tag {
  display: inline-block;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  color: var(--accent-deep);
  font-weight: 700;
}

.actions {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.9rem;
}

.audio-row { grid-template-columns: 1.2fr 1fr 1fr; }
.auto-row { grid-template-columns: 1fr; }
.nav-row { grid-template-columns: 1fr 1fr; }

.sense.current {
  background: #d9efe9;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.btn {
  font-weight: 700;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.72rem 0.35rem;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.btn.active-loop,
.btn.active-auto {
  background: #c45c4a;
  border-color: transparent;
  color: #fff;
}

.foot {
  text-align: center;
  color: #8eaaa6;
  font-size: 0.86rem;
  line-height: 1.6;
  padding: 1rem 0 0.4rem;
}

.pwa-install-bar {
  position: sticky;
  top: 0;
  z-index: 10000;
  width: 100%;
  text-align: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 12px;
  background: var(--accent);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}
.pwa-install-bar[hidden] { display: none !important; }

.pwa-install {
  display: inline-block;
  margin: 0;
  border: 0;
  background: #0b1220;
  color: #fff;
  border-radius: 999px;
  padding: 0.75rem 1.15rem;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

#pwa-install-hint {
  margin: 8px 0 0;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
}

.credit {
  margin-top: 0.35rem;
  opacity: 0.85;
  font-size: 0.8rem;
}

.guide-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 20, 22, 0.62);
  padding: 16px;
  align-items: center;
  justify-content: center;
}

.guide-backdrop.open { display: flex; }

.guide-modal {
  width: 100%;
  max-width: 440px;
  max-height: min(88dvh, 640px);
  background: var(--card);
  color: var(--ink);
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.guide-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.guide-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.guide-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.guide-body {
  padding: 14px 16px;
  overflow-y: auto;
  flex: 1;
}

.guide-actions {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.guide-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: gstep;
  display: grid;
  gap: 10px;
}

.guide-steps li {
  counter-increment: gstep;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 0.92rem;
  line-height: 1.6;
}

.guide-steps li::before {
  content: counter(gstep);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 420px) {
  .filters { grid-template-columns: 1fr; }
  .audio-row { grid-template-columns: 1fr; }
}
