/* Layout: the app shell — top bar (brand, search, tools), sidebar and mobile
   drawer, main column, footer — and the breakpoints that rearrange it. */

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

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding-inline: 20px;
  background: var(--glass);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.brand-mark-frame {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 1.6;
}

.brand-mark-rules {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.1;
  opacity: 0.3;
}

/* The rising line carries the brand gradient (defined in the mark's own <defs>). */
.brand-mark-line {
  fill: none;
  stroke: url(#brand-gradient);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text {
  display: grid;
  min-width: 0;
}

.brand-name {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: right;
  white-space: nowrap;
}

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}

.icon-btn:hover {
  border-color: color-mix(in srgb, var(--teal) 55%, var(--border));
  color: var(--teal);
  text-decoration: none;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* Favourites count: a small pill in the brand gradient. */
.icon-btn .pill {
  position: absolute;
  top: -6px;
  inset-inline-end: -6px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--brand-gradient);
  color: var(--on-btn);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

#menuBtn {
  display: none;
}

/* The first tool pushes the tools to the end of the bar. */
#homeBtn {
  margin-inline-start: auto;
}

/* ------------------------------------------------------------------ search */

.search {
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 620px;
}

.search-input {
  width: 100%;
  height: 42px;
  padding-inline: 42px 60px;
  border: 1px solid var(--border-2);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

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

.search-input:focus,
.search-input:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.search-ic {
  position: absolute;
  top: 50%;
  inset-inline-start: 13px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-kbd {
  position: absolute;
  top: 50%;
  inset-inline-end: 12px;
  transform: translateY(-50%);
  padding: 0 7px;
  border: 1px solid var(--border-2);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  direction: ltr;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline: 0;
  z-index: 50;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}

.sr-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--text);
  cursor: pointer;
}

/* The house highlighter (cyan) marks the result under the pointer or the arrow keys. */
.sr-item:hover,
.sr-item.active {
  background: var(--highlight-wash);
  text-decoration: none;
}

.sr-item .en {
  min-width: 110px;
  color: var(--primary-text);
  font-family: var(--mono);
  font-size: 0.78rem;
  direction: ltr;
}

.sr-item .ar {
  font-weight: 600;
}

.sr-item .def {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-item .cat {
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.sr-empty {
  padding: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ------------------------------------------------------------------ shell & sidebar */

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: var(--header-h);
  z-index: 20;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  border-inline-end: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  scrollbar-width: thin;
  scrollbar-color: var(--border-2) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
  border-radius: 99px;
  background: var(--border-2);
}

.sb-progress {
  padding: 18px 20px 14px;
}

.sb-progress .row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.nav {
  padding: 4px 12px 20px;
}

/* Arabic labels: no letter-spacing or capitals, which would break the joined script. */
.nav-title {
  padding: 14px 10px 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 700;
}

.nav a .n {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 0.74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* The current section wears the brand gradient, like the site's primary action. */
.nav a.active .n {
  background: var(--brand-gradient);
  color: var(--on-btn);
}

.nav a .done-dot {
  width: 8px;
  height: 8px;
  flex: none;
  margin-inline-start: auto;
  border-radius: 50%;
  background: var(--border-2);
}

.nav a .done-dot.p {
  background: var(--amber);
}

.nav a .done-dot.f {
  background: var(--ok);
}

.nav a .cnt {
  margin-inline-start: auto;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.74rem;
}

.nav a.active .cnt {
  background: var(--surface);
}

.sb-foot {
  margin-top: auto;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.76rem;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 39;
  background: rgb(6 9 19 / 0.55);
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: opacity 0.2s;
}

body.sb-open .overlay {
  opacity: 1;
  pointer-events: auto;
}

/* ------------------------------------------------------------------ main & footer */

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 26px 24px 64px;
}

.main:focus,
.main:focus-visible {
  outline: none;
  box-shadow: none;
}

.page {
  animation: fadeUp 0.28s var(--ease) both;
}

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

.site-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  width: 100%;
  max-width: var(--content-w);
  margin-inline: auto;
  padding: 22px 24px calc(22px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-foot a {
  color: var(--text-2);
  font-weight: 600;
  text-decoration: none;
}

.site-foot a:hover {
  color: var(--primary);
}

/* ------------------------------------------------------------------ breakpoints */

/* Wide screens: the brand spans at least the sidebar, so the search starts over the content column. */
@media (min-width: 1101px) {
  .brand {
    min-width: calc(var(--sidebar-w) - 30px);
  }
}

/* Tablets and phones: the sidebar becomes a drawer opened from the menu button. */
@media (max-width: 1100px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 40;
    width: min(var(--sidebar-w), 86vw);
    height: auto;
    border-inline-end: 0;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    /* Hidden (and out of the tab order) once it has slid away. */
    visibility: hidden;
    transition: transform 0.28s var(--ease), visibility 0s linear 0.28s;
  }

  body.sb-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.28s var(--ease), visibility 0s;
  }

  #menuBtn {
    display: grid;
  }
}

/* Phones: two rows — menu, brand and theme; then search, home and favourites. */
@media (max-width: 720px) {
  html {
    scroll-padding-top: 128px;
  }

  body {
    font-size: 15.5px;
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "menu brand brand theme"
      "search search home fav";
    gap: 6px;
    height: auto;
    padding: 8px 10px;
  }

  #menuBtn { grid-area: menu; }
  .brand { grid-area: brand; gap: 8px; }

  /* The full name fits a 360px phone; narrower screens end it with an ellipsis. */
  .brand-name {
    font-size: clamp(0.88rem, 4vw, 1.12rem);
  }
  #themeBtn { grid-area: theme; }
  .search { grid-area: search; max-width: none; }
  #homeBtn { grid-area: home; margin-inline-start: 0; }
  #favBtn { grid-area: fav; }

  .brand-sub,
  .search-kbd {
    display: none;
  }

  .search-input {
    padding-inline-end: 12px;
  }

  .sr-item .def {
    display: none;
  }

  .main {
    padding: 18px 14px 48px;
  }

  .site-foot {
    padding-inline: 14px;
  }
}
