@import url('sw_theme.css?v=3');

/* Hide body until chrome + footer are wired (prevents legacy bar flash) */
html.sw-shell-pending body {
  visibility: hidden;
}
html.sw-shell-ready body {
  visibility: visible;
}

/* Anti-FOUC: final chrome only (no legacy top bar / floating mode bar flash) */
.controls-top {
  display: none !important;
}
body:not(.sw-footer-ready) > .controls-bottom {
  visibility: hidden !important;
  pointer-events: none !important;
}
body:not(.sw-footer-ready) #sw-reader-footer {
  visibility: hidden !important;
  pointer-events: none !important;
}
html:has(link[href*="site_chrome.css"]) .page,
html:has(link[href*="site_chrome.css"]) #main-content {
  padding-top: calc(var(--sw-chrome-h, 58px) + env(safe-area-inset-top, 0px));
}

/* Shared site header — menu · home · כתבי הקודש / The Holy Scriptures · size · dark */
:root {
  --sw-chrome-h: 56px;
  --header-bg: #1e2233;
  --accent: var(--sw-gold, #dbb958);
}

.sw-top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 110;
  min-height: var(--sw-chrome-h);
  background: var(--header-bg);
  border-bottom: 2px solid var(--accent);
  box-sizing: border-box;
  direction: ltr;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(6px, env(safe-area-inset-left, 0px));
  padding-right: max(6px, env(safe-area-inset-right, 0px));
  padding-bottom: 6px;
}
body.dark-mode .sw-top-bar {
  background: #0a0a0a;
}

/* Single row: menu · home · title · size · dark */
.sw-top-bar-inner {
  position: relative;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  align-items: center;
  gap: 6px 10px;
  min-height: 48px;
  direction: ltr;
}

/* True viewport center (not centered in the gap between uneven side controls) */
.sw-top-bar-brand {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 0;
  pointer-events: auto;
  text-decoration: none;
  color: var(--accent);
  line-height: 1.1;
  font-family: 'David Libre', 'Georgia', serif;
  min-width: 0;
  max-width: min(62vw, 320px);
  padding: 2px 6px 0;
  gap: 1px;
  direction: ltr;
  unicode-bidi: isolate;
}
.sw-top-bar-brand-he,
.sw-top-bar-brand-en {
  display: block;
  width: 100%;
  text-align: center;
  white-space: nowrap;
  line-height: 1.12;
}
.sw-top-bar-brand-he {
  font-size: 1.22em;
  font-weight: 700;
  letter-spacing: 0.02em;
  direction: rtl;
  unicode-bidi: plaintext;
}
.sw-top-bar-brand-en {
  font-size: 0.62em;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: none;
  margin-top: 2px;
  opacity: 0.95;
  font-family: 'David Libre', 'Cormorant Garamond', Georgia, serif;
}

.sw-top-bar-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  grid-column: 4;
  grid-row: 1;
  justify-self: end;
  min-width: 0;
  z-index: 2;
}

.sw-top-bar-tools label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 0.82em;
  margin: 0;
  font-family: 'David Libre', 'Georgia', serif;
  white-space: nowrap;
}

.sw-top-bar-tools input[type="range"] {
  width: 72px;
  max-width: 20vw;
  accent-color: var(--accent);
  margin: 0;
  vertical-align: middle;
}

#sw-chrome-dark {
  grid-column: 5;
  grid-row: 1;
  justify-self: end;
  z-index: 2;
}

#sw-chrome-menu {
  grid-column: 1;
  grid-row: 1;
}

.sw-chrome-home {
  grid-column: 2;
  grid-row: 1;
}

/* Hub has no font slider — four items: menu · home · (spacer) · dark */
body:not(.sw-chrome-reader) .sw-top-bar-inner {
  grid-template-columns: auto auto 1fr auto;
}
body:not(.sw-chrome-reader) .sw-top-bar-tools {
  display: none;
}
body:not(.sw-chrome-reader) #sw-chrome-dark {
  grid-column: 4;
}

.sw-chrome-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 6px 8px;
  border: 1px solid #3a3f55;
  border-radius: 4px;
  color: var(--sw-gold, #dbb958);
  text-decoration: none;
  font-size: 1.05em;
  line-height: 1;
  flex-shrink: 0;
}
.sw-chrome-home:hover {
  background: #2a2f44;
}

.sw-chrome-nav-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sw-chrome-menu-icon {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
}
.sw-chrome-menu-icon span {
  display: block;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.sw-chrome-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 8px 10px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 1.2em;
  -webkit-tap-highlight-color: transparent;
}
.sw-chrome-btn:hover {
  background: rgba(200, 168, 78, 0.15);
}

/* Never show legacy reader toolbar — merged into chrome */
body.has-sw-chrome .controls-top {
  display: none !important;
}

body.has-sw-chrome #dark-mode-toggle {
  display: none;
}

/* Breadcrumb slot kept for NavEngine but not shown in the header bar */
.sw-chrome-location,
#sw-chrome-location {
  display: none !important;
  height: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
}

body.has-sw-chrome .page {
  padding-top: calc(var(--sw-chrome-h) + 8px + env(safe-area-inset-top, 0px));
}

body.has-sw-chrome.sw-chrome-reader .page,
body.has-sw-chrome.sw-chrome-reader #main-content {
  padding-top: calc(var(--sw-chrome-h) + 12px + env(safe-area-inset-top, 0px));
}

body.has-sw-chrome #reading-progress {
  top: calc(var(--sw-chrome-h) + env(safe-area-inset-top, 0px));
}

body.has-sw-chrome.audio-bar-open .page {
  padding-top: calc(var(--sw-chrome-h) + 48px + env(safe-area-inset-top, 0px));
}

body.has-sw-chrome #audio-bar.visible {
  top: calc(var(--sw-chrome-h) + env(safe-area-inset-top, 0px));
}

body.has-sw-chrome .dict-legacy-topbar {
  display: none !important;
}
body.has-sw-chrome .dict-wrap {
  padding-top: calc(var(--sw-chrome-h) + 12px + env(safe-area-inset-top, 0px));
}

@media print {
  #sw-top-bar {
    display: none !important;
  }
}

@media (max-width: 520px) {
  .sw-top-bar-inner {
    gap: 4px 6px;
  }
  .sw-top-bar-brand {
    max-width: min(58vw, 240px);
    padding-top: 1px;
  }
  .sw-top-bar-brand-he {
    font-size: 1.05em;
  }
  .sw-top-bar-brand-en {
    font-size: 0.5em;
    letter-spacing: 0.02em;
    margin-top: 1px;
  }
  .sw-top-bar-tools label .label-text {
    display: none;
  }
  .sw-top-bar-tools input[type="range"] {
    width: 56px;
  }
  .sw-chrome-btn {
    min-width: 40px;
    padding: 6px 8px;
  }
  .sw-chrome-home {
    min-width: 36px;
    min-height: 36px;
    padding: 4px 6px;
  }
}
