/* ── Shared top bar: logo, Studios and Shorts, account chip ───────────────
   Loaded by every page (Home, Library, editor, Audio enhancement, Shorts).
   It reads the page's color tokens; pages that name them differently map
   them in their own :root. A page sets --page to its content width so the
   bar lines up with what's under it. */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px 32px;
  padding: 0 max(16px, calc((100% - var(--page, 1040px)) / 2));
  min-height: 60px;
  max-width: none;
  margin: 0 0 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: var(--font);
}
.brand-wrap { display: flex; align-items: baseline; gap: 12px; }
.brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-stretch: var(--wide, 125%); font-weight: 850; font-size: 1.3rem; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none;
}
.brand img { display: block; width: 28px; height: 28px; }
.top .tag { color: var(--muted); font-size: 0.86rem; }

/* Current page: a cobalt level bar along the bar's bottom edge. */
.nav { flex: 1; display: flex; align-items: stretch; gap: 2px; flex-wrap: wrap; align-self: stretch; }
.nav a {
  display: inline-flex; align-items: center;
  padding: 0 11px; min-height: 60px;
  font-size: 0.9rem; font-weight: 600; color: var(--muted); text-decoration: none;
  position: relative;
  transition: color .15s;
}
.nav a::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: transparent; }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { color: var(--text); }
.nav a[aria-current="page"]::after { background: var(--accent); }
.nav a:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

/* Account: an avatar chip at the far right; it opens the account page,
   where logging out lives. */
.nav a.nav-user {
  margin-left: auto; align-self: center; min-height: 0; gap: 8px;
  padding: 3px 12px 3px 3px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); max-width: 220px;
}
.nav a.nav-user:empty { display: none; }
.nav a.nav-help { flex:none; align-self:center; justify-content:center; min-height:28px; width:28px; padding:0; border:1px solid var(--border); border-radius:50%; }
.nav a.nav-user::after { content: none; }
.nav a.nav-user > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a.nav-user:hover { background: var(--chip-bg); border-color: var(--line-strong); }
.nav a.nav-user[aria-current="page"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.nav a.nav-user:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.nav-user .av {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  font-size: 0.75rem; font-weight: 800;
  color: hsl(var(--h, 210) 70% 88%); background: hsl(var(--h, 210) 35% 28%);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not(.always-dark) .nav-user .av { color: hsl(var(--h, 210) 55% 22%); background: hsl(var(--h, 210) 55% 82%); }
}

/* Studio switcher: the studio every page works in, next to the logo.
   Hidden during a live session, so a click can't leave the recording. */
.in-room .studio-switch { display: none; }
.studio-switch { position: relative; align-self: center; }
.studio-switch-button {
  display: inline-flex; align-items: center; gap: 8px; max-width: 260px;
  padding: 4px 10px 4px 4px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--text); font: 600 0.9rem var(--font); cursor: pointer; box-shadow: none;
}
.studio-switch-button:hover, .studio-switch-button[aria-expanded="true"] { background: var(--chip-bg); border-color: var(--line-strong); }
.studio-switch-button:focus-visible { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.studio-switch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-switch-caret { color: var(--muted); font-size: 0.75rem; }
.studio-switch-mark {
  display: inline-grid; place-items: center; flex: none; overflow: hidden;
  width: 26px; height: 26px; border-radius: 7px; font-size: 0.75rem; font-weight: 800;
  color: hsl(var(--h, 210) 70% 88%); background: hsl(var(--h, 210) 35% 28%);
}
.studio-switch-mark img { width: 100%; height: 100%; object-fit: cover; }
.studio-switch-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 260px; max-width: 340px;
  max-height: min(70vh, 460px); overflow: auto; padding: 6px;
  background: var(--surface, var(--bg)); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.studio-switch-heading { margin: 4px 8px 6px; color: var(--muted); font-size: 0.75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.studio-switch-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font: 600 0.9rem var(--font); text-align: left; cursor: pointer; box-shadow: none;
}
.studio-switch-item:hover, .studio-switch-item:focus-visible { background: var(--chip-bg); outline: none; }
.studio-switch-item[aria-checked="true"] { box-shadow: inset 3px 0 var(--accent); background: var(--chip-bg); }
.studio-switch-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.studio-switch-role { color: var(--muted); font-size: 0.75rem; font-weight: 600; }
.studio-switch-footer { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; padding: 8px 8px 4px; border-top: 1px solid var(--border); }
.studio-switch-footer a { color: var(--accent); font-size: 0.85rem; font-weight: 650; text-decoration: none; }
.studio-switch-footer a:hover { text-decoration: underline; }

/* "← All studios" style link back to a parent page. */
.back { display: inline-block; margin: 6px 0 14px; color: var(--muted); text-decoration: none; font-size: 0.9rem; font-weight: 600; }
.back:hover { color: var(--text); }

@media (max-width: 640px) {
  .top { position: static; padding: 0 16px; gap: 8px 14px; flex-wrap: nowrap; min-height: 56px; }
  .top .tag { display: none; }
  .top .brand { font-size: 1.15rem; }
  /* The links scroll sideways rather than widening the page past the screen. */
  .nav { flex-wrap: nowrap; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { min-height: 56px; padding: 0 9px; font-size: 0.88rem; white-space: nowrap; }
  /* Only the avatar on phones; the name is still its accessible label. */
  .nav a.nav-user { min-height: 0; padding: 2px; }
  .nav a.nav-user > span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .nav-user .av { width: 30px; height: 30px; font-size: 0.8rem; }
  /* Only the studio's mark on phones; its name is in the button's label. */
  /* With the studio switcher, the logo alone stands for Tolkun (room for the links). */
  .top:has(.studio-switch) .brand { font-size: 0; gap: 0; }
  .studio-switch-button { padding: 3px 6px 3px 3px; }
  .studio-switch-name { display: none; }
  .studio-switch-menu { position: fixed; top: 56px; left: 8px; right: 8px; max-width: none; }
}

/* Narrower screens: Pricing (also on the Account page) and Admin (a desktop
   task) step aside so the main links, Activity and the account chip fit. */
@media (max-width: 960px) {
  .nav a[href="/pricing/"]:not([aria-current]), .nav a[href="/admin/"]:not([aria-current]) { display: none; }
}

.nav-toggle { display: none; }
@media(max-width:640px){
  .top { position:relative; }
  .top .nav-toggle { display:inline-flex; margin-left:auto; min-height:44px; align-items:center; padding:8px 14px; background:var(--surface); color:var(--text); border:1px solid var(--border); border-radius:6px; }
  .top:has(.nav[hidden]) .nav-toggle { display:none; }
  .top .nav { display:none; }
  .top.nav-menu-open .nav { display:flex; position:absolute; top:100%; left:8px; right:8px; z-index:45; flex-direction:column; align-items:stretch; max-height:70dvh; overflow:auto; padding:8px; background:var(--surface); border:1px solid var(--border); border-radius:10px; box-shadow:var(--shadow); }
  .top.nav-menu-open .nav a { min-height:44px; padding:10px 14px; flex-shrink:0; }
  .top.nav-menu-open .nav a[href='/pricing/'], .top.nav-menu-open .nav a[href='/admin/'] { display:inline-flex; }
  .top.nav-menu-open .nav a.nav-user { margin:8px 0 0; align-self:stretch; gap:10px; }
  .top.nav-menu-open .nav a.nav-user > span:last-child { position:static; width:auto; height:auto; clip-path:none; }
  .top.nav-menu-open .nav a.nav-help { align-self:flex-start; width:auto; }
}
