/* ============================================================
   Mirath: Base
   Reset + typography + app-shell scaffolding.
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
}

/* The HTML `hidden` attribute must always win. Author classes like
   `.field { display: flex }` share specificity with the UA `[hidden]`
   rule and, by source order, silently defeat it, so a `hidden` field
   stays visible. This makes `hidden` authoritative app-wide. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100vh;
  height: 100svh;
  height: var(--visual-height, 100svh);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  color: var(--color-text-primary);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  height: 100%;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-serif);
  margin: 0;
  color: var(--color-text-primary);
  font-weight: 700;
  line-height: 1.21;
}

p { margin: 0; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

blockquote, cite, figure { margin: 0; }

/* ---------- Arabic handling ---------- */

.arabic-term {
  font-family: var(--font-arabic);
  font-size: 1.15em;
  direction: rtl;
  display: inline-block;
  unicode-bidi: embed;
  vertical-align: baseline;
  letter-spacing: 0;
  color: var(--color-arabic-ink);
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

.arabic-heading {
  font-family: var(--font-arabic);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.6;
  direction: rtl;
  text-align: right;
  letter-spacing: 0;
  color: var(--color-arabic-ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
  display: block;
}

/* ---------- App shell ---------- */

.app-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-bg);
}

.top-bar {
  flex-shrink: 0;
  height: calc(var(--top-bar-height) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-inline: var(--space-4);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-separator);
  display: flex;
  align-items: flex-end;
}

.top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  height: var(--top-bar-height);
  width: 100%;
}

.top-bar-text {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}

.site-title {
  margin: 0;                      /* brand wordmark: a <p>, not a heading, so each view's title is the sole h1 */
  font-family: var(--font-serif);
  font-size: var(--text-h2);
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: 0.01em;
}

.site-tagline {
  font-size: var(--text-footnote);
  color: var(--color-text-secondary);
  font-family: var(--font-sans);
}

.top-bar-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Quiet top-bar controls: the theme toggle and the settings doorway. */
.theme-toggle,
.top-bar-action {
  flex-shrink: 0;
  width: var(--tap-target-min);
  height: var(--tap-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--color-text-secondary);
  transition: color var(--dur-micro) ease, background var(--dur-micro) ease;
}

@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover,
  .top-bar-action:hover { color: var(--color-accent); }
}

.theme-toggle:active,
.top-bar-action:active { background: var(--color-surface-raised); }

.top-bar-action-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.top-bar-action.is-active {
  color: var(--color-accent);
}

.theme-toggle-icon {
  width: 20px;
  height: 20px;
  display: block;
  transition: transform var(--dur-small) var(--ease-settle);
}

html.dark .theme-toggle-icon {
  transform: rotate(180deg);
}

.main-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-inline: var(--space-5);
  padding-block: var(--space-6);
}

.bottom-nav {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
  height: calc(var(--bottom-nav-height) + max(env(safe-area-inset-bottom, 0px), var(--visual-bottom-inset, 0px)));
  padding-bottom: max(env(safe-area-inset-bottom, 0px), var(--visual-bottom-inset, 0px));
  padding-inline: var(--space-2);
  background: var(--color-bg);
  border-top: 1px solid var(--color-separator);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-target-min);
  color: var(--color-text-secondary);
  font-size: var(--text-caption);
  transition: color var(--dur-micro) ease;
}

.nav-label {
  font-family: var(--font-sans);
  font-size: var(--text-caption);
  font-weight: 500;
}

/* ---------- Visually hidden: present for assistive tech only ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Focus: WCAG 2.4.11 (AA) ---------- */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: inherit;
}

/* Slightly larger offset for buttons so the ring clears the wax-seal curve */
.btn:focus-visible {
  outline-offset: 3px;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
