/* Shared back control and edge-swipe indicator.
   Loaded after legacy styles; the doubled class outranks context rules in astra.css
   (settings, banner editor, compose and lesson detail), so every screen gets one look. */

/* Keep scrolling content below Telegram's own fullscreen control region. */
html:has(body.beta) { --app-chrome-bg:var(--ui-bg,#f5f6fa); }
body.beta.telegram-display::before,
body.beta.telegram-display .study-intro::after {
  content:"";position:fixed;inset:0 0 auto;height:var(--app-safe-top,0px);
  background:var(--app-chrome-bg);z-index:45;pointer-events:none;
}
/* Mail and files use one toolbar control, including their refresh buttons. */
body.beta #study-main :is(button.mail-icon-button,.files-heading>button.files-icon-button) {
  display:inline-flex;align-items:center;justify-content:center;flex:none;
  box-sizing:border-box;width:44px;min-width:44px;height:44px;min-height:44px;
  padding:0;border:1px solid var(--ui-border);border-radius:12px;
  background:var(--ui-surface);color:var(--ui-accent);box-shadow:none;
}
body.beta #study-main :is(button.mail-icon-button,.files-heading>button.files-icon-button) svg { width:17px;height:17px; }
body.beta #study-main :is(button.mail-icon-button,.files-heading>button.files-icon-button):active { transform:scale(.96); }
@media(hover:hover) {
  body.beta #study-main :is(button.mail-icon-button,.files-heading>button.files-icon-button):hover { background:var(--ui-soft); }
}
@media(max-width:999px) {
  html:has(body.beta) { scroll-padding-top:calc(var(--app-safe-top,0px) + 96px); }
  body.beta #beta-dashboard .study-top,
  body.beta #study-main .hm-header,
  body.beta .study-intro-top {
    box-sizing:border-box;min-height:56px;padding:6px 10px;
    border:0;border-radius:0;background:var(--ui-bg);box-shadow:none;
  }
  body.beta #beta-dashboard .study-top,
  body.beta #study-main .hm-header {
    position:sticky;top:var(--app-safe-top,0px);z-index:30;
    width:calc(100% + 20px);height:auto;margin:0 -10px 16px;
    padding-inline:max(10px,var(--app-safe-left,0px)) max(10px,var(--app-safe-right,0px));
    display:flex;align-items:center;gap:10px;
  }
  body.beta #beta-dashboard .study-top::after,
  body.beta #study-main .hm-header::after {
    content:"";position:absolute;inset:100% 0 auto;height:12px;
    background:linear-gradient(var(--app-chrome-bg),transparent);pointer-events:none;
  }
  body.beta #beta-dashboard .study-top .study-brand { min-height:44px;min-width:0;gap:10px;background:transparent; }
  body.beta #beta-dashboard .study-top .study-wordmark { font-size:22px;line-height:1;letter-spacing:-.8px; }
  body.beta #beta-dashboard .study-top .study-institution { font-size:12px; }
  body.beta #beta-dashboard .study-top .astra-notifications { width:44px;height:44px;background:transparent;box-shadow:none; }
  body.beta #study-main .hm-header h1 {
    font-size:20px;line-height:1.2;letter-spacing:-.4px;
    display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;
  }
  body.beta #study-main .hm-header-identity>span { margin-top:3px;font-size:10px; }
  body.beta #study-main .hm-header .hm-button { border:0;background:transparent; }
  body.beta .study-intro-top {
    position:absolute;left:max(12px,var(--app-safe-left,0px));right:max(12px,var(--app-safe-right,0px));
    top:calc(var(--app-safe-top,0px) + 8px);z-index:12;display:flex;align-items:center;justify-content:space-between;gap:10px;
  }
  body.beta .study-intro-top .study-intro-brand { position:static;font-size:21px;line-height:1; }
  body.beta .study-intro-top .study-intro-skip { position:static;min-height:44px;padding:8px 13px;border-radius:22px;background:var(--ui-soft);color:var(--ui-text); }
  body.beta .study-intro.is-tour:not(.is-mode-choice) .study-intro-top { display:contents; }
  body.beta .study-intro.is-tour:not(.is-mode-choice) .study-intro-skip { position:absolute; }
  body.beta .study-intro.is-tour .study-tour-app .study-top { border-radius:0;background:var(--ui-surface);padding:6px 94px 6px 12px!important;min-height:56px; }
  /* A stable navigation plane: all five destinations stay visible while reading. */
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav {
    position:fixed;inset:auto 0 0;transform:none;z-index:20;
    display:flex;flex-direction:row;gap:0;box-sizing:border-box;width:100%;max-width:none;
    height:auto;min-height:0;max-height:none;margin:0;
    padding:6px max(8px,var(--app-safe-right,0px)) calc(6px + var(--app-safe-bottom,env(safe-area-inset-bottom,0px))) max(8px,var(--app-safe-left,0px));
    border:0;border-radius:0;background:var(--ui-surface);background:color-mix(in srgb,var(--ui-surface) 97%,transparent);
    box-shadow:none;overflow:visible;backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px);
  }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav::before {
    content:"";display:block;position:absolute;inset:auto 0 100%;height:14px;
    background:linear-gradient(transparent,color-mix(in srgb,var(--ui-surface) 97%,transparent));pointer-events:none;
  }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button {
    position:relative;display:flex;flex:1;flex-direction:column;align-items:center;justify-content:center;gap:4px;
    box-sizing:border-box;min-width:0;width:auto;height:54px;min-height:54px;padding:0 2px;
    border:0;border-radius:18px;background:transparent;color:var(--ui-muted);font:500 10.5px/13px Inter,system-ui,sans-serif;
  }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button>svg { position:relative;z-index:1;width:22px;height:22px;margin:0;color:inherit; }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button>span { position:relative;z-index:1;font:inherit;max-width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button::before,body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button::after { display:none; }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button.active { color:var(--ui-accent);background:var(--ui-accent-soft);font-weight:600; }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button:focus-visible { outline:2px solid var(--ui-accent);outline-offset:-2px; }
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button:not(.active):hover { background:transparent; }
}
@media(max-width:359px) {
  body.beta :is(#beta-dashboard,.study-tour-app) .study-nav button { padding-inline:0;font-size:10px; }
}
@media(max-width:999px) and (prefers-reduced-transparency:reduce) {
  body.beta #beta-dashboard .study-top,body.beta #study-main .hm-header,body.beta .study-intro-top,
  body.beta #beta-dashboard .study-nav { background:var(--ui-surface);backdrop-filter:none;-webkit-backdrop-filter:none; }
  body.beta #beta-dashboard .study-top,body.beta #study-main .hm-header { border-bottom:1px solid var(--ui-border); }
  body.beta #beta-dashboard .study-nav { border-top:1px solid var(--ui-border); }
  body.beta #beta-dashboard .study-top::after,body.beta #study-main .hm-header::after,
  body.beta #beta-dashboard .study-nav::before { display:none; }
}

body.beta #study-main button.astra-back.astra-back {
  position: relative;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  justify-content: flex-start;
  flex-shrink: 0;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  height: auto;
  min-height: 44px;
  padding: 0 8px 0 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ui-accent);
  font: 600 14px/1.2 Inter, system-ui, sans-serif;
  letter-spacing: 0;
  text-decoration: none;
  box-shadow: none;
  cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, transform .12s ease;
}
body.beta #study-main button.astra-back.astra-back .astra-back-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
}
body.beta #study-main button.astra-back.astra-back svg { width: 18px; height: 18px; margin: 0; }
body.beta #study-main button.astra-back.astra-back .astra-back-label { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.beta #study-main button.astra-back.astra-back:active { transform: scale(.97); }
body.beta #study-main button.astra-back.astra-back:focus-visible { outline: 3px solid var(--ui-accent); outline-offset: 2px; }
@media (hover: hover) {
  body.beta #study-main button.astra-back.astra-back:hover { border-color: var(--ui-accent-soft); background: var(--ui-soft); }
}
/* A standalone control keeps the destination beside the same round chevron. */
body.beta #study-main > button.astra-back.astra-back,
body.beta #study-main .campus-compose-window > button.astra-back.astra-back { margin: 0 0 12px; }

/* In a title row the control shrinks to a round chevron beside the heading, so it takes no line
   of its own; the destination label stays in the accessible name. */
body.beta #study-main :is(.astra-settings-heading, .astra-delete-heading, .campus-discovery-header, .banner-editor-header):has(> .astra-back) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
body.beta #study-main .astra-title-row { display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0 0 16px; }
/* Center the chevron against the complete lesson title, including wrapped lines. */
body.beta #study-main .lesson-detail-title { display: flex; align-items: center; flex-wrap: nowrap; gap: 12px; order: 1; min-width: 0; }
body.beta #study-main .lesson-detail-title > h1 { flex: 1 1 10ch; min-width: 0; margin: 0; }
body.beta #study-main :is(.astra-title-row, .astra-settings-heading, .astra-delete-heading, .campus-discovery-header, .banner-editor-header) > :is(h1, h2) { min-width: 0; margin: 0; }
body.beta #study-main :is(.study-heading, .astra-title-row, .astra-settings-heading, .astra-delete-heading, .campus-discovery-header, .banner-editor-header, .campus-post-heading, .lesson-detail-title, .files-heading, .hm-header) > button.astra-back.astra-back {
  flex: none;
  align-self: center;
  justify-content: center;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  gap: 0;
  border-color: transparent;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  box-shadow: none;
}
body.beta #study-main :is(.study-heading, .astra-title-row, .astra-settings-heading, .astra-delete-heading, .campus-discovery-header, .banner-editor-header, .campus-post-heading, .lesson-detail-title, .files-heading, .hm-header) > button.astra-back.astra-back .astra-back-icon {
  width: 100%;
  height: 100%;
  background: transparent;
}
body.beta #study-main :is(.study-heading, .astra-title-row, .astra-settings-heading, .astra-delete-heading, .campus-discovery-header, .banner-editor-header, .campus-post-heading, .lesson-detail-title, .files-heading, .hm-header) > button.astra-back.astra-back .astra-back-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
html[data-theme=dark] body.beta #study-main button.astra-back.astra-back { box-shadow: none; }

/* Edge swipe indicator: a round chevron that follows the finger in from the screen edge. */
body.beta .edge-swipe-indicator {
  --edge-progress: 0;
  position: fixed;
  z-index: 1000;
  top: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: 50%;
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  box-shadow: 0 0 0 3px var(--ui-surface), 0 6px 20px rgba(25, 35, 58, .22);
  opacity: calc(.4 + var(--edge-progress) * .6);
  pointer-events: none;
  transition: background-color .12s ease, color .12s ease;
}
body.beta .edge-swipe-indicator[hidden] { display: none; }
body.beta .edge-swipe-indicator[data-side=back] { left: 0; transform: translateX(calc(-40px + var(--edge-progress) * 56px)) scale(calc(.7 + var(--edge-progress) * .3)); }
body.beta .edge-swipe-indicator[data-side=forward] { right: 0; transform: translateX(calc(40px - var(--edge-progress) * 56px)) scale(calc(.7 + var(--edge-progress) * .3)); }
body.beta .edge-swipe-indicator[data-armed] { background: var(--ui-accent); color: var(--ui-on-accent); }
body.beta .edge-swipe-indicator svg { width: 22px; height: 22px; }
html[data-theme=dark] body.beta .edge-swipe-indicator { border: 1px solid var(--ui-border); box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }

@media (prefers-reduced-motion: reduce) {
  body.beta #study-main button.astra-back.astra-back { transition: none; }
  body.beta #study-main button.astra-back.astra-back:active { transform: none; }
}

/* Keep all five destinations readable at the narrowest supported width. */
@media (max-width: 359px) {
  html:is(:not([data-theme=dark]),[data-theme=dark]) body.beta .study-nav { width: calc(100% - 16px); padding: 4px; gap: 0; }
  html:is(:not([data-theme=dark]),[data-theme=dark]) body.beta .study-nav button { padding-inline: 0; }
  html:is(:not([data-theme=dark]),[data-theme=dark]) body.beta .study-nav button > span { font-size: 9px; letter-spacing: -.15px; text-overflow: clip; }
}
