:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #5a5a5a;
  --link: #0b57d0;
  --accent: #d4af37;
  --accent-soft: rgba(212,175,55,0.15);
  --border: rgba(128,128,128,0.1);
  --maxw: 760px;
  --pad: 20px;
  --font: 22px;
  --line: 1.9;
  --he-font: "Noto Serif Hebrew","David Libre",serif;
  --ui-font: "Assistant","Segoe UI",Roboto,Arial,sans-serif;
  --topbar-h: 56px;
  --bottombar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light-mode) {
    --bg: #0a0a0a;
    --fg: #ebebeb;
    --muted: #9a9a9a;
    --link: #8ab4f8;
  }
}
:root.dark-mode {
  --bg: #0a0a0a;
  --fg: #ebebeb;
  --muted: #9a9a9a;
  --link: #8ab4f8;
}

html, body { height: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--he-font);
  font-size: var(--font);
  line-height: var(--line);
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.page {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: calc(var(--pad) + 18px) var(--pad);
  padding-bottom: calc(var(--bottombar-h) + 40px + env(safe-area-inset-bottom));
  direction: rtl;
  unicode-bidi: plaintext;
}

/* ===== TOPBAR ===== */
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, calc((100vw - var(--maxw)) / 2));
  height: var(--topbar-h);
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  direction: ltr;
  gap: 12px;
}
:root.dark-mode header.topbar {
  background: rgba(10,10,10,0.97);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  line-height: 1.12;
  text-decoration: none;
  flex-shrink: 0;
}
.brand-title {
  font-family: var(--ui-font);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
}
.brand-byline {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--ui-font);
  font-weight: 400;
}
.brand:hover { text-decoration: none; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.text-controls {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 10px;
  background: rgba(128,128,128,0.06);
  border-radius: 12px;
  margin-inline-end: 6px;
}
.ui-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}
.tbar-sep {
  width: 1px;
  height: 16px;
  background: rgba(128,128,128,0.2);
  margin: 0 5px;
}
.tbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  color: var(--fg);
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s, opacity 0.12s;
  opacity: 0.5;
}
.tbar-btn:hover { background: rgba(128,128,128,0.1); opacity: 0.9; }
.tbar-toggle.active {
  background: var(--accent-soft);
  color: var(--accent);
  opacity: 1;
  box-shadow: inset 0 0 0 1.5px rgba(212,175,55,0.35);
}

/* Font popover */
.font-popover-wrap { position: relative; }
.font-popover {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  padding: 6px;
  flex-direction: column;
  gap: 2px;
  min-width: 110px;
  z-index: 500;
}
.font-popover.open { display: flex; }
.font-popover button {
  background: none;
  border: none;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--fg);
  font-family: var(--ui-font);
  font-size: 13px;
  border-radius: 6px;
  text-align: left;
}
.font-popover button:hover { background: var(--accent-soft); }

/* ===== BOTTOMBAR ===== */
nav.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--bottombar-h);
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  direction: ltr;
}
:root.dark-mode nav.bottombar {
  background: rgba(10,10,10,0.97);
}
nav.bottombar .bbtn {
  font-family: var(--ui-font);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 20px;
  border-radius: 10px;
  transition: color 0.15s, background 0.15s;
  opacity: 0.6;
}
nav.bottombar .bbtn:hover { opacity: 1; text-decoration: none; }
nav.bottombar .bbtn.active {
  color: var(--accent);
  font-weight: 700;
  opacity: 1;
  border-radius: 0;
}
nav.bottombar .bbtn.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 20%;
  width: 60%;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
  opacity: .85;
}
nav.bottombar .bbtn {
  position: relative;
}

/* ===== SEARCH ===== */
#searchOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 300;
  backdrop-filter: blur(2px);
}
#searchPanel {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  z-index: 301;
  overflow: hidden;
  direction: ltr;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.search-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.search-header input {
  flex: 1;
  border: none;
  background: none;
  font-size: 16px;
  color: var(--fg);
  font-family: var(--ui-font);
  outline: none;
}
.search-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
}
#searchResults { overflow-y: auto; flex: 1; }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--ui-font);
  text-decoration: none;
  color: var(--fg);
}
.search-result-item:hover { background: var(--accent-soft); text-decoration: none; }
.search-result-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 90px;
  white-space: nowrap;
}
.search-result-title { font-size: 15px; color: var(--muted); }

/* ===== LANDING: ocultar controles en home ===== */
body.is-landing .text-controls {
  visibility: hidden;
  pointer-events: none;
}
