/* =========================================================
   4. HEADER
   ========================================================= */

.bb-header {
  background: #e8eef8;
  padding: 22px var(--bb-side-margin) 16px var(--bb-side-margin);
  box-sizing: border-box;

  display: grid;
  grid-template-columns: 1fr 220px 1fr;
  align-items: start;
  column-gap: 16px;
}

.bb-header > .bb-header-left,
.bb-header > .bb-header-center,
.bb-header > .bb-header-right {
  min-width: 0;
}

/* --- header left --- */

.bb-header-left {
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  row-gap: 14px;
}

.bb-section-title {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.08;
  color: #111;
  transform: scaleY(1.12);
  transform-origin: left center;
}

.bb-directions-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;

  background: transparent;
  border: none;
  padding: 0;

  font-size: 18px;
  font-weight: 600;
  color: #111;
  cursor: pointer;

  transform: scaleY(1.12);
  transform-origin: left center;
}

.bb-directions-label-row {
  display: inline-flex;
  align-items: center;
  line-height: 1.1;
}

.bb-caret {
  width: 10px;
  height: 10px;
  margin-left: 6px;

  border-right: 2px solid #111;
  border-bottom: 2px solid #111;

  transform: rotate(45deg);
  transition: transform 0.25s ease;

  position: relative;
  top: -2px;

  display: inline-block;
  box-sizing: border-box;
}

.bb-directions-toggle[aria-expanded="true"] .bb-caret {
  transform: rotate(-135deg);
  top: 3px;
}

/* --- header center --- */

.bb-header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.bb-timer-wrap {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bb-timer {
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  color: #111;
}

.bb-timer-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: #8a8f98;
}

.bb-stopwatch-icon {
  width: 34px;
  height: 34px;
  display: block;
}

.bb-timer.is-warning {
  color: #c62828;
}

.bb-hide-toggle {
  min-width: 78px;
  padding: 7px 24px;

  background: #e8eef8;
  border: 1.5px solid #444;
  border-radius: 999px;

  font-size: 18px;
  font-weight: 600;
  transform: scaleY(1.12);
  line-height: 1;
  cursor: pointer;
}

.bb-hide-toggle:hover {
  background: #dde6f3;
}

.bb-hide-toggle:active {
  transform: translateY(1px);
}

/* =========================================================
   MATH HEADER ONLY – lower right-side tools
   ========================================================= */

.bb-header-right > .bb-tool-btn {
  position: relative;
  top: 10px;
}

.bb-header-right > .bb-more-wrap:not(.bb-rw-more-wrap) {
  position: relative;
  top: 8px;
}

/* --- header right (generic / math) --- */

.bb-header-right {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 28px;
  margin-top: 18px; /*18px*/
  padding-top: 0;
}

.bb-tool-btn {
  position: relative;
  display: grid;
  grid-template-rows: 28px 22px;
  justify-items: center;
  align-items: start;

  min-width: 92px;
  padding: 0;
  border: 0;
  background: transparent;

  color: #111;
  cursor: pointer;

  font-size: 17px;
  font-weight: 600;
  line-height: 1.1;
  transform: scaleY(1.12);
}

.bb-tool-btn:hover,
.bb-directions-toggle:hover,
.bb-hide-toggle:hover {
  opacity: 0.85;
}

.bb-tool-icon-slot {
  width: 56px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bb-tool-icon-slot--empty {
  visibility: hidden;
}

.bb-tool-btn-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.bb-tool-icon {
  display: block;
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
}

.bb-tool-icon-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.bb-more-wrap {
  position: relative;
  display: flex;
  align-items: flex-start;
}

.bb-more-toggle {
  display: grid;
  grid-template-rows: 28px 22px;
  justify-items: center;
  align-items: start;
  min-width: 72px;
  gap: 0;
}

/* =========================================================
   5. HEADER PREVIEW STRIP
   ========================================================= */

.bb-header-preview-wrap {
  position: relative;
  width: 100%;
  padding: 0;
  box-sizing: border-box;
  background: #fff;
}

.bb-header-preview-wrap::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 3;

  background-image: repeating-linear-gradient(
    to right,
    #111 0px,
    #111 24px,
    transparent 24px,
    transparent 28px
  );
}

.bb-header-preview {
  position: relative;
  z-index: 2;
  box-sizing: border-box;

  margin-left: var(--bb-side-margin);
  margin-right: var(--bb-side-margin);
  margin-top: 3px;

  height: 44px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: #232a7a;
  color: #fff;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 1;

  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

/* =========================================================
   6. MORE MENU + EXIT MODAL
   ========================================================= */

.bb-more-menu[hidden],
.bb-exit-modal[hidden] {
  display: none !important;
}

.bb-more-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 280px;
  background: #fff;
  border: 1px solid #d9d9d9;
  border-radius: 18px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
  padding: 10px 0;
  z-index: 2000;
}

.bb-more-item {
  display: block;
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
  padding: 14px 20px;
  font: inherit;
  cursor: pointer;
}

.bb-more-item:disabled {
  color: #777;
  cursor: default;
}

.bb-more-item:not(:disabled):hover {
  background: #f5f6f8;
}

.bb-exit-modal {
  position: fixed !important;
  inset: 0 !important;
  z-index: 20000 !important;
}

.bb-exit-backdrop {
  position: fixed !important;
  inset: 0 !important;
  background: rgba(0, 0, 0, 0.82) !important;
}

.bb-exit-dialog {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  width: min(660px, calc(100vw - 64px)) !important;
  background: #fff !important;
  border-radius: 18px !important;
  padding: 34px 36px 26px !important;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22) !important;
  z-index: 20001 !important;
}

.bb-exit-close {
  position: absolute;
  top: 18px;
  right: 18px;
  border: 0;
  background: transparent;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
}

.bb-exit-dialog h2 {
  margin: 0 60px 22px 0;
  font-size: 31px;
  font-weight: 400;
  line-height: 1.2;
}

.bb-exit-dialog p {
  margin: 0 0 34px 0;
  max-width: 560px;
  font-size: 17px;
  line-height: 1.45;
}

.bb-exit-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 28px;
}

.bb-exit-cancel {
  border: 0;
  background: transparent;
  color: #2d4cc8;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.bb-exit-confirm {
  border: 1px solid #111;
  border-radius: 999px;
  background: #ffd400;
  padding: 14px 28px;
  min-width: 154px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

body.bb-modal-open {
  overflow: hidden;
}

/* =========================================================
   MATH HEADER – TOOL ICON SIZES
   ========================================================= */

.bb-tool-btn[data-panel="reference-panel"] .bb-tool-icon-img {
  width: 24px;
  height: 24px;
}

.bb-tool-btn[data-panel="calculator-panel"] .bb-tool-icon-img {
  width: 20px;
  height: 20px;
}

.bb-tool-btn-more .bb-tool-icon-img {
  width: 14px;
  height: 20px;
}

.bb-tool-btn-more .bb-tool-btn-label {
  position: relative;
  top: 2px;
}

/* =========================================================
   MATH / GENERIC MORE MENU WITH SVG ICONS
   ========================================================= */

.bb-more-menu .bb-more-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.bb-more-item-icon-wrap {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
}

.bb-more-item-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

.bb-more-item-label {
  display: inline-block;
  line-height: 1.2;
  font-size: 20px;
}

.bb-more-item:disabled .bb-more-item-icon-img {
  opacity: 0.55;
}

.bb-more-item:not(:disabled) .bb-more-item-icon-img {
  opacity: 1;
}

.bb-more-item {
  color: #111;
}

.bb-more-item:hover {
  background: #ececec;
}

.bb-more-item:hover .bb-more-item-label {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* =========================================================
   RW HEADER – STACKING / Z-INDEX
   ========================================================= */

.bb-header {
  position: relative;
  z-index: 6000;
}

.bb-header-preview-wrap {
  position: relative;
  z-index: 5990;
}

.bb-header-right {
  position: relative;
  z-index: 6001;
}

.bb-rw-highlights-toggle {
  position: relative;
  z-index: 6002;
}

.bb-tool-tooltip {
  pointer-events: none;
  z-index: 6003;
}

/* =========================================================
   RW HEADER – MORE TOGGLE WITH SVG ICON
   ========================================================= */

.bb-rw-more-wrap {
  position: relative;
  z-index: 6004;
  pointer-events: auto;
  top: 5px;
}

.bb-rw-more-toggle {
  position: relative;
  z-index: 6005;
  pointer-events: auto;
  width: 72px;
  margin-top: 0px;
  text-decoration: none;
  justify-items: center;

  display: grid;
  grid-template-rows: 28px 22px;
  row-gap: 5px;
  align-items: start;
}

.bb-rw-more-toggle * {
  pointer-events: none;
}

.bb-rw-more-toggle .bb-rw-tool-btn-label {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.05;
  position: relative;
  top: 0px;
}

.bb-rw-tool-icon-wrap {
  width: 24px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bb-rw-tool-icon-img {
  width: 14px;
  height: 20px;
  display: block;
  object-fit: contain;
}

/* =========================================================
   RW MORE MENU
   ========================================================= */

.bb-rw-more-menu {
  z-index: 6006;
  min-width: 280px;
}

.bb-rw-more-menu .bb-more-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.bb-rw-more-item-icon-wrap {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 24px;
}

.bb-rw-more-item-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}

.bb-rw-more-item-label {
  display: inline-block;
  line-height: 1.2;
}

.bb-rw-more-menu .bb-more-item:disabled .bb-rw-more-item-icon-img {
  opacity: 0.55;
}

.bb-rw-more-menu .bb-more-item:not(:disabled) .bb-rw-more-item-icon-img {
  opacity: 1;
}