.mdm-flyout-bar {
  --mdm-flyout-bg: #121820;
  --mdm-flyout-border: #233142;
  --mdm-flyout-text: #f4f6f8;
  --mdm-flyout-muted: #b9c2ce;
  --mdm-flyout-highlight: #ddc07a;
  --mdm-flyout-green: #7fff00;
  --mdm-flyout-panel: #0c1118;
  --mdm-flyout-hover: #182230;
  --mdm-flyout-offset: 0px;

  position: relative;
  z-index: 40;
  width: 100%;
  max-width: 100%;
  margin-left: 0;
  margin-right: 0;
  box-sizing: border-box;
  border-top: 1px solid var(--mdm-flyout-border);
  border-bottom: 0;
  background: linear-gradient(180deg, var(--mdm-flyout-bg) 0%, #0d131a 100%);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  overflow: visible;
}

.mdm-flyout-mobile-toggle {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--mdm-flyout-text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mdm-flyout-mobile-caret {
  color: var(--mdm-flyout-highlight);
  transition: transform 0.15s ease;
}

.mdm-flyout-bar.is-mobile-open .mdm-flyout-mobile-caret {
  transform: rotate(180deg);
}

.mdm-flyout-top-list {
  list-style: none;
  margin: 0;
  padding: 0 12px 0 calc(12px + var(--mdm-flyout-offset));
  display: flex;
  align-items: stretch;
  gap: 4px;
  overflow: visible;
  justify-content: center;
}

#mdm-flyout-top-list {
  margin-top: 5px;
}

@media (min-width: 640px) {
  .mdm-flyout-top-list {
    padding-left: 12px;
  }
}

.mdm-flyout-top-item {
  position: relative;
  flex: 0 0 auto;
}

.mdm-flyout-top-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  color: var(--mdm-flyout-text);
  text-decoration: none;
  font-size: 14px;
  font-family: Arial, sans-serif;
  font-weight: 400;
  letter-spacing: 0.01em;
  border-radius: 6px;
}

.mdm-flyout-top-button:hover,
.mdm-flyout-top-button:focus-visible,
.mdm-flyout-top-button:active,
.mdm-flyout-top-item.is-open > .mdm-flyout-top-button {
  background: var(--mdm-flyout-hover);
  color: var(--mdm-flyout-muted);
}

.mdm-flyout-top-title {
  white-space: nowrap;
}

.mdm-flyout-caret {
  font-size: 11px;
  color: var(--mdm-flyout-muted);
}

.mdm-flyout-top-item.is-open .mdm-flyout-caret {
  color: var(--mdm-flyout-muted);
}

.mdm-flyout-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 5px);
  min-width: 260px;
  max-width: min(90vw, 420px);
  border: 1px solid var(--mdm-flyout-border);
  border-radius: 10px;
  background: var(--mdm-flyout-panel);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.35), 0 0 14px rgba(255, 255, 255, 0.18);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  /* visibility:hidden is what actually removes the closed panel from the
     tab order and from the accessibility tree. opacity and pointer-events
     only hide it from sight and from the mouse: without this, every link
     inside every closed submenu stayed keyboard focusable, so a keyboard
     user tabbing across the menu bar fell into invisible links, and a
     screen reader announced the entire menu contents at all times.

     The 0.15s delay on visibility lets the fade-out finish before the
     panel is removed, so the animation is unchanged. */
  visibility: hidden;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}

.mdm-flyout-top-item.is-open > .mdm-flyout-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  /* No delay when opening - the panel must be focusable immediately. */
  visibility: visible;
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s;
}

.mdm-flyout-sub-list {
  margin: 0;
  padding: 6px;
  list-style: none;
}

.mdm-flyout-sub-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--mdm-flyout-text);
  text-decoration: none;
  font-size: 14px;
  font-family: Arial, sans-serif;
  font-weight: 400;
  padding: 8px 10px;
  border-radius: 7px;
}

.mdm-flyout-sub-link:hover {
  background: var(--mdm-flyout-hover);
  color: var(--mdm-flyout-green);
}

.mdm-flyout-sub-link:focus-visible,
.mdm-flyout-sub-link:active {
  background: var(--mdm-flyout-hover);
  color: var(--mdm-flyout-green);
}

.mdm-flyout-badge-new {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: 999px;
  background: #2d8f64;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.mdm-flyout-lock {
  color: #e7a96f;
  font-size: 12px;
}

.mdm-flyout-locked {
  opacity: 0.7;
}

.mdm-flyout-top-button.mdm-flyout-locked:hover,
.mdm-flyout-top-button.mdm-flyout-locked:focus-visible,
.mdm-flyout-top-button.mdm-flyout-locked:active,
.mdm-flyout-top-item.is-open > .mdm-flyout-top-button.mdm-flyout-locked {
  opacity: 1;
}

.mdm-flyout-coming-soon {
  padding: 12px;
  font-size: 13px;
  color: var(--mdm-flyout-muted);
}

@media (max-width: 639px) {
  .mdm-flyout-bar {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding: 5px 0;
    border-top: 0;
    background: transparent;
    box-shadow: none;
  }

  .mdm-flyout-bar .mdm-flyout-mobile-toggle {
    display: flex;
    min-height: 52px;
    /* Leave a safe lane for the site's fixed Saved/Reference tabs, which can
       occupy the far-left edge on tool pages. */
    padding: 0 15px 0 48px;
    border: 1px solid rgba(221, 192, 122, 0.58);
    border-radius: 12px;
    background: linear-gradient(180deg, #1a2230 0%, #111821 100%);
    color: #fff9ed;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.035em;
    text-transform: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 5px 14px rgba(0, 0, 0, 0.22);
  }

  .mdm-flyout-bar .mdm-flyout-mobile-toggle:hover,
  .mdm-flyout-bar .mdm-flyout-mobile-toggle:active,
  .mdm-flyout-bar.is-mobile-open .mdm-flyout-mobile-toggle {
    border-color: var(--mdm-flyout-highlight);
    background: linear-gradient(180deg, #222c3a 0%, #16202b 100%);
    color: #fff;
  }

  .mdm-flyout-bar .mdm-flyout-mobile-toggle:focus-visible {
    outline: 3px solid rgba(221, 192, 122, 0.3);
    outline-offset: 3px;
  }

  .mdm-flyout-mobile-label {
    display: inline-flex;
    align-items: center;
    gap: 11px;
  }

  .mdm-flyout-mobile-icon {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 21px;
    height: 21px;
  }

  .mdm-flyout-mobile-icon span {
    display: block;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: var(--mdm-flyout-highlight);
  }

  .mdm-flyout-mobile-caret {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(221, 192, 122, 0.42);
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.18);
    font-size: 13px;
  }

  .mdm-flyout-top-list {
    display: none;
    flex-direction: column;
    gap: 0;
    padding: 4px 8px 10px;
    overflow: visible;
  }

  .mdm-flyout-bar.is-mobile-open .mdm-flyout-top-list {
    display: flex;
  }

  .mdm-flyout-top-item {
    width: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }

  .mdm-flyout-top-button {
    display: flex;
    width: 100%;
    justify-content: space-between;
    min-height: 40px;
    padding: 0 10px;
    font-size: 14px;
    border-radius: 0;
  }

  .mdm-flyout-panel {
    position: static;
    min-width: 0;
    max-width: none;
    margin: 0 0 8px;
    border-radius: 8px;
    box-shadow: none;
    max-height: 0;
    overflow: hidden;
    border-width: 0;
    opacity: 1;
    transform: none;
    pointer-events: none;
    /* Same reasoning as the desktop rule above. max-height:0 with
       overflow:hidden clips the collapsed panel visually but leaves its
       links in the tab order, so the mobile accordion was fully tabbable
       while appearing closed. */
    visibility: hidden;
    transition: max-height 0.2s ease, visibility 0s linear 0.2s;
  }

  .mdm-flyout-top-item.is-open > .mdm-flyout-panel {
    /* The link count changes in Mega Dungeon Menus, so a fixed height clips
       newly added entries. JavaScript sets this to the panel's real height. */
    max-height: var(--mdm-flyout-panel-height, 1000px);
    pointer-events: auto;
    border-width: 1px;
    visibility: visible;
    transition: max-height 0.2s ease, visibility 0s;
  }

  .mdm-flyout-sub-list {
    padding: 4px;
  }

  .mdm-flyout-sub-link {
    min-height: 36px;
    font-size: 14px;
  }
}

/* ---------------------------------------------------------------
   Image card grid (Style A), 640px and wider.
   Only panels whose items have Featured Images get the
   .mdm-flyout-panel--cards class. Below 640px thumbnails are hidden,
   so the phone menu is unchanged.
   --------------------------------------------------------------- */
.mdm-flyout-sub-thumb {
  display: none;
}

@media (min-width: 640px) {
  .mdm-flyout-panel--cards {
    width: max-content;
    max-width: min(94vw, 1000px);
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-list {
    display: grid;
    grid-template-columns: repeat(var(--mdm-cards-cols, 4), 240px);
    gap: 10px;
    padding: 12px;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-link {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    padding: 6px;
    height: 100%;
    box-sizing: border-box;
    text-align: center;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-thumb {
    display: block;
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 6px;
    background: var(--mdm-flyout-hover);
    border: 1px solid var(--mdm-flyout-border);
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-link:hover .mdm-flyout-sub-thumb img,
  .mdm-flyout-panel--cards .mdm-flyout-sub-link:focus-visible .mdm-flyout-sub-thumb img {
    transform: scale(1.05);
  }

  .mdm-flyout-sub-thumb-initial {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    color: var(--mdm-flyout-muted);
    opacity: 0.5;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-title {
    font-size: 20px;
    line-height: 1.3;
  }

  .mdm-flyout-panel--cards .mdm-flyout-badge-new {
    align-self: center;
  }
}

/* Card titles ride on the lower part of the image (overlay), desktop only. */
@media (min-width: 640px) {
  .mdm-flyout-panel--cards .mdm-flyout-sub-link {
    position: relative;
    padding: 0;
    gap: 0;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid var(--mdm-flyout-border);
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-link:hover,
  .mdm-flyout-panel--cards .mdm-flyout-sub-link:focus-visible {
    border-color: var(--mdm-flyout-green);
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-thumb {
    border: 0;
    border-radius: 0;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 8px 6px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0) 100%);
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    pointer-events: none;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-link:hover .mdm-flyout-sub-title,
  .mdm-flyout-panel--cards .mdm-flyout-sub-link:focus-visible .mdm-flyout-sub-title {
    color: #fff;
    background: linear-gradient(to top, #000 0%, rgba(0, 0, 0, 0) 100%);
  }

  .mdm-flyout-panel--cards .mdm-flyout-badge-new {
    position: absolute;
    top: 6px;
    right: 6px;
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-thumb-initial {
    padding-bottom: 18px;
  }
}

/* Card dropdowns shrink to fit narrower screens (640px and up):
   columns can get narrower than 240px, and the panel never exceeds the
   screen width minus a 16px margin on each side. */
@media (min-width: 640px) {
  .mdm-flyout-panel--cards {
    max-width: calc(100vw - 48px);
  }

  .mdm-flyout-panel--cards .mdm-flyout-sub-list {
    grid-template-columns: repeat(var(--mdm-cards-cols, 4), minmax(0, 240px));
  }
}

/* Desktop top-bar menu items (Intro, Quick Library, ...): bold uppercase style. */
@media (min-width: 640px) {
  .mdm-flyout-top-button {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--ttui_grey-300, #c7ccd1);
    text-decoration: none;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 14px;
    line-height: 21px;
    cursor: pointer;
    background: transparent;
    background-position-y: 0%;
    background-repeat: repeat;
    background-image: none;
    border: none;
    white-space: nowrap;
    fill: currentColor;
  }
}

/* Menu bar (640px+): red glow rises from the bottom of a top menu item on
   hover/focus, and stays while its dropdown is open. Replaces the grey box. */
@media (min-width: 640px) {
  .mdm-flyout-top-button {
    position: relative;
    background-color: transparent;
    background-image: radial-gradient(80% 50% at 50% 100%, #e40712 0, transparent 50%);
    background-repeat: no-repeat;
    background-position-x: 50%;
    background-position-y: 32px;
    transition: color 0s ease, background-position-y 0.4s ease;
  }

  .mdm-flyout-top-button:hover,
  .mdm-flyout-top-button:focus-visible,
  .mdm-flyout-top-button:active,
  .mdm-flyout-top-item.is-open > .mdm-flyout-top-button {
    background-color: transparent;
    background-image: radial-gradient(80% 50% at 50% 100%, #e40712 0, transparent 50%);
    background-repeat: no-repeat;
    background-position-x: 50%;
    background-position-y: 0;
  }
}

/* Menu bar (640px+): while a dropdown is open, its top item's text and
   triangle turn white and the triangle flips upward. */
@media (min-width: 640px) {
  .mdm-flyout-caret {
    display: inline-block;
    transition: transform 0.2s ease, color 0s ease;
  }

  .mdm-flyout-top-item.is-open > .mdm-flyout-top-button,
  .mdm-flyout-top-item.is-open > .mdm-flyout-top-button .mdm-flyout-caret {
    color: #fff;
  }

  .mdm-flyout-top-item.is-open > .mdm-flyout-top-button .mdm-flyout-caret {
    transform: rotate(180deg);
  }
}
